github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/filesystem/rootfs/docker/scripts/docker.sh (about)

     1  #!/bin/bash
     2  # Copyright © 2021 Alibaba Group Holding Ltd.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  command_exists() {
    17      command -v "$@" > /dev/null 2>&1
    18  }
    19  get_distribution() {
    20      lsb_dist=""
    21      # Every system that we officially support has /etc/os-release
    22      if [ -r /etc/os-release ]; then
    23      	lsb_dist="$(. /etc/os-release && echo "$ID")"
    24      fi
    25      # Returning an empty string here should be alright since the
    26      # case statements don't act unless you provide an actual value
    27      echo "$lsb_dist"
    28  }
    29  disable_selinux(){
    30      if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
    31          sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    32          setenforce 0
    33      fi
    34  }
    35  set -e
    36  set -x
    37  storage=${1:-/var/lib/docker}
    38  mkdir -p $storage
    39  if ! command_exists docker; then
    40    lsb_dist=$( get_distribution )
    41    lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
    42    echo "current system is $lsb_dist"
    43    case "$lsb_dist" in
    44      ubuntu|deepin|debian|raspbian|kylin)
    45      	cp ../etc/docker.service /lib/systemd/system/docker.service
    46      ;;
    47    	centos|rhel|ol|sles|kylin|neokylin)
    48  			cp ../etc/docker.service /usr/lib/systemd/system/docker.service
    49  		;;
    50      alios)
    51        ip link add name docker0 type bridge
    52        ip addr add dev docker0 172.17.0.1/16
    53      	cp ../etc/docker.service /usr/lib/systemd/system/docker.service
    54      ;;
    55      *)
    56  			echo "unknown system to use /lib/systemd/system/docker.service"
    57  			cp ../etc/docker.service /lib/systemd/system/docker.service
    58      ;;
    59    esac
    60  
    61    [ -d  /etc/docker/ ] || mkdir /etc/docker/  -p
    62  
    63    chmod -R 755 ../cri
    64    tar -zxvf ../cri/docker.tar.gz -C /usr/bin
    65    chmod a+x /usr/bin
    66    chmod a+x /usr/bin/docker
    67    chmod a+x /usr/bin/dockerd
    68    systemctl enable docker.service
    69    systemctl restart docker.service
    70    cp ../etc/daemon.json /etc/docker
    71    if [[ -n $1 && -n $2 ]]; then
    72      sed -i "s/sea.hub:5000/$2:$3/g" /etc/docker/daemon.json
    73    fi
    74  fi
    75  disable_selinux
    76  systemctl daemon-reload
    77  systemctl restart docker.service