abdoolamunir commited on
Commit
23d7cec
1 Parent(s): ecc5f2a

Create get-docker.sh

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