2121# the script was uploaded (Should only be modified by upload job):
2222SCRIPT_COMMIT_SHA=" ${LOAD_SCRIPT_COMMIT_SHA} "
2323
24+ # strip "v" prefix if present
25+ VERSION=" ${VERSION# v} "
2426
2527# The channel to install from:
2628# * nightly
@@ -69,16 +71,57 @@ case "$mirror" in
6971 ;;
7072esac
7173
72- # docker-ce-rootless-extras is packaged since Docker 20.10.0
73- has_rootless_extras=" 1"
74- if echo " $VERSION " | grep -q ' ^1' ; then
75- has_rootless_extras=
76- fi
77-
7874command_exists () {
7975 command -v " $@ " > /dev/null 2>&1
8076}
8177
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+
82125is_dry_run () {
83126 if [ -z " $DRY_RUN " ]; then
84127 return 1
@@ -148,7 +191,7 @@ echo_docker_as_nonroot() {
148191 echo
149192 echo " ================================================================================"
150193 echo
151- if [ -n " $has_rootless_extras " ] ; then
194+ if version_gte " 20.10 " ; then
152195 echo " To run Docker as a non-privileged user, consider setting up the"
153196 echo " Docker daemon in rootless mode for your user:"
154197 echo
@@ -365,24 +408,32 @@ do_install() {
365408 echo
366409 exit 1
367410 fi
368- search_command=" apt-cache madison 'docker-ce-cli' | grep '$pkg_pattern ' | head -1 | awk '{\$ 1=\$ 1};1' | cut -d' ' -f 3"
369- # Don't insert an = for cli_pkg_version, we'll just include it later
370- cli_pkg_version=" $( $sh_c " $search_command " ) "
411+ if version_gte " 18.09" ; then
412+ search_command=" apt-cache madison 'docker-ce-cli' | grep '$pkg_pattern ' | head -1 | awk '{\$ 1=\$ 1};1' | cut -d' ' -f 3"
413+ echo " INFO: $search_command "
414+ cli_pkg_version=" =$( $sh_c " $search_command " ) "
415+ fi
371416 pkg_version=" =$pkg_version "
372417 fi
373418 fi
374419 (
420+ pkgs=" "
421+ if version_gte " 18.09" ; then
422+ # older versions don't support a cli package
423+ pkgs=" $pkgs docker-ce-cli${cli_pkg_version% =} "
424+ fi
425+ if version_gte " 20.10" && [ " $( uname -m) " = " x86_64" ]; then
426+ # also install the latest version of the "docker scan" cli-plugin (only supported on x86 currently)
427+ pkgs=" $pkgs docker-scan-plugin"
428+ fi
429+ pkgs=" $pkgs docker-ce${pkg_version% =} "
375430 if ! is_dry_run; then
376431 set -x
377432 fi
378- if [ -n " $cli_pkg_version " ]; then
379- $sh_c " apt-get install -y -qq --no-install-recommends docker-ce-cli=$cli_pkg_version >/dev/null"
380- fi
381- $sh_c " apt-get install -y -qq --no-install-recommends docker-ce$pkg_version >/dev/null"
382- # shellcheck disable=SC2030
383- if [ -n " $has_rootless_extras " ]; then
433+ $sh_c " DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends $pkgs >/dev/null"
434+ if version_gte " 20.10" ; then
384435 # Install docker-ce-rootless-extras without "--no-install-recommends", so as to install slirp4netns when available
385- $sh_c " DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce-rootless-extras$pkg_version >/dev/null"
436+ $sh_c " DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce-rootless-extras${ pkg_version% =} >/dev/null"
386437 fi
387438 )
388439 echo_docker_as_nonroot
@@ -438,9 +489,11 @@ do_install() {
438489 echo
439490 exit 1
440491 fi
441- search_command=" $pkg_manager list --showduplicates 'docker-ce-cli' | grep '$pkg_pattern ' | tail -1 | awk '{print \$ 2}'"
442- # It's okay for cli_pkg_version to be blank, since older versions don't support a cli package
443- cli_pkg_version=" $( $sh_c " $search_command " | cut -d' :' -f 2) "
492+ if version_gte " 18.09" ; then
493+ # older versions don't support a cli package
494+ search_command=" $pkg_manager list --showduplicates 'docker-ce-cli' | grep '$pkg_pattern ' | tail -1 | awk '{print \$ 2}'"
495+ cli_pkg_version=" $( $sh_c " $search_command " | cut -d' :' -f 2) "
496+ fi
444497 # Cut out the epoch and prefix with a '-'
445498 pkg_version=" -$( echo " $pkg_version " | cut -d' :' -f 2) "
446499 fi
@@ -454,8 +507,7 @@ do_install() {
454507 $sh_c " $pkg_manager install -y -q docker-ce-cli-$cli_pkg_version "
455508 fi
456509 $sh_c " $pkg_manager install -y -q docker-ce$pkg_version "
457- # shellcheck disable=SC2031
458- if [ -n " $has_rootless_extras " ]; then
510+ if version_gte " 20.10" ; then
459511 $sh_c " $pkg_manager install -y -q docker-ce-rootless-extras$pkg_version "
460512 fi
461513 )
0 commit comments