forked from SuperManito/LinuxMirrors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerInstallation.sh
682 lines (661 loc) · 23.8 KB
/
DockerInstallation.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
#!/bin/bash
## Author: SuperManito
## Modified: 2021-09-09
## License: GPL-2.0
## Repository: https://github.com/SuperManito/LinuxMirrors
## https://gitee.com/SuperManito/LinuxMirrors
function AuthorSignature() {
if [ ${SYSTEM_FACTIONS} = ${SYSTEM_DEBIAN} ]; then
apt-get install -y figlet toilet >/dev/null 2>&1
elif [ ${SYSTEM_FACTIONS} = ${SYSTEM_REDHAT} ]; then
yum install -y figlet toilet >/dev/null 2>&1
fi
if [[ $? -eq 0 ]]; then
echo -e "\n$(toilet -f slant -F border --gay SuperManito)\n"
else
echo -e '\n\033[35m _____ __ ___ _ __ \033[0m'
echo -e '\033[31m / ___/__ ______ ___ _____/ |/ /___ _____ (_) /_____ \033[0m'
echo -e '\033[33m \__ \/ / / / __ \/ _ \/ ___/ /|_/ / __ `/ __ \/ / __/ __ \ \033[0m'
echo -e '\033[32m ___/ / /_/ / /_/ / __/ / / / / / /_/ / / / / / /_/ /_/ / \033[0m'
echo -e '\033[36m /____/\__,_/ .___/\___/_/ /_/ /_/\__,_/_/ /_/_/\__/\____/ \033[0m'
echo -e '\033[34m /_/ \033[0m\n'
fi
}
## 定义系统判定变量
DebianRelease=lsb_release
Arch=$(uname -m)
SYSTEM_DEBIAN="Debian"
SYSTEM_UBUNTU="Ubuntu"
SYSTEM_KALI="Kali"
SYSTEM_REDHAT="RedHat"
SYSTEM_RHEL="RedHat"
SYSTEM_CENTOS="CentOS"
SYSTEM_FEDORA="Fedora"
## 定义目录和文件
LinuxRelease=/etc/os-release
RedHatRelease=/etc/redhat-release
DebianSourceList=/etc/apt/sources.list
DebianExtendListDir=/etc/apt/sources.list.d
RedHatReposDir=/etc/yum.repos.d
SelinuxConfig=/etc/selinux/config
## 定义 Docker 相关变量
DockerSourceList=$DebianExtendListDir/docker.list
DockerRepo=$RedHatReposDir/download.docker.com_linux_*.repo
DockerDir=/etc/docker
DockerConfig=$DockerDir/daemon.json
DockerConfigBackup=$DockerDir/daemon.json.bak
DockerCompose=/usr/local/bin/docker-compose
DockerVersionFile=docker-version.txt
DockerCEVersionFile=docker-ce-version.txt
DockerCECLIVersionFile=docker-ce-cli-version.txt
PROXY_URL=https://ghproxy.com/
DOCKER_COMPOSE_VERSION=1.29.2
DOCKER_COMPOSE_DOWNLOAD_URL=https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-Linux-x86_64
## 组合函数
function Combin_Function() {
PermissionJudgment
NetWorkJudgment && clear
EnvJudgment
ChooseMirrors
InstallationEnvironment
ConfigureDockerCEMirror
DockerEngine
DockerCompose
ShowVersion
AuthorSignature
}
## 系统判定变量
function EnvJudgment() {
## 判定当前系统基于 Debian or RedHat
if [ -f $RedHatRelease ]; then
SYSTEM_FACTIONS=${SYSTEM_REDHAT}
else
SYSTEM_FACTIONS=${SYSTEM_DEBIAN}
fi
## 定义系统名称
SYSTEM_NAME=$(cat $LinuxRelease | grep -E "^NAME" | awk -F '\"' '{print$2}')
## 定义系统版本号
SYSTEM_VERSION_NUMBER=$(cat $LinuxRelease | grep -E "VERSION_ID" | awk -F '\"' '{print$2}')
## 判定系统名称、版本、版本号
case ${SYSTEM_FACTIONS} in
Debian)
SYSTEM_JUDGMENT=$(${DebianRelease} -is)
SYSTEM_VERSION=$(${DebianRelease} -cs)
;;
RedHat)
SYSTEM_JUDGMENT=$(cat $RedHatRelease | sed 's/ //g' | cut -c1-6)
if [[ ${SYSTEM_JUDGMENT} = ${SYSTEM_CENTOS} || ${SYSTEM_JUDGMENT} = ${SYSTEM_RHEL} ]]; then
CENTOS_VERSION=$(echo ${SYSTEM_VERSION_NUMBER} | cut -c1)
else
CENTOS_VERSION=""
fi
;;
esac
## 判定系统处理器架构
case $Arch in
x86_64)
SYSTEM_ARCH=x86_64
SOURCE_ARCH=amd64
;;
aarch64)
SYSTEM_ARCH=ARM64
SOURCE_ARCH=arm64
;;
armv7l)
SYSTEM_ARCH=ARMv7
SOURCE_ARCH=armhf
;;
armv6l)
SYSTEM_ARCH=ARMv6
SOURCE_ARCH=armhf
;;
i686)
SYSTEM_ARCH=x86_32
echo -e '\n\033[31m---------- Docker Engine 不支持安装在 x86_32 架构的环境上 ----------\033[0m'
exit 1
;;
*)
SYSTEM_ARCH=$Arch
SOURCE_ARCH=armhf
;;
esac
## 定义软件源分支名称
if [ ${SYSTEM_JUDGMENT} = ${SYSTEM_RHEL} ]; then
SOURCE_BRANCH="centos"
else
SOURCE_BRANCH=${SYSTEM_JUDGMENT,,}
fi
## 定义软件源同步/更新文字
case ${SYSTEM_FACTIONS} in
Debian)
SYNC_TXT="更新"
;;
RedHat)
SYNC_TXT="同步"
;;
esac
}
## 基础环境判断
function PermissionJudgment() {
if [ $UID -ne 0 ]; then
echo -e '\033[31m ---------- Permission no enough, please use user ROOT! ---------- \033[0m'
exit
fi
}
function NetWorkJudgment() {
ping -c 1 www.baidu.com >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\033[31m ----- Network connection error, please check the network environment and try again later! ----- \033[0m"
exit
fi
}
## 关闭防火墙
function TurnOffFirewall() {
systemctl status firewalld | grep running -q
if [ $? -eq 0 ]; then
systemctl disable --now firewalld >/dev/null 2>&1
[ -s $SelinuxConfig ] && sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" $SelinuxConfig && setenforce 0 >/dev/null 2>&1
fi
}
## 安装环境包
function InstallationEnvironment() {
case ${SYSTEM_FACTIONS} in
Debian)
sed -i '/docker-ce/d' $DebianSourceList
rm -rf $DockerSourceList
;;
RedHat)
rm -rf $DockerRepo
;;
esac
case ${SYSTEM_FACTIONS} in
Debian)
apt-get update
;;
RedHat)
yum makecache
;;
esac
VERIFICATION_SOURCESYNC=$?
if [ ${VERIFICATION_SOURCESYNC} -ne 0 ]; then
echo -e "\n\033[31m ---------- 软件源${SYNC_TXT}出错,请先确保软件包管理工具可用 ---------- \033[0m\n"
exit 1
fi
case ${SYSTEM_FACTIONS} in
Debian)
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
;;
RedHat)
yum install -y yum-utils device-mapper-persistent-data lvm2
;;
esac
}
## 卸载旧版本的 Docker Engine
function RemoveOldVersion() {
systemctl disable --now docker >/dev/null 2>&1
sleep 2s
case ${SYSTEM_FACTIONS} in
Debian)
apt-get remove -y docker-ce docker-ce-cli containerd.io runc >/dev/null 2>&1
apt-get autoremove -y >/dev/null 2>&1
;;
RedHat)
yum remove -y docker-ce docker-ce-cli containerd.io podman* runc >/dev/null 2>&1
yum autoremove -y >/dev/null 2>&1
;;
esac
}
## 查看可供安装的 Docker Engine 版本清单
function DockerEngineVersionList() {
case ${SYSTEM_FACTIONS} in
Debian)
apt-cache madison docker-ce | awk '{print $3}' | grep -Eo "[0-9][0-9].[0-9][0-9].[0-9]{1,2}" >$DockerCEVersionFile
apt-cache madison docker-ce-cli | awk '{print $3}' | grep -Eo "[0-9][0-9].[0-9][0-9].[0-9]{1,2}" >$DockerCECLIVersionFile
grep -wf $DockerCEVersionFile $DockerCECLIVersionFile >$DockerVersionFile
;;
RedHat)
yum list docker-ce --showduplicates | sort -r | awk '{print $2}' | grep -Eo "[0-9][0-9].[0-9][0-9].[0-9]{1,2}" >$DockerCEVersionFile
yum list docker-ce-cli --showduplicates | sort -r | awk '{print $2}' | grep -Eo "[0-9][0-9].[0-9][0-9].[0-9]{1,2}" >$DockerCECLIVersionFile
grep -wf $DockerCEVersionFile $DockerCECLIVersionFile >$DockerVersionFile
;;
esac
rm -rf $DockerCEVersionFile $DockerCECLIVersionFile
}
## 配置 Docker CE 源
function ConfigureDockerCEMirror() {
if [ ${DOCKER_VERSION_INSTALL_LATEST} == "True" ]; then
SOURCE_JUDGMENT=${SOURCE}
else
SOURCE_JUDGMENT="download.docker.com"
fi
case ${SYSTEM_FACTIONS} in
Debian)
if [ ${SYSTEM_JUDGMENT} = ${SYSTEM_KALI} ]; then
curl -fsSL https://${SOURCE_JUDGMENT}/linux/debian/gpg | apt-key add - >/dev/null 2>&1
else
curl -fsSL https://${SOURCE_JUDGMENT}/linux/${SOURCE_BRANCH}/gpg | apt-key add - >/dev/null 2>&1
fi
echo "deb [arch=${SOURCE_ARCH}] https://${SOURCE_JUDGMENT}/linux/${SOURCE_BRANCH} ${SYSTEM_VERSION} stable" | tee $DockerSourceList >/dev/null 2>&1
if [ ${SYSTEM_JUDGMENT} = ${SYSTEM_KALI} ]; then
sed -i "s/${SYSTEM_VERSION}/buster/g" $DockerSourceList
sed -i "s/${SOURCE_BRANCH}/debian/g" $DockerSourceList
fi
apt-get update >/dev/null 2>&1
;;
RedHat)
yum-config-manager -y --add-repo https://${SOURCE_JUDGMENT}/linux/${SOURCE_BRANCH}/docker-ce.repo
yum makecache >/dev/null 2>&1
;;
esac
}
## 安装 Docker Engine
function DockerEngine() {
case ${SYSTEM_FACTIONS} in
Debian)
dpkg -l | grep docker-ce-cli -q
;;
RedHat)
rpm -qa | grep docker-ce-cli -q
;;
esac
if [ $? -eq 0 ]; then
DockerEngineVersionList
DOCKER_INSTALLED_VERSION=$(docker -v | grep -Eo "[0-9][0-9].[0-9][0-9].[0-9]{1,2}")
DOCKER_VERSION_LATEST=$(cat $DockerVersionFile | head -n 1)
if [[ ${DOCKER_INSTALLED_VERSION} == ${DOCKER_VERSION_LATEST} ]]; then
if [ ${DOCKER_VERSION_INSTALL_LATEST} = "True" ]; then
echo -e '\n\033[32m---------- 检测到已安装最新版本的 Docker Engine,跳过安装 ----------\033[0m'
ConfigureImageAccelerator
systemctl status docker | grep running -q
if [ $? -eq 0 ]; then
systemctl restart docker
fi
echo ''
systemctl enable --now docker >/dev/null 2>&1
DockerCompose
ShowVersion
AuthorSignature
exit
else
CHOICE_E=$(echo -e '\n\033[34m└ 检测到已安装最新版本的 Docker Engine,是否继续安装其它版本 [ Y/n ]:\033[0m')
fi
else
if [ ${DOCKER_VERSION_INSTALL_LATEST} = "True" ]; then
CHOICE_E=$(echo -e '\n\033[34m└ 检测到已安装旧版本的 Docker Engine,是否覆盖安装为最新版本 [ Y/n ]:\033[0m')
else
CHOICE_E=$(echo -e '\n\033[34m└ 检测到已安装旧版本的 Docker Engine,是否继续安装其它版本 [ Y/n ]:\033[0m')
fi
fi
read -p "${CHOICE_E}" INPUT
[ -z ${INPUT} ] && INPUT=Y
case $INPUT in
[Yy]*)
echo -en '\n[\033[34m*\033[0m] 正在卸载之前的版本... '
RemoveOldVersion
echo -e '\n\n[\033[32mOK\033[0m] 卸载完毕\n'
DockerEngineInstall
;;
[Nn]*) ;;
*)
echo -e '\n\033[33m---------- 输入错误,默认不覆盖安装 ----------\033[0m\n'
;;
esac
rm -rf $DockerVersionFile
else
RemoveOldVersion
DockerEngineInstall
fi
ConfigureImageAccelerator
systemctl stop docker >/dev/null 2>&1
systemctl enable --now docker >/dev/null 2>&1
}
function DockerEngineInstall() {
if [ ${DOCKER_VERSION_INSTALL_LATEST} == "True" ]; then
case ${SYSTEM_FACTIONS} in
Debian)
apt-get install -y docker-ce docker-ce-cli containerd.io
;;
RedHat)
yum install -y docker-ce docker-ce-cli containerd.io
;;
esac
else
DockerEngineVersionList
echo -e '\n\033[32m --------- 请选择你要安装的版本,如:19.03.15 ---------- \033[0m\n'
cat $DockerVersionFile
echo -e '\n注:以上可供选择的安装版本由官方源提供,若系统过新可能无法安装较旧的版本'
while true; do
CHOICE_F=$(echo -e '\n\033[34m└ 请根据上面的列表,输入你想要安装的具体版本号:\033[0m\n')
read -p "${CHOICE_F}" DOCKER_VERSION
echo ''
cat $DockerVersionFile | grep -Ew "${DOCKER_VERSION}" >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo ${DOCKER_VERSION} | grep -Ew '[1,2][0,8,9].[0,1][0-9].[0-9]{1,2}' >/dev/null 2>&1
if [ $? -eq 0 ]; then
rm -rf $DockerVersionFile
break
else
echo -e '\033[33m ---------- 请输入正确的版本号 ---------- \033[0m'
fi
else
echo -e '\033[33m ---------- 输入错误请重新输入 ---------- \033[0m'
fi
done
case ${SYSTEM_FACTIONS} in
Debian)
CheckVersion=$(echo ${DOCKER_VERSION} | cut -c1-2)
CheckSubversion=$(echo ${DOCKER_VERSION} | cut -c4-5)
case ${CheckVersion} in
21 | 20 | 19)
INSTALL_JUDGMENT="5:"
;;
18)
if [ ${CheckSubversion} == "09" ]; then
INSTALL_JUDGMENT="5:"
else
INSTALL_JUDGMENT=""
fi
;;
*)
INSTALL_JUDGMENT=""
;;
esac
apt-get install -y docker-ce=${INSTALL_JUDGMENT}${DOCKER_VERSION}* docker-ce-cli=5:${DOCKER_VERSION}* containerd.io
;;
RedHat)
yum install -y docker-ce-${DOCKER_VERSION} docker-ce-cli-${DOCKER_VERSION} containerd.io
;;
esac
fi
}
## 修改 Docker Hub 源
function ConfigureImageAccelerator() {
if [ ${REGISTRY_SOURCE_OFFICIAL} = "False" ]; then
if [ -d $DockerDir ] && [ -e $DockerConfig ]; then
if [ -e $DockerConfigBackup ]; then
CHOICE_BACKUP=$(echo -e "\n\033[34m└ 检测到已备份的 Docker 配置文件,是否覆盖备份 [ Y/n ]:\033[0m")
read -p "${CHOICE_BACKUP}" INPUT
[ -z ${INPUT} ] && INPUT=Y
case $INPUT in
[Yy]*)
cp -rf $DockerConfig $DockerConfigBackup >/dev/null 2>&1
;;
[Nn]*) ;;
*)
echo -e '\n\033[33m------------ 输入错误,默认不覆盖 ------------\033[0m '
;;
esac
else
cp -rf $DockerConfig $DockerConfigBackup >/dev/null 2>&1
echo -e "\n\033[34m└ 已备份原有 Docker 配置文件至 $DockerConfigBackup ...... \033[0m"
fi
sleep 2s
else
mkdir -p $DockerDir >/dev/null 2>&1
touch $DockerConfig
fi
echo -e '{\n "registry-mirrors": ["https://SOURCE"]\n}' >$DockerConfig
sed -i "s/SOURCE/$REGISTRY_SOURCE/g" $DockerConfig
systemctl daemon-reload
fi
}
## 安装 Docker Compose
function DockerCompose() {
if [ ${DOCKER_COMPOSE} == "True" ]; then
[ -e $DockerCompose ] && rm -rf $DockerCompose
if [ ${Arch} = "x86_64" ]; then
echo -e ''
if [ ${DOCKER_COMPOSE_DOWNLOAD_PROXY} = "True" ]; then
curl -L ${PROXY_URL}${DOCKER_COMPOSE_DOWNLOAD_URL} -o $DockerCompose
else
curl -L ${DOCKER_COMPOSE_DOWNLOAD_URL} -o $DockerCompose
fi
chmod +x $DockerCompose
else
echo -e '\n[*] 正在通过 pip 安装 Docker Compose ......\n'
if [ ${SYSTEM_FACTIONS} = ${SYSTEM_DEBIAN} ]; then
apt-get install -y python3-pip python3-dev gcc libffi-dev openssl >/dev/null 2>&1
elif [ ${SYSTEM_FACTIONS} = ${SYSTEM_REDHAT} ]; then
yum install -y python3-pip python3-devel gcc libffi-devel openssl-devel >/dev/null 2>&1
fi
pip3 install --upgrade pip
if [ ${DOCKER_COMPOSE_DOWNLOAD_PROXY} = "True" ]; then
pip3 install -i https://mirrors.aliyun.com/pypi/simple docker-compose
else
pip3 install docker-compose
fi
[ $? -ne 0 ] && echo -e "\n\033[31m---------- Docker Compose 安装失败,检测到当前处理器为 ${Arch} 架构无法保证 100% 安装成功,自行查看 pip 报错原因 ----------\033[0m\n"
fi
echo -e ''
else
echo -e ''
fi
}
## 查看版本并验证安装结果
function ShowVersion() {
echo -e '\033[32m---------- 验证安装版本 ----------\033[0m\n'
docker -v
VERIFICATION_DOCKER=$?
[ ${DOCKER_COMPOSE} = "True" ] && docker-compose -v
if [ ${VERIFICATION_DOCKER} -eq 0 ]; then
echo -e '\n\033[32m---------- 安装完成 ----------\033[0m'
else
echo -e '\n\033[31m---------- 安装失败 ----------\033[0m'
exit
fi
systemctl status docker | grep running -q
if [[ $? -ne 0 ]]; then
sleep 2
systemctl disable --now docker >/dev/null 2>&1
sleep 2
systemctl enable --now docker >/dev/null 2>&1
sleep 2
systemctl status docker | grep running -q
if [[ $? -ne 0 ]]; then
echo -e '\n\033[31m [ERROR] 检测到 Docker 服务启动异常,可能由于重复安装相同版本导致\033[0m'
echo -e '\n\033[31m 请执行 systemctl start docker 或 service docker start 命令尝试启动\033[0m'
echo -e '\n\033[31m 官方安装文档:https://docs.docker.com/engine/install\033[0m'
fi
fi
}
function ChooseMirrors() {
echo -e '+---------------------------------------------------+'
echo -e '| |'
echo -e '| ============================================= |'
echo -e '| |'
echo -e '| 欢迎使用 Docker 一键安装脚本 |'
echo -e '| |'
echo -e '| ============================================= |'
echo -e '| |'
echo -e '+---------------------------------------------------+'
echo -e ''
echo -e '#####################################################'
echo -e ''
echo -e ' 提供以下 Docker CE 和 Docker Hub 源可供选择:'
echo -e ''
echo -e '#####################################################'
echo -e ''
echo -e ' Docker CE'
echo -e ''
echo -e ' ❖ 阿里云 1)'
echo -e ' ❖ 腾讯云 2)'
echo -e ' ❖ 华为云 3)'
echo -e ' ❖ Azure 4)'
echo -e ' ❖ 网易 5)'
echo -e ' ❖ 清华大学 6)'
echo -e ' ❖ 浙江大学 7)'
echo -e ' ❖ 中科大 8)'
echo -e ' ❖ 官方 9)'
echo -e ''
echo -e ' Docker Hub'
echo -e ''
echo -e ' ❖ 阿里云(北京) 1)'
echo -e ' ❖ 阿里云(杭州) 2)'
echo -e ' ❖ 阿里云(成都) 3)'
echo -e ' ❖ 阿里云(广州) 4)'
echo -e ' ❖ 阿里云(香港) 5)'
echo -e ' ❖ 腾讯云 6)'
echo -e ' ❖ 华为云 7)'
echo -e ' ❖ Azure 8)'
echo -e ' ❖ DaoCloud 9)'
echo -e ' ❖ 中科大 10)'
echo -e ' ❖ 谷歌云 11)'
echo -e ' ❖ 官方 12)'
echo -e ''
echo -e '#####################################################'
echo -e ''
echo -e " 运行环境 ${SYSTEM_NAME} ${SYSTEM_VERSION_NUMBER} ${SYSTEM_ARCH}"
echo -e " 系统时间 $(date "+%Y-%m-%d %H:%M:%S")"
echo -e ''
echo -e '#####################################################'
CHOICE_A=$(echo -e '\n\033[34m└ 请选择并输入你想使用的 Docker CE 源 [ 1~9 ]:\033[0m')
read -p "${CHOICE_A}" INPUT
case $INPUT in
1)
SOURCE="mirrors.aliyun.com/docker-ce"
;;
2)
SOURCE="mirrors.cloud.tencent.com/docker-ce"
;;
3)
SOURCE="repo.huaweicloud.com/docker-ce"
;;
4)
SOURCE="mirror.azure.cn/docker-ce"
;;
5)
SOURCE="mirrors.163.com/docker-ce"
;;
6)
SOURCE="mirrors.tuna.tsinghua.edu.cn/docker-ce"
;;
7)
SOURCE="mirrors.zju.edu.cn/docker-ce"
;;
8)
SOURCE="mirrors.ustc.edu.cn/docker-ce"
;;
9)
SOURCE="download.docker.com"
;;
*)
SOURCE="mirrors.aliyun.com/docker-ce"
echo -e '\n\033[33m---------- 输入错误,默认使用阿里云 ----------\033[0m'
sleep 1s
;;
esac
## 是否手动选择安装版本
CHOICE_C=$(echo -e '\n\033[34m └ 是否安装最新版本的 Docker Engine [ Y/n ]:\033[0m')
read -p "${CHOICE_C}" INPUT
[ -z ${INPUT} ] && INPUT=Y
case $INPUT in
[Yy]*)
DOCKER_VERSION_INSTALL_LATEST="True"
;;
[Nn]*)
DOCKER_VERSION_INSTALL_LATEST="False"
if [ ${SOURCE} != "download.docker.com" ]; then
echo -e "\n\033[33m ---------- Docker CE 源已替换成官方源 ---------- \033[0m"
fi
;;
*)
DOCKER_VERSION_INSTALL_LATEST="True"
echo -e '\n\033[33m---------- 输入错误,默认安装最新版本 ----------\033[0m'
;;
esac
CHOICE_B=$(echo -e '\n\033[34m└ 请选择并输入你想使用的 Docker Hub 源 [ 1~12 ]:\033[0m')
read -p "${CHOICE_B}" INPUT
case $INPUT in
1)
REGISTRY_SOURCE="registry.cn-beijing.aliyuncs.com"
REGISTRY_SOURCE_OFFICIAL="False"
;;
2)
REGISTRY_SOURCE="registry.cn-hangzhou.aliyuncs.com"
REGISTRY_SOURCE_OFFICIAL="False"
;;
3)
REGISTRY_SOURCE="registry.cn-chengdu.aliyuncs.com"
REGISTRY_SOURCE_OFFICIAL="False"
;;
4)
REGISTRY_SOURCE="registry.cn-guangzhou.aliyuncs.com"
REGISTRY_SOURCE_OFFICIAL="False"
;;
5)
REGISTRY_SOURCE="registry.cn-hongkong.aliyuncs.com"
REGISTRY_SOURCE_OFFICIAL="False"
;;
6)
REGISTRY_SOURCE="mirror.ccs.tencentyun.com"
REGISTRY_SOURCE_OFFICIAL="False"
;;
7)
REGISTRY_SOURCE="0bab0ef02500f24b0f31c00db79ffa00.mirror.swr.myhuaweicloud.com"
REGISTRY_SOURCE_OFFICIAL="False"
;;
8)
REGISTRY_SOURCE="dockerhub.azk8s.com"
REGISTRY_SOURCE_OFFICIAL="False"
;;
9)
REGISTRY_SOURCE="f1361db2.m.daocloud.io"
REGISTRY_SOURCE_OFFICIAL="False"
;;
10)
REGISTRY_SOURCE="docker.mirrors.ustc.edu.cn"
REGISTRY_SOURCE_OFFICIAL="False"
;;
11)
REGISTRY_SOURCE="gcr.io"
REGISTRY_SOURCE_OFFICIAL="False"
;;
12)
REGISTRY_SOURCE="registry.docker-cn.com"
REGISTRY_SOURCE_OFFICIAL="True"
;;
*)
REGISTRY_SOURCE="registry.cn-hangzhou.aliyuncs.com"
REGISTRY_SOURCE_OFFICIAL="False"
echo -e '\n\033[33m---------- 输入错误,默认使用阿里云(杭州) ----------\033[0m'
sleep 1s
;;
esac
if [ -x $DockerCompose ]; then
CHOICE_D=$(echo -e '\n\033[34m└ 检测到已安装 Docker Compose ,是否覆盖安装 [ Y/n ]:\033[0m')
else
CHOICE_D=$(echo -e '\n\033[34m└ 是否安装 Docker Compose [ Y/n ]:\033[0m')
fi
read -p "${CHOICE_D}" INPUT
[ -z ${INPUT} ] && INPUT=Y
case $INPUT in
[Yy]*)
DOCKER_COMPOSE="True"
CHOICE_D1=$(echo -e '\n\033[34m └ 是否使用国内代理进行下载 [ Y/n ]:\033[0m')
read -p "${CHOICE_D1}" INPUT
[ -z ${INPUT} ] && INPUT=Y
case $INPUT in
[Yy]*)
DOCKER_COMPOSE_DOWNLOAD_PROXY="True"
;;
[Nn]*)
DOCKER_COMPOSE_DOWNLOAD_PROXY="False"
;;
*)
DOCKER_COMPOSE_DOWNLOAD_PROXY="False"
echo -e '\n\033[33m---------- 输入错误,默认不使用 ----------\033[0m\n'
;;
esac
;;
[Nn]*)
DOCKER_COMPOSE="False"
;;
*)
DOCKER_COMPOSE="False"
echo -e '\n\033[33m---------- 输入错误,默认不安装 ----------\033[0m\n'
;;
esac
echo -e ''
[ ${SYSTEM_FACTIONS} == ${SYSTEM_REDHAT} ] && TurnOffFirewall
}
Combin_Function