forked from Billionmail/BillionMail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
1401 lines (1194 loc) · 51.6 KB
/
install.sh
File metadata and controls
1401 lines (1194 loc) · 51.6 KB
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
CONTAINER_PROJECT_NAME=billionmail
PGSQL_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-pgsql-billionmail-1"
DOVECOT_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-dovecot-billionmail-1"
POSTFIX_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-postfix-billionmail-1"
RSPAMD_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-rspamd-billionmail-1"
create_time=$(date +%s)
DBNAME=billionmail
DBUSER=billionmail
SMTP_PORT=25
SMTPS_PORT=465
SUBMISSION_PORT=587
IMAP_PORT=143
IMAPS_PORT=993
POP_PORT=110
POPS_PORT=995
REDIS_PORT=127.0.0.1:26379
SQL_PORT=127.0.0.1:25432
HTTP_PORT=80
HTTPS_PORT=443
SafePath=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 8)
REDISPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 32)
ADMIN_USERNAME=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 8)
ADMIN_PASSWORD=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 8)
time=$(date +%Y_%m_%d_%H_%M_%S)
PWD_d=`pwd`
download_Url=https://node.aapanel.com
mirror=''
Default_Download_Url=""
CPU_architecture=$(uname -m)
# List of supported architectures
SUPPORTED_ARCHS=("x86_64" "aarch64")
# Check whether the current architecture is supported
if [[ ! " ${SUPPORTED_ARCHS[@]} " =~ " ${CPU_architecture} " ]]; then
echo -e "\033[31mSorry, not support the ${CPU_architecture} architecture for install. \nPlease use the x86_64, aarch64 server architecture. \033[0m"
exit 1
fi
is64bit=$(getconf LONG_BIT)
if [ "${is64bit}" != '64' ];then
echo -e "\033[31m Sorry, BillionMail does not support 32-bit systems \033[0m"
exit 1
fi
if [ $(whoami) != "root" ];then
echo -e "Non-root install, please try the following solutions: \n 1.Please switch to root user install \n 2.Try executing the following install commands: \n sudo bash $0 $@"
exit 1
fi
while [ ${#} -gt 0 ]; do
case $1 in
-h|--help)
echo "Usage: [options]"
echo "Options:"
echo " -d, --domain Set Mail Server domain. eg: example.com"
echo " -t, --TZ Set Time Zone. eg: CST"
echo " Time Zone See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of timezones"
echo " Use a column named "TZ identifier" + note the column named "Notes""
echo "eg: bash install.sh --domain example.com --TZ CST"
exit 0
;;
-d|--domain)
BILLIONMAIL_HOSTNAME=$2
shift 1
;;
-t|--TZ)
BILLIONMAIL_TIME_ZONE=$2
shift 1
;;
esac
shift 1
done
if [ -f "billionmail.conf" ]; then
read -r -p "Check that the configuration file exists, will you continue to overwrite the file?? [y/N] " gogo
case $gogo in
[Yy][eE][sS]|[Yy])
if [ ! -d "./backup/" ]; then
mkdir ./backup
fi
mv billionmail.conf ./backup/billionmail.conf_${time}
echo "Backup: billionmail.conf --> ./backup/billionmail.conf_${time}"
if [ -f ".env" ]; then
mv .env env_${time}
echo "Backup: .env --> ./backup/env_${time}"
fi
;;
*)
exit 1
;;
esac
fi
while [ -z "${BILLIONMAIL_HOSTNAME}" ]; do
echo "Press Enter to confirm the detected value '[value]', or enter a custom value."
echo -e ""
echo -e "Mail Server hostname (FQDN), \e[0;33mAs: example.com\e[0m"
echo -e ""
read -p "Please enter the Mail Server hostname (FQDN: e.g. example.com): " -e BILLIONMAIL_HOSTNAME
#if [[ ! "${BILLIONMAIL_HOSTNAME}" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9](\.[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])*$ ]]; then
if [[ ! "${BILLIONMAIL_HOSTNAME}" =~ ^([a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$ ]]; then
echo -e "\e[31m(${BILLIONMAIL_HOSTNAME}) is not a FQDN!\e[0m"
echo "Please change it to a FQDN"
exit 1
elif [[ "${BILLIONMAIL_HOSTNAME: -1}" == "." ]]; then
echo "(${BILLIONMAIL_HOSTNAME}) is ending with a dot. This is not a valid FQDN!"
exit 1
fi
done
# Count number of dots in the domain
DOT_COUNT=$(echo "${BILLIONMAIL_HOSTNAME}" | tr -cd '.' | wc -c)
# If only one dot, prepend "mail."
if [ "${DOT_COUNT}" -eq 1 ]; then
ADD_MAIL_BILLIONMAIL_HOSTNAME="mail.${BILLIONMAIL_HOSTNAME}"
echo "Postfix myhostname configuration use: ${ADD_MAIL_BILLIONMAIL_HOSTNAME}"
fi
# Ensure ADD_MAIL_BILLIONMAIL_HOSTNAME is always set (fallback to original if empty)
if [ -z "${ADD_MAIL_BILLIONMAIL_HOSTNAME}" ]; then
ADD_MAIL_BILLIONMAIL_HOSTNAME="${BILLIONMAIL_HOSTNAME}"
echo "Postfix myhostname configuration use: ${ADD_MAIL_BILLIONMAIL_HOSTNAME}"
fi
if [ -a /etc/timezone ]; then
SYSTEM_TIME_ZONE=$(cat /etc/timezone)
elif [ -a /etc/localtime ]; then
SYSTEM_TIME_ZONE=$(readlink /etc/localtime|sed -n 's|^.*zoneinfo/||p')
fi
while [ -z "${BILLIONMAIL_TIME_ZONE}" ]; do
echo -e ""
echo -e "See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of timezones"
echo -e "Use a column named "TZ identifier" + note the column named "Notes""
echo -e "Please enter your time zone"
echo -e ""
if [ -z "${SYSTEM_TIME_ZONE}" ]; then
read -p "Timezone: " -e BILLIONMAIL_TIME_ZONE
else
read -p "Timezone [${SYSTEM_TIME_ZONE}]: " -e BILLIONMAIL_TIME_ZONE
[ -z "${BILLIONMAIL_TIME_ZONE}" ] && BILLIONMAIL_TIME_ZONE=${SYSTEM_TIME_ZONE}
fi
done
DBPASS_file=DBPASS_file.pl
if [ ! -s "${DBPASS_file}" ]; then
DBPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 32)
echo "${DBPASS}" > ${DBPASS_file}
chmod 600 ${DBPASS_file}
else
DBPASS=$(cat ${DBPASS_file})
fi
GetSysInfo(){
if [ -s "/etc/redhat-release" ];then
SYS_VERSION=$(cat /etc/redhat-release)
elif [ -s "/etc/issue" ]; then
SYS_VERSION=$(cat /etc/issue)
fi
SYS_INFO=$(uname -a)
SYS_BIT=$(getconf LONG_BIT)
MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
CPU_INFO=$(getconf _NPROCESSORS_ONLN)
echo -e ${SYS_VERSION}
echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
echo -e ${SYS_INFO}
echo -e "Please screenshot the above error message and post to the https://github.com/aaPanel/Billion-Mail/issues for help"
}
Red_Error(){
echo '=================================================';
printf '\033[1;31;40m%b\033[0m\n' "$@";
GetSysInfo
exit 1;
}
PORT(){
if Command_Exists ss ; then
command_port="ss"
elif Command_Exists netstat ; then
command_port="netstat"
else
echo -e "Command does not exist and cannot check whether the port is used"
command_port=""
fi
if [[ ! -z $command_port ]]; then
echo "Checking if the port is used"
#check_command=$($command_port -ltnp | grep -E ':(25|465|587|110|143|993|995)\s')
check_command=$($command_port -ltnp | grep -E ":(${SMTP_PORT}|${SMTPS_PORT}|${SUBMISSION_PORT}|${POP_PORT}|${IMAP_PORT}|${IMAPS_PORT}|${POPS_PORT}|${HTTP_PORT}|${HTTPS_PORT})\s")
if [[ ! -z "$check_command" ]]; then
echo "$check_command"
echo -e "\033[31m Mail Server need use port ${SMTP_PORT}|${SMTPS_PORT}|${SUBMISSION_PORT}|${POP_PORT}|${IMAP_PORT}|${IMAPS_PORT}|${POPS_PORT}|${HTTP_PORT}|${HTTPS_PORT}. There are already services ports in the system, cannot be installed. \nRecommended use a new system. \033[0m"
exit 1
fi
fi
}
Check_Port(){
if ! Command_Exists docker; then
PORT
else
check=$(docker ps |grep -wE "${POSTFIX_CONTAINER_NAME}|${DOVECOT_CONTAINER_NAME}")
if [[ -z "$check" ]]; then
PORT
fi
fi
}
LXC_install_tips (){
# Check if it is in the lxc container
System_Info=$(hostnamectl)
check_container=$(echo "$System_Info" |grep "Chassis"|awk -F":" '{print $2}')
#echo $check_container
if [[ "$check_container" =~ "container" ]];then
echo -e "\033[33mInstalling in an LXC container,May not install properly. \nDocker may not be able to correctly obtain the number of CPU cores, \nwhich may cause the system to crash and cause high load when nginx is running. \nRecommended use VPS or physical machine for install.\033[0m"
echo -e ""
echo -e "\033[33mMust be turned on \"Unprivileged container\", \"nesting\". Otherwise the container cannot be started.\033[0m"
echo "Please confirm whether continue install?"
while [ "$lxc" != 'y' ] && [ "$lxc" != 'n' ]; do
read -p "Please confirm whether in LXC container continue install? (y/n): " lxc;
done
if [ "$lxc" == 'n' ];then
echo "Install canceled."
exit;
fi
LXC_install="yes"
fi
}
Get_Pack_Manager(){
if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
PM="yum"
elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
PM="apt-get"
fi
}
Install_RPM_Pack(){
yumPacks="wget curl tar gzip git firewalld ca-certificates";
yum install -y ${yumPacks}
for yumPack in ${yumPacks}
do
rpmPack=$(rpm -q ${yumPack})
packCheck=$(echo ${rpmPack}|grep not)
if [ "${packCheck}" ]; then
yum install ${yumPack} -y
fi
done
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
}
Install_Deb_Pack(){
debPacks="wget curl tar gzip git lsb-release ufw ca-certificates";
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y $debPacks --allow-downgrades --allow-remove-essential --allow-change-held-packages
for debPack in ${debPacks}
do
packCheck=$(dpkg -l ${debPack})
if [ "$?" -ne "0" ] ;then
apt-get install -y $debPack
fi
done
}
Command_Exists() {
command -v "$@" >/dev/null 2>&1
}
Docker_Download_Url_Check() {
echo -e "Selecting download docker address source, please wait..."
ser_names=(download.docker.com mirrors.ustc.edu.cn/docker-ce mirrors.tuna.tsinghua.edu.cn/docker-ce mirrors.aliyun.com/docker-ce mirror.azure.cn/docker-ce)
tmp_file1=/dev/shm/net_test1.pl
tmp_file2=/dev/shm/net_test2.pl
[ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
[ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
touch $tmp_file1
touch $tmp_file2
for ser_name in ${ser_names[@]};
do
NODE_CHECK=$(curl -k -s 2>/dev/null --connect-timeout 5 -w "%{http_code} %{time_total}" https://${ser_name} -o c${ser_name}.txt|xargs)
rm -rf c${ser_name}.txt
NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $1}')
TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $2 * 1000 - 500 }'|cut -d '.' -f 1)
if [ "${NODE_STATUS}" == "200" ] || [ "${NODE_STATUS}" == "301" ] || [ "${NODE_STATUS}" == "403" ];then
if [ $TIME_TOTAL -lt 100 ]; then
echo "$ser_name" >> $tmp_file1
elif [ $TIME_TOTAL -gt 1500 ] && [ $TIME_TOTAL -lt 2500 ]; then
echo "$ser_name" >> $tmp_file2
fi
fi
done
Docker_NODE_URL=$(cat $tmp_file1|head -n 1|awk '{print $1}')
if [ -z "$Docker_NODE_URL" ];then
Docker_NODE_URL=$(cat $tmp_file2|head -n 1|awk '{print $1}')
fi
rm -f $tmp_file1
rm -f $tmp_file2
mirror="$Docker_NODE_URL"
echo $mirror
case "$mirror" in
mirrors.aliyun.com/docker-ce)
Default_Download_Url="https://mirrors.aliyun.com/docker-ce"
mirror="Aliyun"
;;
mirror.azure.cn/docker-ce)
Default_Download_Url="https://mirror.azure.cn/docker-ce"
mirror="AzureChinaCloud"
;;
mirrors.ustc.edu.cn/docker-ce)
Default_Download_Url="https://mirrors.ustc.edu.cn/docker-ce"
mirror="USTC"
;;
mirrors.tuna.tsinghua.edu.cn/docker-ce)
Default_Download_Url="https://mirrors.tuna.tsinghua.edu.cn/docker-ce"
mirror="tsinghua"
;;
*)
Default_Download_Url="https://download.docker.com"
mirror=""
;;
esac
DEFAULT_REPO_FILE="docker-ce.repo"
if [ -z "$REPO_FILE" ]; then
REPO_FILE="$DEFAULT_REPO_FILE"
fi
}
Get_Distribution() {
lsb_dist=""
lsb_name=""
if [ -r /etc/os-release ]; then
lsb_dist="$(. /etc/os-release && echo "$ID")"
lsb_name="$(. /etc/os-release && echo "$NAME")"
fi
echo "$lsb_dist $lsb_name"
}
Bored_waiting(){
w_time="$wait_time"
msg="$wait_msg"
progress="."
for ((i=0; i<${w_time}; i++))
do
printf "$msg %-10s %d\r" "$progress" "$((i+1))"
sleep 1
if [ "$progress" == ".........." ]; then
progress="."
else
progress+="."
fi
done
printf "$msg %-10s %d\r" ".........." "$w_time"
#echo ""
}
Docker_Start() {
if Command_Exists docker || [ -f /lib/systemd/system/docker.service ]; then
if Command_Exists systemctl; then
# systemctl mask getty@tty1.service
systemctl enable docker
systemctl reset-failed docker.service
systemctl start docker.service
if [ "$?" != "0" ];then
systemctl reset-failed docker.service
systemctl restart docker.service
if [ "$?" != "0" ];then
docker_status=$(systemctl status docker.service)
echo "$docker_status"
if [ -f /etc/docker/daemon.json ]; then
echo "/etc/docker/daemon.json file content:"
cat /etc/docker/daemon.json
echo -e "\033[33mRecommended check the above /etc/docker/daemon.json Are the file contents correct?\033[0m"
fi
# Wait for 100 seconds of animation
echo -e "\033[31m start docker service failed, maybe too fast to start\033[0m"
wait_msg="waiting 100 seconds to start docker service"
wait_time="100"
Bored_waiting
systemctl reset-failed docker.service
systemctl restart docker.service
if [ "$?" != "0" ];then
docker_status=$(systemctl status docker.service)
echo "$docker_status"
Red_Error "docker start failed" "Please try again later execute the restart docker command: systemctl restart docker.service (no content returns normal)" "Finally, re-execute install BillionMail"
fi
fi
fi
else
chkconfig --add docker
chkconfig --level 2345 docker on
service docker start
if [ "$?" != "0" ];then
service docker.service status
cat /etc/docker/daemon.json
Red_Error "docker start failed"
fi
fi
else
Red_Error "Docker is not installed"
fi
}
Is_Darwin() {
case "$(uname -s)" in
*darwin*) true ;;
*Darwin*) true ;;
*) false ;;
esac
}
Check_Forked() {
if Command_Exists lsb_release; then
set +e
lsb_release -a -u >/dev/null 2>&1
lsb_release_exit_code=$?
if [ "$lsb_release_exit_code" = "0" ]; then
cat <<-EOF
You're using '$lsb_dist' version '$dist_version'.
EOF
lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')
dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')
cat <<-EOF
Upstream release is '$lsb_dist' version '$dist_version'.
EOF
else
if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
if [ "$lsb_dist" = "osmc" ]; then
lsb_dist=raspbian
else
lsb_dist=debian
fi
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
case "$dist_version" in
12)
dist_version="bookworm"
;;
11)
dist_version="bullseye"
;;
10)
dist_version="buster"
;;
9)
dist_version="stretch"
;;
8)
dist_version="jessie"
;;
esac
fi
fi
fi
}
Docker_Check(){
# Default value is: 0 Not installed
is_docker="0"
docker_version="docker version"
if Command_Exists $docker_version ; then
is_docker="1"
fi
echo "docker command: $is_docker"
}
create_docker_yum_repo() {
cat <<EOF >/etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - \$basearch
baseurl=https://download.docker.com/linux/centos/\$releasever/\$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
EOF
}
Docker_Install() {
lsb_dist=$(Get_Distribution|awk -F " " '{print $1}')
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
case "$lsb_dist" in
ubuntu)
if Command_Exists lsb_release; then
dist_version="$(lsb_release --codename | cut -f2)"
fi
if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
fi
;;
debian | raspbian)
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
case "$dist_version" in
12)
dist_version="bookworm"
;;
11)
dist_version="bullseye"
;;
10)
dist_version="buster"
;;
9)
dist_version="stretch"
;;
8)
dist_version="jessie"
;;
esac
;;
centos | rhel | sles | ol | tencentos | alinux | anolis | rocky | euleros | almalinux | opencloudos |openeuler |hce | kylin |uos | kylinsecos |amzn )
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
;;
*)
if Command_Exists lsb_release; then
dist_version="$(lsb_release --release | cut -f2)"
fi
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
;;
esac
Check_Forked
case "$lsb_dist" in
ubuntu | debian | raspbian)
docker_gpg="/usr/share/keyrings/docker-archive-keyring.gpg"
apt_repo_file="/etc/apt/sources.list.d/docker.list"
pre_reqs="apt-transport-https ca-certificates curl wget"
if ! command -v gpg >/dev/null; then
pre_reqs="$pre_reqs gnupg"
fi
apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=$docker_gpg] $Default_Download_Url/linux/$lsb_dist $dist_version stable"
(
DEBIAN_FRONTEND=noninteractive apt-get install -y $pre_reqs
if [ -f $docker_gpg ] && [ -f $apt_repo_file ]; then
rm -rf $docker_gpg
rm -rf $apt_repo_file
fi
#curl -fsSL --connect-time 10 --retry 5 $Default_Download_Url/linux/$lsb_dist/gpg | gpg --dearmor --yes -o $docker_gpg
#wget --no-check-certificate -qO - -t 5 -T 20 $Default_Download_Url/linux/$lsb_dist/gpg | gpg --dearmor --yes -o $docker_gpg
wget -qO - -t 5 -T 10 $Default_Download_Url/linux/$lsb_dist/gpg | gpg --dearmor --yes -o $docker_gpg
chmod a+r $docker_gpg
echo "$apt_repo" > $apt_repo_file
apt-get update -y
)
pkg_version=""
#First check whether apt-get is used. It cannot be put into the subshell, that is, () to execute, otherwise it will not exit.
# Check_apt_status
(
pkgs="$pkgs docker-ce${pkg_version%=}"
DEBIAN_FRONTEND=noninteractive apt-get install -y $pkgs docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
)
;;
centos | fedora | rhel | ol | tencentos | alinux | anolis | rocky | almalinux | opencloudos |openeuler |hce |uos |amzn )
pkg_version=""
yum_repo="$Default_Download_Url/linux/$lsb_dist/$REPO_FILE"
if [ "$lsb_dist" == "ol" ] || [ "$lsb_dist" == "tencentos" ] || [ "$lsb_dist" == "alinux" ] || [ "$lsb_dist" == "anolis" ] || [ "$lsb_dist" == "opencloudos" ] || [ "$lsb_dist" == "openeuler" ] || [ "$lsb_dist" == "hce" ] || [ "$lsb_dist" == "uos" ] || [ "$lsb_dist" == "amzn" ] ; then
yum_repo="$Default_Download_Url/linux/centos/$REPO_FILE"
fi
if [ "$lsb_dist" == "rocky" ] || [ "$lsb_dist" == "almalinux" ]; then
yum_repo="$Default_Download_Url/linux/centos/$REPO_FILE"
fi
if [ "$lsb_dist" = "fedora" ]; then
pkg_manager="dnf"
config_manager="dnf config-manager"
enable_channel_flag="--set-enabled"
disable_channel_flag="--set-disabled"
pre_reqs="dnf-plugins-core"
pkg_suffix="fc$dist_version"
else
pkg_manager="yum"
config_manager="yum-config-manager"
enable_channel_flag="--enable"
disable_channel_flag="--disable"
pre_reqs="yum-utils"
pkg_suffix="el"
fi
#wget --no-check-certificate -O /etc/yum.repos.d/docker-ce.repo $yum_repo -t 5 -T 10
wget -O /etc/yum.repos.d/docker-ce.repo $yum_repo -t 5 -T 10
if [ $? -ne "0" ]; then
create_docker_yum_repo
fi
if ! grep -q "docker" /etc/yum.repos.d/docker-ce.repo; then
create_docker_yum_repo
fi
sed -i "s|https://download.docker.com|$Default_Download_Url|g" /etc/yum.repos.d/docker-ce.repo
# cat /etc/yum.repos.d/docker-ce.repo
lsb_name=$(Get_Distribution|awk -F " " '{print $3}')
echo $lsb_name
echo $lsb_dist
#if [ "$lsb_name" = "Stream" ] || [ "$lsb_dist" = "alinux" ] || [ "$lsb_dist" = "anolis" ];then
#if [ "$lsb_name" = "Stream" ] || [ "$lsb_dist" = "anolis" ];then
if [ "$lsb_name" = "Stream" ]; then
conflicting="--allowerasing"
fi
if [ "$lsb_name" = "rocky" ] || [ "$lsb_dist" = "euleros" ] || [ "$lsb_dist" = "almalinux" ];then
conflicting="--allowerasing"
fi
if [ "$lsb_dist" = "openeuler" ];then
openeuler_v=$(cat /etc/os-release |grep "VERSION=")
if [[ $openeuler_v =~ "23.0" ]]; then
sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
$pkg_manager makecache
elif [[ $openeuler_v =~ "22.0" ]]; then
sed -i "s|\$releasever|7|g" /etc/yum.repos.d/docker-ce.repo
$pkg_manager makecache
else
if [ -f "/etc/os-release" ]; then
cat /etc/os-release
fi
echo "ERROR: not support this system yum auto install docker"
fi
fi
# Amazon Linux
if [ "$lsb_dist" = "amzn" ];then
#amzn_v=$(. /etc/os-release && echo "$VERSION_ID")
sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
$pkg_manager makecache
fi
# Huawei Cloud EulerOS
if [ "$lsb_dist" = "hce" ];then
hce_v=$(. /etc/os-release && echo "$VERSION_ID")
if [[ $hce_v =~ "2.0" ]]; then
sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
$pkg_manager makecache
else
if [ -f "/etc/os-release" ]; then
cat /etc/os-release
fi
echo "ERROR: not support this system yum auto install docker"
fi
fi
# OpenCloudOS 9.0
if [ "$lsb_dist" = "opencloudos" ];then
pkg_manager="yum"
opencloudos_v=$(. /etc/os-release && echo "$VERSION_ID")
if [[ $opencloudos_v =~ "9.0" ]]; then
sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
# centos 8
download_container_selinux="$download_Url/cloudwaf/package/container-selinux-2.224.0-1.module_el8+712+4cd1bd69.noarch.rpm"
wget --no-check-certificate -O container-selinux-2.224.0-1.module_el8+712+4cd1bd69.noarch.rpm ${download_container_selinux} -t 5 -T 10
install_docker="1"
$pkg_manager makecache
$pkg_manager install -y docker-ce$pkg_version docker-ce-cli docker-buildx-plugin docker-compose-plugin container-selinux-2.224.0-1.module_el8+712+4cd1bd69.noarch.rpm
rm -f container-selinux-2.224.0-1.module_el8+712+4cd1bd69.noarch.rpm
fi
fi
if [ "$lsb_dist" = "uos" ];then
pkg_manager="yum"
uos_v=$(. /etc/os-release && echo "$VERSION_ID")
uos_NAME=$(. /etc/os-release && echo "$NAME")
if [[ $uos_v =~ "20" ]] && [[ "$uos_NAME" == "UOS Server Euler" ]]; then
# UOS Server Euler 20 Install using the default source
if [ -f /etc/yum.repos.d/docker-ce.repo ]; then
rm -f /etc/yum.repos.d/docker-ce.repo
fi
# Define to install docker using other commands
install_docker="1"
$pkg_manager makecache
$pkg_manager install -y docker* --skip-broken
elif [[ $uos_v =~ "20" ]]; then
sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
# Define to install docker using other commands
install_docker="1"
$pkg_manager makecache
$pkg_manager install -y docker-ce$pkg_version docker-ce-cli docker-buildx-plugin docker-compose-plugin
else
if [ -f "/etc/os-release" ]; then
cat /etc/os-release
fi
echo "ERROR: not support this system yum auto install docker"
fi
fi
if [[ "$install_docker" != "1" ]]; then
# 1 When docker is installed using other commands
$pkg_manager makecache
$pkg_manager install -y docker-ce$pkg_version docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin $conflicting
fi
;;
*)
if [ -z "$lsb_dist" ]; then
if Is_Darwin; then
echo
echo "ERROR: Unsupported operating system 'macOS'"
echo
exit 1
fi
fi
echo
Red_Error "ERROR: not support '$lsb_dist' this system auto install docker"
;;
esac
if ! Command_Exists docker && [ ! -f /usr/bin/docker ]; then
echo "Trying to install docker using binary package method."
Binary_package_install_docker
fi
if ! Command_Exists docker ; then
Red_Error "docker command not exists,install docker failed,please check the reason."
fi
}
Binary_package_install_docker(){
# Install docker in binary package
DOCKER_VERSION="27.3.1"
SYS_TYPE=$(uname -m)
echo "Create docker group"
groupadd docker
echo "Downloading docker ${DOCKER_VERSION}.tgz file, please wait..."
wget --no-check-certificate -O docker-${DOCKER_VERSION}.tgz ${download_Url}/src/docker-${DOCKER_VERSION}-${SYS_TYPE}.tgz -t 5 -T 10
tmp_size=$(du -b docker-${DOCKER_VERSION}.tgz |awk '{print $1}')
if [ $tmp_size -lt 60831072 ];then
ls -l docker-${DOCKER_VERSION}.tgz
Red_Error "ERROR: Failed to download, please try install again!"
fi
echo "Unzip the docker ${DOCKER_VERSION}.tgz file, please wait..."
tar -xvf docker-${DOCKER_VERSION}.tgz
\cp docker/* /usr/bin/
# rm -rf docker
rm -f docker-${DOCKER_VERSION}.tgz
wget --no-check-certificate -O /usr/bin/docker-compose ${download_Url}/src/docker-compose-linux-${SYS_TYPE} -t 5 -T 20
chmod +x /usr/bin/docker-compose
wget --no-check-certificate -O /usr/lib/systemd/system/docker.service ${download_Url}/init/systemd/docker.service -t 5 -T 20
wget --no-check-certificate -O /usr/lib/systemd/system/docker.socket ${download_Url}/init/systemd/docker.socket -t 5 -T 20
wget --no-check-certificate -O /usr/lib/systemd/system/containerd.service ${download_Url}/init/systemd/containerd.service -t 5 -T 20
systemctl enable docker.service
systemctl enable docker.socket
systemctl enable containerd.service
systemctl start containerd.service
systemctl start docker.socket
systemctl start docker.service
}
Docker_Compose_Check(){
is_docker_compose="0"
if Command_Exists docker-compose; then
is_docker_compose="1"
DOCKER_COMPOSE="docker-compose"
else
if Command_Exists docker; then
Docker_compose="docker compose version"
if $Docker_compose; then
is_docker_compose="1"
DOCKER_COMPOSE="docker compose"
fi
else
is_docker_compose="0"
fi
fi
}
Docker_Compose_Install() {
if [ $is_docker_compose == "0" ]; then
Docker_Install
fi
Compose_Download_Url="$download_Url/install/src/docker-compose-$(uname -s)-$(uname -m)"
Compose_Path="/usr/local/bin/docker-compose"
New_Compose_Path="/usr/libexec/docker/cli-plugins/docker-compose"
Compose_lin="/usr/bin/docker-compose"
if [ ! -f $New_Compose_Path ]; then
wget --no-check-certificate -t 5 -T 20 -O $New_Compose_Path $Compose_Download_Url
chmod +x $New_Compose_Path
rm -rf $Compose_lin
fi
if [ ! -f ${Compose_lin} ];then
ln -s $New_Compose_Path $Compose_lin
fi
}
Set_Firewall() {
sshPort=$(cat /etc/ssh/sshd_config | grep 'Port ' | awk '{print $2}')
if [ "${PM}" = "apt-get" ]; then
if [ ! -f "/usr/bin/ufw" ] && [ ! -f "/bin/ufw" ] && ! Command_Exists "ufw"; then
apt-get install -y ufw
fi
if [ -f "/usr/sbin/ufw" ]; then
ufw allow 20/tcp >/dev/null 2>&1
ufw allow 21/tcp >/dev/null 2>&1
ufw allow 22/tcp >/dev/null 2>&1
ufw allow 80/tcp >/dev/null 2>&1
ufw allow 443/tcp >/dev/null 2>&1
ufw allow 888/tcp >/dev/null 2>&1
ufw allow 39000:40000/tcp >/dev/null 2>&1
ufw allow ${SMTP_PORT}/tcp >/dev/null 2>&1
ufw allow ${SMTPS_PORT}/tcp >/dev/null 2>&1
ufw allow ${SUBMISSION_PORT}/tcp >/dev/null 2>&1
ufw allow ${IMAP_PORT}/tcp >/dev/null 2>&1
ufw allow ${IMAPS_PORT}/tcp >/dev/null 2>&1
ufw allow ${POP_PORT}/tcp >/dev/null 2>&1
ufw allow ${POPS_PORT}/tcp >/dev/null 2>&1
ufw allow ${HTTP_PORT}/tcp >/dev/null 2>&1
ufw allow ${HTTPS_PORT}/tcp >/dev/null 2>&1
ufw allow ${sshPort}/tcp >/dev/null 2>&1
ufw_status=$(ufw status)
echo y | ufw enable
ufw default deny
ufw reload
fi
else
if [ -f "/etc/init.d/iptables" ]; then
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${SMTP_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${SMTPS_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${SUBMISSION_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${IMAP_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${IMAPS_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${POP_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${POPS_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${HTTP_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${HTTPS_PORT} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
#iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
iptables -A INPUT -s localhost -d localhost -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -P INPUT DROP
service iptables save
sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
iptables_status=$(service iptables status | grep 'not running')
if [ "${iptables_status}" == '' ]; then
service iptables restart
fi
else
AliyunCheck=$(cat /etc/redhat-release | grep "Aliyun Linux")
[ "${AliyunCheck}" ] && return
if [ ! -f "/usr/bin/firewall-cmd" ] && [ ! -f "/bin/firewall-cmd" ] && ! Command_Exists "firewall-cmd"; then
yum install firewalld -y
fi
[ "${Centos8Check}" ] && yum reinstall python3-six -y
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --set-default-zone=public >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=20/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=21/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=22/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=80/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=443/tcp > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${SMTP_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${SMTPS_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${SUBMISSION_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${IMAP_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${IMAPS_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${POP_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${POPS_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${HTTP_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${HTTPS_PORT}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp >/dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp >/dev/null 2>&1
#firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
firewall-cmd --reload
fi
fi
}
Check_apt_status(){
MAX_RETRIES=30
retries=0
while [ $retries -lt $MAX_RETRIES ]; do
output=$(ps aux| grep -E '(apt|apt-get)\s' 2>&1)
check_output=$(echo "$output" | grep -E '(apt|apt-get)\s')
# If check_output is empty, terminate the loop
if [ -z "$check_output" ]; then
break
fi
retries=$((retries + 1))
echo "apt-get is in use, it will automatically exit after ${retries}/${MAX_RETRIES} times, try again after 10 seconds..."
echo "$check_output"
wait_msg="Please wait "
wait_time="10"
Bored_waiting
done
if [ $retries -ge $MAX_RETRIES ]; then
echo "$output" > /tmp/waf_install_log.txt
Red_Error "ERROR: apt-get command exceeds the maximum wait times: ${MAX_RETRIES}. Do not use the apt/apt-get command or install software during installation, please try to reinstall!"
fi
}
Check_Connect_PgSql(){
MAX_RETRIES=10