Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/get-docker.sh
1292 views
1
#!/bin/sh
2
set -e
3
# Docker CE for Linux installation script
4
#
5
# See https://docs.docker.com/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="3d8fe77c2c46c5b7571f94b42793905e5b3e42e4"
23
24
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
35
DEFAULT_DOWNLOAD_URL="https://download.docker.com"
36
if [ -z "$DOWNLOAD_URL" ]; then
37
DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
38
fi
39
40
DEFAULT_REPO_FILE="docker-ce.repo"
41
if [ -z "$REPO_FILE" ]; then
42
REPO_FILE="$DEFAULT_REPO_FILE"
43
fi
44
45
mirror=''
46
DRY_RUN=${DRY_RUN:-}
47
while [ $# -gt 0 ]; do
48
case "$1" in
49
--mirror)
50
mirror="$2"
51
shift
52
;;
53
--dry-run)
54
DRY_RUN=1
55
;;
56
--*)
57
echo "Illegal option $1"
58
;;
59
esac
60
shift $(( $# > 0 ? 1 : 0 ))
61
done
62
63
case "$mirror" in
64
Aliyun)
65
DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"
66
;;
67
AzureChinaCloud)
68
DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"
69
;;
70
esac
71
72
command_exists() {
73
command -v "$@" > /dev/null 2>&1
74
}
75
76
is_dry_run() {
77
if [ -z "$DRY_RUN" ]; then
78
return 1
79
else
80
return 0
81
fi
82
}
83
84
is_wsl() {
85
case "$(uname -r)" in
86
*microsoft* ) true ;; # WSL 2
87
*Microsoft* ) true ;; # WSL 1
88
* ) false;;
89
esac
90
}
91
92
is_darwin() {
93
case "$(uname -s)" in
94
*darwin* ) true ;;
95
*Darwin* ) true ;;
96
* ) false;;
97
esac
98
}
99
100
deprecation_notice() {
101
distro=$1
102
date=$2
103
echo
104
echo "DEPRECATION WARNING:"
105
echo " The distribution, $distro, will no longer be supported in this script as of $date."
106
echo " If you feel this is a mistake please submit an issue at https://github.com/docker/docker-install/issues/new"
107
echo
108
sleep 10
109
}
110
111
get_distribution() {
112
lsb_dist=""
113
# Every system that we officially support has /etc/os-release
114
if [ -r /etc/os-release ]; then
115
lsb_dist="$(. /etc/os-release && echo "$ID")"
116
fi
117
# Returning an empty string here should be alright since the
118
# case statements don't act unless you provide an actual value
119
echo "$lsb_dist"
120
}
121
122
add_debian_backport_repo() {
123
debian_version="$1"
124
backports="deb http://ftp.debian.org/debian $debian_version-backports main"
125
if ! grep -Fxq "$backports" /etc/apt/sources.list; then
126
(set -x; $sh_c "echo \"$backports\" >> /etc/apt/sources.list")
127
fi
128
}
129
130
echo_docker_as_nonroot() {
131
if is_dry_run; then
132
return
133
fi
134
if command_exists docker && [ -e /var/run/docker.sock ]; then
135
(
136
set -x
137
$sh_c 'docker version'
138
) || true
139
fi
140
your_user=your-user
141
[ "$user" != 'root' ] && your_user="$user"
142
# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
143
echo "If you would like to use Docker as a non-root user, you should now consider"
144
echo "adding your user to the \"docker\" group with something like:"
145
echo
146
echo " sudo usermod -aG docker $your_user"
147
echo
148
echo "Remember that you will have to log out and back in for this to take effect!"
149
echo
150
echo "WARNING: Adding a user to the \"docker\" group will grant the ability to run"
151
echo " containers which can be used to obtain root privileges on the"
152
echo " docker host."
153
echo " Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface"
154
echo " for more information."
155
156
}
157
158
# Check if this is a forked Linux distro
159
check_forked() {
160
161
# Check for lsb_release command existence, it usually exists in forked distros
162
if command_exists lsb_release; then
163
# Check if the `-u` option is supported
164
set +e
165
lsb_release -a -u > /dev/null 2>&1
166
lsb_release_exit_code=$?
167
set -e
168
169
# Check if the command has exited successfully, it means we're in a forked distro
170
if [ "$lsb_release_exit_code" = "0" ]; then
171
# Print info about current distro
172
cat <<-EOF
173
You're using '$lsb_dist' version '$dist_version'.
174
EOF
175
176
# Get the upstream release info
177
lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')
178
dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')
179
180
# Print info about upstream distro
181
cat <<-EOF
182
Upstream release is '$lsb_dist' version '$dist_version'.
183
EOF
184
else
185
if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
186
if [ "$lsb_dist" = "osmc" ]; then
187
# OSMC runs Raspbian
188
lsb_dist=raspbian
189
else
190
# We're Debian and don't even know it!
191
lsb_dist=debian
192
fi
193
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
194
case "$dist_version" in
195
10)
196
dist_version="buster"
197
;;
198
9)
199
dist_version="stretch"
200
;;
201
8|'Kali Linux 2')
202
dist_version="jessie"
203
;;
204
esac
205
fi
206
fi
207
fi
208
}
209
210
semverParse() {
211
major="${1%%.*}"
212
minor="${1#$major.}"
213
minor="${minor%%.*}"
214
patch="${1#$major.$minor.}"
215
patch="${patch%%[-.]*}"
216
}
217
218
do_install() {
219
echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"
220
221
if command_exists docker; then
222
docker_version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)"
223
MAJOR_W=1
224
MINOR_W=10
225
226
semverParse "$docker_version"
227
228
shouldWarn=0
229
if [ "$major" -lt "$MAJOR_W" ]; then
230
shouldWarn=1
231
fi
232
233
if [ "$major" -le "$MAJOR_W" ] && [ "$minor" -lt "$MINOR_W" ]; then
234
shouldWarn=1
235
fi
236
237
cat >&2 <<-'EOF'
238
Warning: the "docker" command appears to already exist on this system.
239
240
If you already have Docker installed, this script can cause trouble, which is
241
why we're displaying this warning and provide the opportunity to cancel the
242
installation.
243
244
If you installed the current Docker package using this script and are using it
245
EOF
246
247
if [ $shouldWarn -eq 1 ]; then
248
cat >&2 <<-'EOF'
249
again to update Docker, we urge you to migrate your image store before upgrading
250
to v1.10+.
251
252
You can find instructions for this here:
253
https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration
254
EOF
255
else
256
cat >&2 <<-'EOF'
257
again to update Docker, you can safely ignore this message.
258
EOF
259
fi
260
261
cat >&2 <<-'EOF'
262
263
You may press Ctrl+C now to abort this script.
264
EOF
265
( set -x; sleep 20 )
266
fi
267
268
user="$(id -un 2>/dev/null || true)"
269
270
sh_c='sh -c'
271
if [ "$user" != 'root' ]; then
272
if command_exists sudo; then
273
sh_c='sudo -E sh -c'
274
elif command_exists su; then
275
sh_c='su -c'
276
else
277
cat >&2 <<-'EOF'
278
Error: this installer needs the ability to run commands as root.
279
We are unable to find either "sudo" or "su" available to make this happen.
280
EOF
281
exit 1
282
fi
283
fi
284
285
if is_dry_run; then
286
sh_c="echo"
287
fi
288
289
# perform some very rudimentary platform detection
290
lsb_dist=$( get_distribution )
291
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
292
293
if is_wsl; then
294
echo
295
echo "WSL DETECTED: We recommend using Docker Desktop for Windows."
296
echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
297
echo
298
cat >&2 <<-'EOF'
299
300
You may press Ctrl+C now to abort this script.
301
EOF
302
( set -x; sleep 20 )
303
fi
304
305
case "$lsb_dist" in
306
307
ubuntu)
308
if command_exists lsb_release; then
309
dist_version="$(lsb_release --codename | cut -f2)"
310
fi
311
if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
312
dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
313
fi
314
;;
315
316
debian|raspbian)
317
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
318
case "$dist_version" in
319
10)
320
dist_version="buster"
321
;;
322
9)
323
dist_version="stretch"
324
;;
325
8)
326
dist_version="jessie"
327
;;
328
esac
329
;;
330
331
centos|rhel)
332
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
333
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
334
fi
335
;;
336
337
*)
338
if command_exists lsb_release; then
339
dist_version="$(lsb_release --release | cut -f2)"
340
fi
341
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
342
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
343
fi
344
;;
345
346
esac
347
348
# Check if this is a forked Linux distro
349
check_forked
350
351
# Run setup for each distro accordingly
352
case "$lsb_dist" in
353
ubuntu|debian|raspbian)
354
pre_reqs="apt-transport-https ca-certificates curl"
355
if [ "$lsb_dist" = "debian" ]; then
356
# libseccomp2 does not exist for debian jessie main repos for aarch64
357
if [ "$(uname -m)" = "aarch64" ] && [ "$dist_version" = "jessie" ]; then
358
add_debian_backport_repo "$dist_version"
359
fi
360
fi
361
362
if ! command -v gpg > /dev/null; then
363
pre_reqs="$pre_reqs gnupg"
364
fi
365
apt_repo="deb [arch=$(dpkg --print-architecture)] $DOWNLOAD_URL/linux/$lsb_dist $dist_version $CHANNEL"
366
(
367
if ! is_dry_run; then
368
set -x
369
fi
370
$sh_c 'apt-get update -qq >/dev/null'
371
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pre_reqs >/dev/null"
372
$sh_c "curl -fsSL \"$DOWNLOAD_URL/linux/$lsb_dist/gpg\" | apt-key add -qq - >/dev/null"
373
$sh_c "echo \"$apt_repo\" > /etc/apt/sources.list.d/docker.list"
374
$sh_c 'apt-get update -qq >/dev/null'
375
)
376
pkg_version=""
377
if [ -n "$VERSION" ]; then
378
if is_dry_run; then
379
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
380
else
381
# Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel
382
pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/~ce~.*/g" | sed "s/-/.*/g").*-0~$lsb_dist"
383
search_command="apt-cache madison 'docker-ce' | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
384
pkg_version="$($sh_c "$search_command")"
385
echo "INFO: Searching repository for VERSION '$VERSION'"
386
echo "INFO: $search_command"
387
if [ -z "$pkg_version" ]; then
388
echo
389
echo "ERROR: '$VERSION' not found amongst apt-cache madison results"
390
echo
391
exit 1
392
fi
393
search_command="apt-cache madison 'docker-ce-cli' | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
394
# Don't insert an = for cli_pkg_version, we'll just include it later
395
cli_pkg_version="$($sh_c "$search_command")"
396
pkg_version="=$pkg_version"
397
fi
398
fi
399
(
400
if ! is_dry_run; then
401
set -x
402
fi
403
if [ -n "$cli_pkg_version" ]; then
404
$sh_c "apt-get install -y -qq --no-install-recommends docker-ce-cli=$cli_pkg_version >/dev/null"
405
fi
406
$sh_c "apt-get install -y -qq --no-install-recommends docker-ce$pkg_version >/dev/null"
407
)
408
echo_docker_as_nonroot
409
exit 0
410
;;
411
centos|fedora|rhel)
412
yum_repo="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
413
if ! curl -Ifs "$yum_repo" > /dev/null; then
414
echo "Error: Unable to curl repository file $yum_repo, is it valid?"
415
exit 1
416
fi
417
if [ "$lsb_dist" = "fedora" ]; then
418
pkg_manager="dnf"
419
config_manager="dnf config-manager"
420
enable_channel_flag="--set-enabled"
421
disable_channel_flag="--set-disabled"
422
pre_reqs="dnf-plugins-core"
423
pkg_suffix="fc$dist_version"
424
else
425
pkg_manager="yum"
426
config_manager="yum-config-manager"
427
enable_channel_flag="--enable"
428
disable_channel_flag="--disable"
429
pre_reqs="yum-utils"
430
pkg_suffix="el"
431
fi
432
(
433
if ! is_dry_run; then
434
set -x
435
fi
436
$sh_c "$pkg_manager install -y -q $pre_reqs"
437
$sh_c "$config_manager --add-repo $yum_repo"
438
439
if [ "$CHANNEL" != "stable" ]; then
440
$sh_c "$config_manager $disable_channel_flag docker-ce-*"
441
$sh_c "$config_manager $enable_channel_flag docker-ce-$CHANNEL"
442
fi
443
$sh_c "$pkg_manager makecache"
444
)
445
pkg_version=""
446
if [ -n "$VERSION" ]; then
447
if is_dry_run; then
448
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
449
else
450
pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/\\\\.ce.*/g" | sed "s/-/.*/g").*$pkg_suffix"
451
search_command="$pkg_manager list --showduplicates 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
452
pkg_version="$($sh_c "$search_command")"
453
echo "INFO: Searching repository for VERSION '$VERSION'"
454
echo "INFO: $search_command"
455
if [ -z "$pkg_version" ]; then
456
echo
457
echo "ERROR: '$VERSION' not found amongst $pkg_manager list results"
458
echo
459
exit 1
460
fi
461
search_command="$pkg_manager list --showduplicates 'docker-ce-cli' | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
462
# It's okay for cli_pkg_version to be blank, since older versions don't support a cli package
463
cli_pkg_version="$($sh_c "$search_command" | cut -d':' -f 2)"
464
# Cut out the epoch and prefix with a '-'
465
pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)"
466
fi
467
fi
468
(
469
if ! is_dry_run; then
470
set -x
471
fi
472
# install the correct cli version first
473
if [ -n "$cli_pkg_version" ]; then
474
$sh_c "$pkg_manager install -y -q docker-ce-cli-$cli_pkg_version"
475
fi
476
$sh_c "$pkg_manager install -y -q docker-ce$pkg_version"
477
)
478
echo_docker_as_nonroot
479
exit 0
480
;;
481
*)
482
if [ -z "$lsb_dist" ]; then
483
if is_darwin; then
484
echo
485
echo "ERROR: Unsupported operating system 'macOS'"
486
echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
487
echo
488
exit 1
489
fi
490
fi
491
echo
492
echo "ERROR: Unsupported distribution '$lsb_dist'"
493
echo
494
exit 1
495
;;
496
esac
497
exit 1
498
}
499
500
# wrapped up in a function so that we have some protection against only getting
501
# half the file during "curl | sh"
502
do_install
503
504