install_docker.sh 18 KB

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