跳转至

docker一键安装脚本

安装方法

wget -qO- get.docker.com | sh     #官方安装



curl -sSL https://get.daocloud.io/docker | sh     #国内daodocker安装,推荐

脚本1内容

[root@jumpserver ~]# wget -qO- get.docker.com > docker_install1.sh
[root@jumpserver ~]# cat docker_install1.sh -n
     1  #!/bin/sh
     2  set -e
     3  # Docker CE for Linux installation script
     4  #
     5  # See https://docs.docker.com/engine/install/ for the installation steps.
     6  #
     7  # This script is meant for quick & easy install via:
     8  #   $ curl -fsSL https://get.docker.com -o get-docker.sh
     9  #   $ sh get-docker.sh
    10  #
    11  # For test builds (ie. release candidates):
    12  #   $ curl -fsSL https://test.docker.com -o test-docker.sh
    13  #   $ sh test-docker.sh
    14  #
    15  # NOTE: Make sure to verify the contents of the script
    16  #       you downloaded matches the contents of install.sh
    17  #       located at https://github.com/docker/docker-install
    18  #       before executing.
    19  #
    20  # Git commit from https://github.com/docker/docker-install when
    21  # the script was uploaded (Should only be modified by upload job):
    22  SCRIPT_COMMIT_SHA="93d2499759296ac1f9c510605fef85052a2c32be"
    23
    24  # strip "v" prefix if present
    25  VERSION="${VERSION#v}"
    26
    27  # The channel to install from:
    28  #   * nightly
    29  #   * test
    30  #   * stable
    31  #   * edge (deprecated)
    32  DEFAULT_CHANNEL_VALUE="stable"
    33  if [ -z "$CHANNEL" ]; then
    34          CHANNEL=$DEFAULT_CHANNEL_VALUE
    35  fi
    36
    37  DEFAULT_DOWNLOAD_URL="https://download.docker.com"
    38  if [ -z "$DOWNLOAD_URL" ]; then
    39          DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
    40  fi
    41
    42  DEFAULT_REPO_FILE="docker-ce.repo"
    43  if [ -z "$REPO_FILE" ]; then
    44          REPO_FILE="$DEFAULT_REPO_FILE"
    45  fi
    46
    47  mirror=''
    48  DRY_RUN=${DRY_RUN:-}
    49  while [ $# -gt 0 ]; do
    50          case "$1" in
    51                  --mirror)
    52                          mirror="$2"
    53                          shift
    54                          ;;
    55                  --dry-run)
    56                          DRY_RUN=1
    57                          ;;
    58                  --*)
    59                          echo "Illegal option $1"
    60                          ;;
    61          esac
    62          shift $(( $# > 0 ? 1 : 0 ))
    63  done
    64
    65  case "$mirror" in
    66          Aliyun)
    67                  DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"
    68                  ;;
    69          AzureChinaCloud)
    70                  DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"
    71                  ;;
    72  esac
    73
    74  command_exists() {
    75          command -v "$@" > /dev/null 2>&1
    76  }
    77
    78  # version_gte checks if the version specified in $VERSION is at least
    79  # the given CalVer (YY.MM) version. returns 0 (success) if $VERSION is either
    80  # unset (=latest) or newer or equal than the specified version. Returns 1 (fail)
    81  # otherwise.
    82  #
    83  # examples:
    84  #
    85  # VERSION=20.10
    86  # version_gte 20.10 // 0 (success)
    87  # version_gte 19.03 // 0 (success)
    88  # version_gte 21.10 // 1 (fail)
    89  version_gte() {
    90          if [ -z "$VERSION" ]; then
    91                          return 0
    92          fi
    93          eval calver_compare "$VERSION" "$1"
    94  }
    95
    96  # calver_compare compares two CalVer (YY.MM) version strings. returns 0 (success)
    97  # if version A is newer or equal than version B, or 1 (fail) otherwise. Patch
    98  # releases and pre-release (-alpha/-beta) are not taken into account
    99  #
   100  # examples:
   101  #
   102  # calver_compare 20.10 19.03 // 0 (success)
   103  # calver_compare 20.10 20.10 // 0 (success)
   104  # calver_compare 19.03 20.10 // 1 (fail)
   105  calver_compare() (
   106          set +x
   107
   108          yy_a="$(echo "$1" | cut -d'.' -f1)"
   109          yy_b="$(echo "$2" | cut -d'.' -f1)"
   110          if [ "$yy_a" -lt "$yy_b" ]; then
   111                  return 1
   112          fi
   113          if [ "$yy_a" -gt "$yy_b" ]; then
   114                  return 0
   115          fi
   116          mm_a="$(echo "$1" | cut -d'.' -f2)"
   117          mm_b="$(echo "$2" | cut -d'.' -f2)"
   118          if [ "${mm_a#0}" -lt "${mm_b#0}" ]; then
   119                  return 1
   120          fi
   121
   122          return 0
   123  )
   124
   125  is_dry_run() {
   126          if [ -z "$DRY_RUN" ]; then
   127                  return 1
   128          else
   129                  return 0
   130          fi
   131  }
   132
   133  is_wsl() {
   134          case "$(uname -r)" in
   135          *microsoft* ) true ;; # WSL 2
   136          *Microsoft* ) true ;; # WSL 1
   137          * ) false;;
   138          esac
   139  }
   140
   141  is_darwin() {
   142          case "$(uname -s)" in
   143          *darwin* ) true ;;
   144          *Darwin* ) true ;;
   145          * ) false;;
   146          esac
   147  }
   148
   149  deprecation_notice() {
   150          distro=$1
   151          distro_version=$2
   152          echo
   153          printf "\033[91;1mDEPRECATION WARNING\033[0m\n"
   154          printf "    This Linux distribution (\033[1m%s %s\033[0m) reached end-of-life and is no longer supported by this script.\n" "$distro" "$distro_version"
   155          echo   "    No updates or security fixes will be released for this distribution, and users are recommended"
   156          echo   "    to upgrade to a currently maintained version of $distro."
   157          echo
   158          printf   "Press \033[1mCtrl+C\033[0m now to abort this script, or wait for the installation to continue."
   159          echo
   160          sleep 10
   161  }
   162
   163  get_distribution() {
   164          lsb_dist=""
   165          # Every system that we officially support has /etc/os-release
   166          if [ -r /etc/os-release ]; then
   167                  lsb_dist="$(. /etc/os-release && echo "$ID")"
   168          fi
   169          # Returning an empty string here should be alright since the
   170          # case statements don't act unless you provide an actual value
   171          echo "$lsb_dist"
   172  }
   173
   174  echo_docker_as_nonroot() {
   175          if is_dry_run; then
   176                  return
   177          fi
   178          if command_exists docker && [ -e /var/run/docker.sock ]; then
   179                  (
   180                          set -x
   181                          $sh_c 'docker version'
   182                  ) || true
   183          fi
   184
   185          # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
   186          echo
   187          echo "================================================================================"
   188          echo
   189          if version_gte "20.10"; then
   190                  echo "To run Docker as a non-privileged user, consider setting up the"
   191                  echo "Docker daemon in rootless mode for your user:"
   192                  echo
   193                  echo "    dockerd-rootless-setuptool.sh install"
   194                  echo
   195                  echo "Visit https://docs.docker.com/go/rootless/ to learn about rootless mode."
   196                  echo
   197          fi
   198          echo
   199          echo "To run the Docker daemon as a fully privileged service, but granting non-root"
   200          echo "users access, refer to https://docs.docker.com/go/daemon-access/"
   201          echo
   202          echo "WARNING: Access to the remote API on a privileged Docker daemon is equivalent"
   203          echo "         to root access on the host. Refer to the 'Docker daemon attack surface'"
   204          echo "         documentation for details: https://docs.docker.com/go/attack-surface/"
   205          echo
   206          echo "================================================================================"
   207          echo
   208  }
   209
   210  # Check if this is a forked Linux distro
   211  check_forked() {
   212
   213          # Check for lsb_release command existence, it usually exists in forked distros
   214          if command_exists lsb_release; then
   215                  # Check if the `-u` option is supported
   216                  set +e
   217                  lsb_release -a -u > /dev/null 2>&1
   218                  lsb_release_exit_code=$?
   219                  set -e
   220
   221                  # Check if the command has exited successfully, it means we're in a forked distro
   222                  if [ "$lsb_release_exit_code" = "0" ]; then
   223                          # Print info about current distro
   224                          cat <<-EOF
   225                          You're using '$lsb_dist' version '$dist_version'.
   226                          EOF
   227
   228                          # Get the upstream release info
   229                          lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')
   230                          dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')
   231
   232                          # Print info about upstream distro
   233                          cat <<-EOF
   234                          Upstream release is '$lsb_dist' version '$dist_version'.
   235                          EOF
   236                  else
   237                          if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
   238                                  if [ "$lsb_dist" = "osmc" ]; then
   239                                          # OSMC runs Raspbian
   240                                          lsb_dist=raspbian
   241                                  else
   242                                          # We're Debian and don't even know it!
   243                                          lsb_dist=debian
   244                                  fi
   245                                  dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
   246                                  case "$dist_version" in
   247                                          11)
   248                                                  dist_version="bullseye"
   249                                          ;;
   250                                          10)
   251                                                  dist_version="buster"
   252                                          ;;
   253                                          9)
   254                                                  dist_version="stretch"
   255                                          ;;
   256                                          8)
   257                                                  dist_version="jessie"
   258                                          ;;
   259                                  esac
   260                          fi
   261                  fi
   262          fi
   263  }
   264
   265  do_install() {
   266          echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"
   267
   268          if command_exists docker; then
   269                  cat >&2 <<-'EOF'
   270                          Warning: the "docker" command appears to already exist on this system.
   271
   272                          If you already have Docker installed, this script can cause trouble, which is
   273                          why we're displaying this warning and provide the opportunity to cancel the
   274                          installation.
   275
   276                          If you installed the current Docker package using this script and are using it
   277                          again to update Docker, you can safely ignore this message.
   278
   279                          You may press Ctrl+C now to abort this script.
   280                  EOF
   281                  ( set -x; sleep 20 )
   282          fi
   283
   284          user="$(id -un 2>/dev/null || true)"
   285
   286          sh_c='sh -c'
   287          if [ "$user" != 'root' ]; then
   288                  if command_exists sudo; then
   289                          sh_c='sudo -E sh -c'
   290                  elif command_exists su; then
   291                          sh_c='su -c'
   292                  else
   293                          cat >&2 <<-'EOF'
   294                          Error: this installer needs the ability to run commands as root.
   295                          We are unable to find either "sudo" or "su" available to make this happen.
   296                          EOF
   297                          exit 1
   298                  fi
   299          fi
   300
   301          if is_dry_run; then
   302                  sh_c="echo"
   303          fi
   304
   305          # perform some very rudimentary platform detection
   306          lsb_dist=$( get_distribution )
   307          lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
   308
   309          if is_wsl; then
   310                  echo
   311                  echo "WSL DETECTED: We recommend using Docker Desktop for Windows."
   312                  echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
   313                  echo
   314                  cat >&2 <<-'EOF'
   315
   316                          You may press Ctrl+C now to abort this script.
   317                  EOF
   318                  ( set -x; sleep 20 )
   319          fi
   320
   321          case "$lsb_dist" in
   322
   323                  ubuntu)
   324                          if command_exists lsb_release; then
   325                                  dist_version="$(lsb_release --codename | cut -f2)"
   326                          fi
   327                          if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
   328                                  dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
   329                          fi
   330                  ;;
   331
   332                  debian|raspbian)
   333                          dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
   334                          case "$dist_version" in
   335                                  11)
   336                                          dist_version="bullseye"
   337                                  ;;
   338                                  10)
   339                                          dist_version="buster"
   340                                  ;;
   341                                  9)
   342                                          dist_version="stretch"
   343                                  ;;
   344                                  8)
   345                                          dist_version="jessie"
   346                                  ;;
   347                          esac
   348                  ;;
   349
   350                  centos|rhel|sles)
   351                          if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
   352                                  dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
   353                          fi
   354                  ;;
   355
   356                  *)
   357                          if command_exists lsb_release; then
   358                                  dist_version="$(lsb_release --release | cut -f2)"
   359                          fi
   360                          if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
   361                                  dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
   362                          fi
   363                  ;;
   364
   365          esac
   366
   367          # Check if this is a forked Linux distro
   368          check_forked
   369
   370          # Print deprecation warnings for distro versions that recently reached EOL,
   371          # but may still be commonly used (especially LTS versions).
   372          case "$lsb_dist.$dist_version" in
   373                  debian.stretch|debian.jessie)
   374                          deprecation_notice "$lsb_dist" "$dist_version"
   375                          ;;
   376                  raspbian.stretch|raspbian.jessie)
   377                          deprecation_notice "$lsb_dist" "$dist_version"
   378                          ;;
   379                  ubuntu.xenial|ubuntu.trusty)
   380                          deprecation_notice "$lsb_dist" "$dist_version"
   381                          ;;
   382                  fedora.*)
   383                          if [ "$dist_version" -lt 33 ]; then
   384                                  deprecation_notice "$lsb_dist" "$dist_version"
   385                          fi
   386                          ;;
   387          esac
   388
   389          # Run setup for each distro accordingly
   390          case "$lsb_dist" in
   391                  ubuntu|debian|raspbian)
   392                          pre_reqs="apt-transport-https ca-certificates curl"
   393                          if ! command -v gpg > /dev/null; then
   394                                  pre_reqs="$pre_reqs gnupg"
   395                          fi
   396                          apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $DOWNLOAD_URL/linux/$lsb_dist $dist_version $CHANNEL"
   397                          (
   398                                  if ! is_dry_run; then
   399                                          set -x
   400                                  fi
   401                                  $sh_c 'apt-get update -qq >/dev/null'
   402                                  $sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pre_reqs >/dev/null"
   403                                  $sh_c "curl -fsSL \"$DOWNLOAD_URL/linux/$lsb_dist/gpg\" | gpg --dearmor --yes -o /usr/share/keyrings/docker-archive-keyring.gpg"
   404                                  $sh_c "echo \"$apt_repo\" > /etc/apt/sources.list.d/docker.list"
   405                                  $sh_c 'apt-get update -qq >/dev/null'
   406                          )
   407                          pkg_version=""
   408                          if [ -n "$VERSION" ]; then
   409                                  if is_dry_run; then
   410                                          echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
   411                                  else
   412                                          # Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel
   413                                          pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/~ce~.*/g" | sed "s/-/.*/g").*-0~$lsb_dist"
   414                                          search_command="apt-cache madison 'docker-ce' | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
   415                                          pkg_version="$($sh_c "$search_command")"
   416                                          echo "INFO: Searching repository for VERSION '$VERSION'"
   417                                          echo "INFO: $search_command"
   418                                          if [ -z "$pkg_version" ]; then
   419                                                  echo
   420                                                  echo "ERROR: '$VERSION' not found amongst apt-cache madison results"
   421                                                  echo
   422                                                  exit 1
   423                                          fi
   424                                          if version_gte "18.09"; then
   425                                                          search_command="apt-cache madison 'docker-ce-cli' | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
   426                                                          echo "INFO: $search_command"
   427                                                          cli_pkg_version="=$($sh_c "$search_command")"
   428                                          fi
   429                                          pkg_version="=$pkg_version"
   430                                  fi
   431                          fi
   432                          (
   433                                  pkgs=""
   434                                  if version_gte "18.09"; then
   435                                                  # older versions don't support a cli package
   436                                                  pkgs="$pkgs docker-ce-cli${cli_pkg_version%=}"
   437                                  fi
   438                                  if version_gte "20.10" && [ "$(uname -m)" = "x86_64" ]; then
   439                                                  # also install the latest version of the "docker scan" cli-plugin (only supported on x86 currently)
   440                                                  pkgs="$pkgs docker-scan-plugin"
   441                                  fi
   442                                  pkgs="$pkgs docker-ce${pkg_version%=}"
   443                                  if ! is_dry_run; then
   444                                          set -x
   445                                  fi
   446                                  $sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends $pkgs >/dev/null"
   447                                  if version_gte "20.10"; then
   448                                          # Install docker-ce-rootless-extras without "--no-install-recommends", so as to install slirp4netns when available
   449                                          $sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce-rootless-extras${pkg_version%=} >/dev/null"
   450                                  fi
   451                          )
   452                          echo_docker_as_nonroot
   453                          exit 0
   454                          ;;
   455                  centos|fedora|rhel)
   456                          if [ "$(uname -m)" != "s390x" ] && [ "$lsb_dist" = "rhel" ]; then
   457                                  echo "Packages for RHEL are currently only available for s390x."
   458                                  exit 1
   459                          fi
   460                          yum_repo="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
   461                          if ! curl -Ifs "$yum_repo" > /dev/null; then
   462                                  echo "Error: Unable to curl repository file $yum_repo, is it valid?"
   463                                  exit 1
   464                          fi
   465                          if [ "$lsb_dist" = "fedora" ]; then
   466                                  pkg_manager="dnf"
   467                                  config_manager="dnf config-manager"
   468                                  enable_channel_flag="--set-enabled"
   469                                  disable_channel_flag="--set-disabled"
   470                                  pre_reqs="dnf-plugins-core"
   471                                  pkg_suffix="fc$dist_version"
   472                          else
   473                                  pkg_manager="yum"
   474                                  config_manager="yum-config-manager"
   475                                  enable_channel_flag="--enable"
   476                                  disable_channel_flag="--disable"
   477                                  pre_reqs="yum-utils"
   478                                  pkg_suffix="el"
   479                          fi
   480                          (
   481                                  if ! is_dry_run; then
   482                                          set -x
   483                                  fi
   484                                  $sh_c "$pkg_manager install -y -q $pre_reqs"
   485                                  $sh_c "$config_manager --add-repo $yum_repo"
   486
   487                                  if [ "$CHANNEL" != "stable" ]; then
   488                                          $sh_c "$config_manager $disable_channel_flag docker-ce-*"
   489                                          $sh_c "$config_manager $enable_channel_flag docker-ce-$CHANNEL"
   490                                  fi
   491                                  $sh_c "$pkg_manager makecache"
   492                          )
   493                          pkg_version=""
   494                          if [ -n "$VERSION" ]; then
   495                                  if is_dry_run; then
   496                                          echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
   497                                  else
   498                                          pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/\\\\.ce.*/g" | sed "s/-/.*/g").*$pkg_suffix"
   499                                          search_command="$pkg_manager list --showduplicates 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
   500                                          pkg_version="$($sh_c "$search_command")"
   501                                          echo "INFO: Searching repository for VERSION '$VERSION'"
   502                                          echo "INFO: $search_command"
   503                                          if [ -z "$pkg_version" ]; then
   504                                                  echo
   505                                                  echo "ERROR: '$VERSION' not found amongst $pkg_manager list results"
   506                                                  echo
   507                                                  exit 1
   508                                          fi
   509                                          if version_gte "18.09"; then
   510                                                  # older versions don't support a cli package
   511                                                  search_command="$pkg_manager list --showduplicates 'docker-ce-cli' | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
   512                                                  cli_pkg_version="$($sh_c "$search_command" | cut -d':' -f 2)"
   513                                          fi
   514                                          # Cut out the epoch and prefix with a '-'
   515                                          pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)"
   516                                  fi
   517                          fi
   518                          (
   519                                  if ! is_dry_run; then
   520                                          set -x
   521                                  fi
   522                                  # install the correct cli version first
   523                                  if [ -n "$cli_pkg_version" ]; then
   524                                          $sh_c "$pkg_manager install -y -q docker-ce-cli-$cli_pkg_version"
   525                                  fi
   526                                  $sh_c "$pkg_manager install -y -q docker-ce$pkg_version"
   527                                  if version_gte "20.10"; then
   528                                          $sh_c "$pkg_manager install -y -q docker-ce-rootless-extras$pkg_version"
   529                                  fi
   530                          )
   531                          echo_docker_as_nonroot
   532                          exit 0
   533                          ;;
   534                  sles)
   535                          if [ "$(uname -m)" != "s390x" ]; then
   536                                  echo "Packages for SLES are currently only available for s390x"
   537                                  exit 1
   538                          fi
   539
   540                          sles_version="${dist_version##*.}"
   541                          sles_repo="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
   542                          opensuse_repo="https://download.opensuse.org/repositories/security:SELinux/SLE_15_SP$sles_version/security:SELinux.repo"
   543                          if ! curl -Ifs "$sles_repo" > /dev/null; then
   544                                  echo "Error: Unable to curl repository file $sles_repo, is it valid?"
   545                                  exit 1
   546                          fi
   547                          pre_reqs="ca-certificates curl libseccomp2 awk"
   548                          (
   549                                  if ! is_dry_run; then
   550                                          set -x
   551                                  fi
   552                                  $sh_c "zypper install -y $pre_reqs"
   553                                  $sh_c "zypper addrepo $sles_repo"
   554                                  if ! is_dry_run; then
   555                                                  cat >&2 <<-'EOF'
   556                                                  WARNING!!
   557                                                  openSUSE repository (https://download.opensuse.org/repositories/security:SELinux) will be enabled now.
   558                                                  Do you wish to continue?
   559                                                  You may press Ctrl+C now to abort this script.
   560                                                  EOF
   561                                                  ( set -x; sleep 30 )
   562                                  fi
   563                                  $sh_c "zypper addrepo $opensuse_repo"
   564                                  $sh_c "zypper --gpg-auto-import-keys refresh"
   565                                  $sh_c "zypper lr -d"
   566                          )
   567                          pkg_version=""
   568                          if [ -n "$VERSION" ]; then
   569                                  if is_dry_run; then
   570                                          echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
   571                                  else
   572                                          pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/\\\\.ce.*/g" | sed "s/-/.*/g")"
   573                                          search_command="zypper search -s --match-exact 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
   574                                          pkg_version="$($sh_c "$search_command")"
   575                                          echo "INFO: Searching repository for VERSION '$VERSION'"
   576                                          echo "INFO: $search_command"
   577                                          if [ -z "$pkg_version" ]; then
   578                                                  echo
   579                                                  echo "ERROR: '$VERSION' not found amongst zypper list results"
   580                                                  echo
   581                                                  exit 1
   582                                          fi
   583                                          search_command="zypper search -s --match-exact 'docker-ce-cli' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
   584                                          # It's okay for cli_pkg_version to be blank, since older versions don't support a cli package
   585                                          cli_pkg_version="$($sh_c "$search_command")"
   586                                          pkg_version="-$pkg_version"
   587
   588                                          search_command="zypper search -s --match-exact 'docker-ce-rootless-extras' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
   589                                          rootless_pkg_version="$($sh_c "$search_command")"
   590                                          rootless_pkg_version="-$rootless_pkg_version"
   591                                  fi
   592                          fi
   593                          (
   594                                  if ! is_dry_run; then
   595                                          set -x
   596                                  fi
   597                                  # install the correct cli version first
   598                                  if [ -n "$cli_pkg_version" ]; then
   599                                          $sh_c "zypper install -y  docker-ce-cli-$cli_pkg_version"
   600                                  fi
   601                                  $sh_c "zypper install -y docker-ce$pkg_version"
   602                                  if version_gte "20.10"; then
   603                                          $sh_c "zypper install -y docker-ce-rootless-extras$rootless_pkg_version"
   604                                  fi
   605                          )
   606                          echo_docker_as_nonroot
   607                          exit 0
   608                          ;;
   609                  *)
   610                          if [ -z "$lsb_dist" ]; then
   611                                  if is_darwin; then
   612                                          echo
   613                                          echo "ERROR: Unsupported operating system 'macOS'"
   614                                          echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
   615                                          echo
   616                                          exit 1
   617                                  fi
   618                          fi
   619                          echo
   620                          echo "ERROR: Unsupported distribution '$lsb_dist'"
   621                          echo
   622                          exit 1
   623                          ;;
   624          esac
   625          exit 1
   626  }
   627
   628  # wrapped up in a function so that we have some protection against only getting
   629  # half the file during "curl | sh"
   630  do_install

脚本2内容

[root@jumpserver ~]# curl -sSL https://get.daocloud.io/docker >docker_install2.sh
[root@jumpserver ~]#
[root@jumpserver ~]#
[root@jumpserver ~]# cat docker_install2.sh |cat -n
     1  #!/bin/sh
     2  set -e
     3  # Docker CE for Linux installation script
     4  #
     5  # See https://docs.docker.com/engine/install/ for the installation steps.
     6  #
     7  # This script is meant for quick & easy install via:
     8  #   $ curl -fsSL https://get.docker.com -o get-docker.sh
     9  #   $ sh get-docker.sh
    10  #
    11  # For test builds (ie. release candidates):
    12  #   $ curl -fsSL https://test.docker.com -o test-docker.sh
    13  #   $ sh test-docker.sh
    14  #
    15  # NOTE: Make sure to verify the contents of the script
    16  #       you downloaded matches the contents of install.sh
    17  #       located at https://github.com/docker/docker-install
    18  #       before executing.
    19  #
    20  # Git commit from https://github.com/docker/docker-install when
    21  # the script was uploaded (Should only be modified by upload job):
    22  SCRIPT_COMMIT_SHA="93d2499759296ac1f9c510605fef85052a2c32be"
    23
    24  # strip "v" prefix if present
    25  VERSION="${VERSION#v}"
    26
    27  # The channel to install from:
    28  #   * nightly
    29  #   * test
    30  #   * stable
    31  #   * edge (deprecated)
    32  DEFAULT_CHANNEL_VALUE="stable"
    33  if [ -z "$CHANNEL" ]; then
    34          CHANNEL=$DEFAULT_CHANNEL_VALUE
    35  fi
    36
    37  DEFAULT_DOWNLOAD_URL="https://download.docker.com"
    38  if [ -z "$DOWNLOAD_URL" ]; then
    39          DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
    40  fi
    41
    42  DEFAULT_REPO_FILE="docker-ce.repo"
    43  if [ -z "$REPO_FILE" ]; then
    44          REPO_FILE="$DEFAULT_REPO_FILE"
    45  fi
    46
    47  mirror=''
    48  DRY_RUN=${DRY_RUN:-}
    49  while [ $# -gt 0 ]; do
    50          case "$1" in
    51                  --mirror)
    52                          mirror="$2"
    53                          shift
    54                          ;;
    55                  --dry-run)
    56                          DRY_RUN=1
    57                          ;;
    58                  --*)
    59                          echo "Illegal option $1"
    60                          ;;
    61          esac
    62          shift $(( $# > 0 ? 1 : 0 ))
    63  done
    64
    65  case "$mirror" in
    66          Aliyun)
    67                  DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"
    68                  ;;
    69          AzureChinaCloud)
    70                  DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"
    71                  ;;
    72  esac
    73
    74  command_exists() {
    75          command -v "$@" > /dev/null 2>&1
    76  }
    77
    78  # version_gte checks if the version specified in $VERSION is at least
    79  # the given CalVer (YY.MM) version. returns 0 (success) if $VERSION is either
    80  # unset (=latest) or newer or equal than the specified version. Returns 1 (fail)
    81  # otherwise.
    82  #
    83  # examples:
    84  #
    85  # VERSION=20.10
    86  # version_gte 20.10 // 0 (success)
    87  # version_gte 19.03 // 0 (success)
    88  # version_gte 21.10 // 1 (fail)
    89  version_gte() {
    90          if [ -z "$VERSION" ]; then
    91                          return 0
    92          fi
    93          eval calver_compare "$VERSION" "$1"
    94  }
    95
    96  # calver_compare compares two CalVer (YY.MM) version strings. returns 0 (success)
    97  # if version A is newer or equal than version B, or 1 (fail) otherwise. Patch
    98  # releases and pre-release (-alpha/-beta) are not taken into account
    99  #
   100  # examples:
   101  #
   102  # calver_compare 20.10 19.03 // 0 (success)
   103  # calver_compare 20.10 20.10 // 0 (success)
   104  # calver_compare 19.03 20.10 // 1 (fail)
   105  calver_compare() (
   106          set +x
   107
   108          yy_a="$(echo "$1" | cut -d'.' -f1)"
   109          yy_b="$(echo "$2" | cut -d'.' -f1)"
   110          if [ "$yy_a" -lt "$yy_b" ]; then
   111                  return 1
   112          fi
   113          if [ "$yy_a" -gt "$yy_b" ]; then
   114                  return 0
   115          fi
   116          mm_a="$(echo "$1" | cut -d'.' -f2)"
   117          mm_b="$(echo "$2" | cut -d'.' -f2)"
   118          if [ "${mm_a#0}" -lt "${mm_b#0}" ]; then
   119                  return 1
   120          fi
   121
   122          return 0
   123  )
   124
   125  is_dry_run() {
   126          if [ -z "$DRY_RUN" ]; then
   127                  return 1
   128          else
   129                  return 0
   130          fi
   131  }
   132
   133  is_wsl() {
   134          case "$(uname -r)" in
   135          *microsoft* ) true ;; # WSL 2
   136          *Microsoft* ) true ;; # WSL 1
   137          * ) false;;
   138          esac
   139  }
   140
   141  is_darwin() {
   142          case "$(uname -s)" in
   143          *darwin* ) true ;;
   144          *Darwin* ) true ;;
   145          * ) false;;
   146          esac
   147  }
   148
   149  deprecation_notice() {
   150          distro=$1
   151          distro_version=$2
   152          echo
   153          printf "\033[91;1mDEPRECATION WARNING\033[0m\n"
   154          printf "    This Linux distribution (\033[1m%s %s\033[0m) reached end-of-life and is no longer supported by this script.\n" "$distro" "$distro_version"
   155          echo   "    No updates or security fixes will be released for this distribution, and users are recommended"
   156          echo   "    to upgrade to a currently maintained version of $distro."
   157          echo
   158          printf   "Press \033[1mCtrl+C\033[0m now to abort this script, or wait for the installation to continue."
   159          echo
   160          sleep 10
   161  }
   162
   163  get_distribution() {
   164          lsb_dist=""
   165          # Every system that we officially support has /etc/os-release
   166          if [ -r /etc/os-release ]; then
   167                  lsb_dist="$(. /etc/os-release && echo "$ID")"
   168          fi
   169          # Returning an empty string here should be alright since the
   170          # case statements don't act unless you provide an actual value
   171          echo "$lsb_dist"
   172  }
   173
   174  echo_docker_as_nonroot() {
   175          if is_dry_run; then
   176                  return
   177          fi
   178          if command_exists docker && [ -e /var/run/docker.sock ]; then
   179                  (
   180                          set -x
   181                          $sh_c 'docker version'
   182                  ) || true
   183          fi
   184
   185          # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
   186          echo
   187          echo "================================================================================"
   188          echo
   189          if version_gte "20.10"; then
   190                  echo "To run Docker as a non-privileged user, consider setting up the"
   191                  echo "Docker daemon in rootless mode for your user:"
   192                  echo
   193                  echo "    dockerd-rootless-setuptool.sh install"
   194                  echo
   195                  echo "Visit https://docs.docker.com/go/rootless/ to learn about rootless mode."
   196                  echo
   197          fi
   198          echo
   199          echo "To run the Docker daemon as a fully privileged service, but granting non-root"
   200          echo "users access, refer to https://docs.docker.com/go/daemon-access/"
   201          echo
   202          echo "WARNING: Access to the remote API on a privileged Docker daemon is equivalent"
   203          echo "         to root access on the host. Refer to the 'Docker daemon attack surface'"
   204          echo "         documentation for details: https://docs.docker.com/go/attack-surface/"
   205          echo
   206          echo "================================================================================"
   207          echo
   208  }
   209
   210  # Check if this is a forked Linux distro
   211  check_forked() {
   212
   213          # Check for lsb_release command existence, it usually exists in forked distros
   214          if command_exists lsb_release; then
   215                  # Check if the `-u` option is supported
   216                  set +e
   217                  lsb_release -a -u > /dev/null 2>&1
   218                  lsb_release_exit_code=$?
   219                  set -e
   220
   221                  # Check if the command has exited successfully, it means we're in a forked distro
   222                  if [ "$lsb_release_exit_code" = "0" ]; then
   223                          # Print info about current distro
   224                          cat <<-EOF
   225                          You're using '$lsb_dist' version '$dist_version'.
   226                          EOF
   227
   228                          # Get the upstream release info
   229                          lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')
   230                          dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')
   231
   232                          # Print info about upstream distro
   233                          cat <<-EOF
   234                          Upstream release is '$lsb_dist' version '$dist_version'.
   235                          EOF
   236                  else
   237                          if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
   238                                  if [ "$lsb_dist" = "osmc" ]; then
   239                                          # OSMC runs Raspbian
   240                                          lsb_dist=raspbian
   241                                  else
   242                                          # We're Debian and don't even know it!
   243                                          lsb_dist=debian
   244                                  fi
   245                                  dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
   246                                  case "$dist_version" in
   247                                          11)
   248                                                  dist_version="bullseye"
   249                                          ;;
   250                                          10)
   251                                                  dist_version="buster"
   252                                          ;;
   253                                          9)
   254                                                  dist_version="stretch"
   255                                          ;;
   256                                          8)
   257                                                  dist_version="jessie"
   258                                          ;;
   259                                  esac
   260                          fi
   261                  fi
   262          fi
   263  }
   264
   265  do_install() {
   266          echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"
   267
   268          if command_exists docker; then
   269                  cat >&2 <<-'EOF'
   270                          Warning: the "docker" command appears to already exist on this system.
   271
   272                          If you already have Docker installed, this script can cause trouble, which is
   273                          why we're displaying this warning and provide the opportunity to cancel the
   274                          installation.
   275
   276                          If you installed the current Docker package using this script and are using it
   277                          again to update Docker, you can safely ignore this message.
   278
   279                          You may press Ctrl+C now to abort this script.
   280                  EOF
   281                  ( set -x; sleep 20 )
   282          fi
   283
   284          user="$(id -un 2>/dev/null || true)"
   285
   286          sh_c='sh -c'
   287          if [ "$user" != 'root' ]; then
   288                  if command_exists sudo; then
   289                          sh_c='sudo -E sh -c'
   290                  elif command_exists su; then
   291                          sh_c='su -c'
   292                  else
   293                          cat >&2 <<-'EOF'
   294                          Error: this installer needs the ability to run commands as root.
   295                          We are unable to find either "sudo" or "su" available to make this happen.
   296                          EOF
   297                          exit 1
   298                  fi
   299          fi
   300
   301          if is_dry_run; then
   302                  sh_c="echo"
   303          fi
   304
   305          # perform some very rudimentary platform detection
   306          lsb_dist=$( get_distribution )
   307          lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
   308
   309          if is_wsl; then
   310                  echo
   311                  echo "WSL DETECTED: We recommend using Docker Desktop for Windows."
   312                  echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
   313                  echo
   314                  cat >&2 <<-'EOF'
   315
   316                          You may press Ctrl+C now to abort this script.
   317                  EOF
   318                  ( set -x; sleep 20 )
   319          fi
   320
   321          case "$lsb_dist" in
   322
   323                  ubuntu)
   324                          if command_exists lsb_release; then
   325                                  dist_version="$(lsb_release --codename | cut -f2)"
   326                          fi
   327                          if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
   328                                  dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
   329                          fi
   330                  ;;
   331
   332                  debian|raspbian)
   333                          dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
   334                          case "$dist_version" in
   335                                  11)
   336                                          dist_version="bullseye"
   337                                  ;;
   338                                  10)
   339                                          dist_version="buster"
   340                                  ;;
   341                                  9)
   342                                          dist_version="stretch"
   343                                  ;;
   344                                  8)
   345                                          dist_version="jessie"
   346                                  ;;
   347                          esac
   348                  ;;
   349
   350                  centos|rhel|sles)
   351                          if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
   352                                  dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
   353                          fi
   354                  ;;
   355
   356                  *)
   357                          if command_exists lsb_release; then
   358                                  dist_version="$(lsb_release --release | cut -f2)"
   359                          fi
   360                          if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
   361                                  dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
   362                          fi
   363                  ;;
   364
   365          esac
   366
   367          # Check if this is a forked Linux distro
   368          check_forked
   369
   370          # Print deprecation warnings for distro versions that recently reached EOL,
   371          # but may still be commonly used (especially LTS versions).
   372          case "$lsb_dist.$dist_version" in
   373                  debian.stretch|debian.jessie)
   374                          deprecation_notice "$lsb_dist" "$dist_version"
   375                          ;;
   376                  raspbian.stretch|raspbian.jessie)
   377                          deprecation_notice "$lsb_dist" "$dist_version"
   378                          ;;
   379                  ubuntu.xenial|ubuntu.trusty)
   380                          deprecation_notice "$lsb_dist" "$dist_version"
   381                          ;;
   382                  fedora.*)
   383                          if [ "$dist_version" -lt 33 ]; then
   384                                  deprecation_notice "$lsb_dist" "$dist_version"
   385                          fi
   386                          ;;
   387          esac
   388
   389          # Run setup for each distro accordingly
   390          case "$lsb_dist" in
   391                  ubuntu|debian|raspbian)
   392                          pre_reqs="apt-transport-https ca-certificates curl"
   393                          if ! command -v gpg > /dev/null; then
   394                                  pre_reqs="$pre_reqs gnupg"
   395                          fi
   396                          apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $DOWNLOAD_URL/linux/$lsb_dist $dist_version $CHANNEL"
   397                          (
   398                                  if ! is_dry_run; then
   399                                          set -x
   400                                  fi
   401                                  $sh_c 'apt-get update -qq >/dev/null'
   402                                  $sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pre_reqs >/dev/null"
   403                                  $sh_c "curl -fsSL \"$DOWNLOAD_URL/linux/$lsb_dist/gpg\" | gpg --dearmor --yes -o /usr/share/keyrings/docker-archive-keyring.gpg"
   404                                  $sh_c "echo \"$apt_repo\" > /etc/apt/sources.list.d/docker.list"
   405                                  $sh_c 'apt-get update -qq >/dev/null'
   406                          )
   407                          pkg_version=""
   408                          if [ -n "$VERSION" ]; then
   409                                  if is_dry_run; then
   410                                          echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
   411                                  else
   412                                          # Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel
   413                                          pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/~ce~.*/g" | sed "s/-/.*/g").*-0~$lsb_dist"
   414                                          search_command="apt-cache madison 'docker-ce' | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
   415                                          pkg_version="$($sh_c "$search_command")"
   416                                          echo "INFO: Searching repository for VERSION '$VERSION'"
   417                                          echo "INFO: $search_command"
   418                                          if [ -z "$pkg_version" ]; then
   419                                                  echo
   420                                                  echo "ERROR: '$VERSION' not found amongst apt-cache madison results"
   421                                                  echo
   422                                                  exit 1
   423                                          fi
   424                                          if version_gte "18.09"; then
   425                                                          search_command="apt-cache madison 'docker-ce-cli' | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
   426                                                          echo "INFO: $search_command"
   427                                                          cli_pkg_version="=$($sh_c "$search_command")"
   428                                          fi
   429                                          pkg_version="=$pkg_version"
   430                                  fi
   431                          fi
   432                          (
   433                                  pkgs=""
   434                                  if version_gte "18.09"; then
   435                                                  # older versions don't support a cli package
   436                                                  pkgs="$pkgs docker-ce-cli${cli_pkg_version%=}"
   437                                  fi
   438                                  if version_gte "20.10" && [ "$(uname -m)" = "x86_64" ]; then
   439                                                  # also install the latest version of the "docker scan" cli-plugin (only supported on x86 currently)
   440                                                  pkgs="$pkgs docker-scan-plugin"
   441                                  fi
   442                                  pkgs="$pkgs docker-ce${pkg_version%=}"
   443                                  if ! is_dry_run; then
   444                                          set -x
   445                                  fi
   446                                  $sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends $pkgs >/dev/null"
   447                                  if version_gte "20.10"; then
   448                                          # Install docker-ce-rootless-extras without "--no-install-recommends", so as to install slirp4netns when available
   449                                          $sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce-rootless-extras${pkg_version%=} >/dev/null"
   450                                  fi
   451                          )
   452                          echo_docker_as_nonroot
   453                          exit 0
   454                          ;;
   455                  centos|fedora|rhel)
   456                          if [ "$(uname -m)" != "s390x" ] && [ "$lsb_dist" = "rhel" ]; then
   457                                  echo "Packages for RHEL are currently only available for s390x."
   458                                  exit 1
   459                          fi
   460                          yum_repo="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
   461                          if ! curl -Ifs "$yum_repo" > /dev/null; then
   462                                  echo "Error: Unable to curl repository file $yum_repo, is it valid?"
   463                                  exit 1
   464                          fi
   465                          if [ "$lsb_dist" = "fedora" ]; then
   466                                  pkg_manager="dnf"
   467                                  config_manager="dnf config-manager"
   468                                  enable_channel_flag="--set-enabled"
   469                                  disable_channel_flag="--set-disabled"
   470                                  pre_reqs="dnf-plugins-core"
   471                                  pkg_suffix="fc$dist_version"
   472                          else
   473                                  pkg_manager="yum"
   474                                  config_manager="yum-config-manager"
   475                                  enable_channel_flag="--enable"
   476                                  disable_channel_flag="--disable"
   477                                  pre_reqs="yum-utils"
   478                                  pkg_suffix="el"
   479                          fi
   480                          (
   481                                  if ! is_dry_run; then
   482                                          set -x
   483                                  fi
   484                                  $sh_c "$pkg_manager install -y -q $pre_reqs"
   485                                  $sh_c "$config_manager --add-repo $yum_repo"
   486
   487                                  if [ "$CHANNEL" != "stable" ]; then
   488                                          $sh_c "$config_manager $disable_channel_flag docker-ce-*"
   489                                          $sh_c "$config_manager $enable_channel_flag docker-ce-$CHANNEL"
   490                                  fi
   491                                  $sh_c "$pkg_manager makecache"
   492                          )
   493                          pkg_version=""
   494                          if [ -n "$VERSION" ]; then
   495                                  if is_dry_run; then
   496                                          echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
   497                                  else
   498                                          pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/\\\\.ce.*/g" | sed "s/-/.*/g").*$pkg_suffix"
   499                                          search_command="$pkg_manager list --showduplicates 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
   500                                          pkg_version="$($sh_c "$search_command")"
   501                                          echo "INFO: Searching repository for VERSION '$VERSION'"
   502                                          echo "INFO: $search_command"
   503                                          if [ -z "$pkg_version" ]; then
   504                                                  echo
   505                                                  echo "ERROR: '$VERSION' not found amongst $pkg_manager list results"
   506                                                  echo
   507                                                  exit 1
   508                                          fi
   509                                          if version_gte "18.09"; then
   510                                                  # older versions don't support a cli package
   511                                                  search_command="$pkg_manager list --showduplicates 'docker-ce-cli' | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
   512                                                  cli_pkg_version="$($sh_c "$search_command" | cut -d':' -f 2)"
   513                                          fi
   514                                          # Cut out the epoch and prefix with a '-'
   515                                          pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)"
   516                                  fi
   517                          fi
   518                          (
   519                                  if ! is_dry_run; then
   520                                          set -x
   521                                  fi
   522                                  # install the correct cli version first
   523                                  if [ -n "$cli_pkg_version" ]; then
   524                                          $sh_c "$pkg_manager install -y -q docker-ce-cli-$cli_pkg_version"
   525                                  fi
   526                                  $sh_c "$pkg_manager install -y -q docker-ce$pkg_version"
   527                                  if version_gte "20.10"; then
   528                                          $sh_c "$pkg_manager install -y -q docker-ce-rootless-extras$pkg_version"
   529                                  fi
   530                          )
   531                          echo_docker_as_nonroot
   532                          exit 0
   533                          ;;
   534                  sles)
   535                          if [ "$(uname -m)" != "s390x" ]; then
   536                                  echo "Packages for SLES are currently only available for s390x"
   537                                  exit 1
   538                          fi
   539
   540                          sles_version="${dist_version##*.}"
   541                          sles_repo="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
   542                          opensuse_repo="https://download.opensuse.org/repositories/security:SELinux/SLE_15_SP$sles_version/security:SELinux.repo"
   543                          if ! curl -Ifs "$sles_repo" > /dev/null; then
   544                                  echo "Error: Unable to curl repository file $sles_repo, is it valid?"
   545                                  exit 1
   546                          fi
   547                          pre_reqs="ca-certificates curl libseccomp2 awk"
   548                          (
   549                                  if ! is_dry_run; then
   550                                          set -x
   551                                  fi
   552                                  $sh_c "zypper install -y $pre_reqs"
   553                                  $sh_c "zypper addrepo $sles_repo"
   554                                  if ! is_dry_run; then
   555                                                  cat >&2 <<-'EOF'
   556                                                  WARNING!!
   557                                                  openSUSE repository (https://download.opensuse.org/repositories/security:SELinux) will be enabled now.
   558                                                  Do you wish to continue?
   559                                                  You may press Ctrl+C now to abort this script.
   560                                                  EOF
   561                                                  ( set -x; sleep 30 )
   562                                  fi
   563                                  $sh_c "zypper addrepo $opensuse_repo"
   564                                  $sh_c "zypper --gpg-auto-import-keys refresh"
   565                                  $sh_c "zypper lr -d"
   566                          )
   567                          pkg_version=""
   568                          if [ -n "$VERSION" ]; then
   569                                  if is_dry_run; then
   570                                          echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
   571                                  else
   572                                          pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/\\\\.ce.*/g" | sed "s/-/.*/g")"
   573                                          search_command="zypper search -s --match-exact 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
   574                                          pkg_version="$($sh_c "$search_command")"
   575                                          echo "INFO: Searching repository for VERSION '$VERSION'"
   576                                          echo "INFO: $search_command"
   577                                          if [ -z "$pkg_version" ]; then
   578                                                  echo
   579                                                  echo "ERROR: '$VERSION' not found amongst zypper list results"
   580                                                  echo
   581                                                  exit 1
   582                                          fi
   583                                          search_command="zypper search -s --match-exact 'docker-ce-cli' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
   584                                          # It's okay for cli_pkg_version to be blank, since older versions don't support a cli package
   585                                          cli_pkg_version="$($sh_c "$search_command")"
   586                                          pkg_version="-$pkg_version"
   587
   588                                          search_command="zypper search -s --match-exact 'docker-ce-rootless-extras' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
   589                                          rootless_pkg_version="$($sh_c "$search_command")"
   590                                          rootless_pkg_version="-$rootless_pkg_version"
   591                                  fi
   592                          fi
   593                          (
   594                                  if ! is_dry_run; then
   595                                          set -x
   596                                  fi
   597                                  # install the correct cli version first
   598                                  if [ -n "$cli_pkg_version" ]; then
   599                                          $sh_c "zypper install -y  docker-ce-cli-$cli_pkg_version"
   600                                  fi
   601                                  $sh_c "zypper install -y docker-ce$pkg_version"
   602                                  if version_gte "20.10"; then
   603                                          $sh_c "zypper install -y docker-ce-rootless-extras$rootless_pkg_version"
   604                                  fi
   605                          )
   606                          echo_docker_as_nonroot
   607                          exit 0
   608                          ;;
   609                  *)
   610                          if [ -z "$lsb_dist" ]; then
   611                                  if is_darwin; then
   612                                          echo
   613                                          echo "ERROR: Unsupported operating system 'macOS'"
   614                                          echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
   615                                          echo
   616                                          exit 1
   617                                  fi
   618                          fi
   619                          echo
   620                          echo "ERROR: Unsupported distribution '$lsb_dist'"
   621                          echo
   622                          exit 1
   623                          ;;
   624          esac
   625          exit 1
   626  }
   627
   628  # wrapped up in a function so that we have some protection against only getting
   629  # half the file during "curl | sh"
   630  do_install

最后更新: 2022-02-19 13:51:47