forked from aaPanel/aaPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
2061 lines (1786 loc) · 79.3 KB
/
install.sh
File metadata and controls
2061 lines (1786 loc) · 79.3 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
LANG=en_US.UTF-8
if [ $(whoami) != "root" ]; then
# echo "Please use the [root] user to execute the aapanel installation script!"
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
is64bit=$(getconf LONG_BIT)
if [ "${is64bit}" != '64' ]; then
Red_Error "Sorry, aaPanel does not support 32-bit systems"
fi
HOSTNAME_CHECK=$(cat /etc/hostname)
if [ -z "${HOSTNAME_CHECK}" ];then
echo "hostname is empty. Already set as aaPanel"
echo "aaPanel" > /etc/hostname
hostnamectl set-hostname aaPanel
fi
if [ -f "/etc/SUSE-brand" ];then
openSUSE_check=$(cat /etc/SUSE-brand |grep openSUSE)
if [ "${openSUSE_check}" ];then
echo "Error: openSUSE not supported, Recommended that you use:"
echo "Debian 11/12, Ubuntu 20/22/24, Rocky/Alma 8, Rocky/Alma/Centos 9"
exit 1
fi
fi
cd ~
setup_path="/www"
python_bin=$setup_path/server/panel/pyenv/bin/python
cpu_cpunt=$(cat /proc/cpuinfo | grep ^processor | wc -l)
panelPort=$(expr $RANDOM % 55535 + 10000)
if [ "$1" ]; then
IDC_CODE=$1
fi
Command_Exists() {
command -v "$@" >/dev/null 2>&1
}
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 above error message and post forum forum.aapanel.com or send email: support@aapanel.com for help"
}
Replace_symbol(){
# 更换符号为__
text="${text#"${text%%[![:space:]]*}"}"
text=${text%% }
text=${text// /__}
text=${text//\(/__}
text=${text//\)/__}
text=${text//\"/__}
text=${text//\“/__}
text=${text//\”/__}
text=${text//\(/__}
text=${text//\)/__}
text=${text//\!/__}
text=${text//\!/__}
text=${text//:/__}
text=${text//:/__}
text=${text//,/__}
text=${text//,/__}
text=${text//。/__}
text=${text//\$/__}
text=${text//\{/__}
text=${text//\}/__}
text=${text//\[/__}
text=${text//\]/__}
text=${text//./__}
text=${text//-/__}
text=${text//>/__}
text=${text//=/__}
text=${text//\//__}
text=${text//\'/__}
}
Little_tail() {
arch=$(uname -m)
if [ -s "/etc/redhat-release" ];then
SYS_VERSION=$(cat /etc/redhat-release)
elif Command_Exists hostnamectl; then
SYS_VERSION=$(hostnamectl | grep "Operating System" | awk -F":" '{print $2}')
elif [ -s "/etc/issue" ]; then
SYS_VERSION=$(cat /etc/issue | tr '\n' ' ')
fi
text="${SYS_VERSION}_${arch}"
Replace_symbol
# echo "$text"
system="$text"
curl -o /dev/null -fsSLk --connect-time 10 "https://www.aapanel.com/api/setupCount/setupPanelFailed?type=Linux&os=${system}&errmsg=${url_err_msg}" >/dev/null 2>&1
}
Red_Error() {
echo '================================================='
printf '\033[1;31;40m%b\033[0m\n' "$@"
GetSysInfo
if [[ "$@" == "" ]]; then
url_err_msg="aaPanel_install_failed"
else
text="$@"
Replace_symbol
url_err_msg="${text}"
#echo "url_err_msg:$url_err_msg"
fi
Little_tail
exit 1
}
if [ -f "/etc/redhat-release" ]; then
Centos6Check=$(cat /etc/redhat-release | grep ' 6.' | grep -iE 'centos|Red Hat')
if [ "${Centos6Check}" ]; then
Red_Error "Sorry, Centos6 does not support installing aaPanel"
fi
Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos|Red Hat')
Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
if [ "${Centos7Check}" ] || [ "${Centos8Check}" ];then
echo "Centos 7/8 provider no longer maintained, Recommended that you use:"
echo "Debian 11/12, Ubuntu 20/22/24, Rocky/Alma 8, Rocky/Alma/Centos 9"
echo "Press Ctrl+C to cancel or Wait 10 seconds before install"
sleep 10
fi
fi
if [ -f "/etc/issue" ]; then
UbuntuCheck=$(cat /etc/issue | grep Ubuntu | awk '{print $2}' | cut -f 1 -d '.')
if [[ ! -z "${UbuntuCheck}" ]] && [[ "${UbuntuCheck}" =~ ^[0-9]+$ ]] && [[ "${UbuntuCheck}" -lt "18" ]]; then
Red_Error "Ubuntu ${UbuntuCheck} is not supported to the aaPanel, it is recommended to replace the Ubuntu 20/22/24 to install"
fi
DebianCheck=$(cat /etc/issue | grep Debian | awk '{print $3}' | cut -f 1 -d '.')
if [[ ! -z "${DebianCheck}" ]] && [[ "${DebianCheck}" =~ ^[0-9]+$ ]] && [[ "${DebianCheck}" -lt "10" ]]; then
Red_Error "Debian ${DebianCheck} is not supported to the aaPanel, it is recommended to replace the Debian 11/12 to install"
fi
fi
Check_Disk_Space() {
# Get the available space of the partition where the /www directory is located (in kb)
if [ -d "/www" ]; then
available_kb=$(df -k /www | awk 'NR==2 {print $4}')
else
available_kb=$(df -k / | awk 'NR==2 {print $4}')
fi
# 1GB = 1024MB = 1024*1024KB
available_gb=$((available_kb / 1024 / 1024))
echo "Available disk space on the install partition: "$available_gb" G"
# Determine if available space is less than 1 gb
if [ "$available_gb" -lt 1 ]; then
echo -e "\033[31m The available space is less than 1G.\033[0m"
echo -e "\033[31m It is recommended to clean or upgrade the server space before upgrading.\033[0m"
Red_Error "Error: The available space is less than 1G"
fi
}
Lock_Clear() {
if [ -f "/etc/bt_crack.pl" ]; then
chattr -R -ia /www
chattr -ia /etc/init.d/bt
\cp -rpa /www/backup/panel/vhost/* /www/server/panel/vhost/
mv /www/server/panel/BTPanel/__init__.bak /www/server/panel/BTPanel/__init__.py
rm -f /etc/bt_crack.pl
fi
}
Install_Check() {
if [ "${INSTALL_FORCE}" ]; then
return
fi
echo -e "----------------------------------------------------"
echo -e "Web service is already installed,installing aaPanel may affect existing sites."
echo -e "----------------------------------------------------"
echo -e "Enter [yes] to force installation"
read -p "Enter yes to force installation: " yes
if [ "$yes" != "yes" ]; then
echo -e "------------"
echo "Installation canceled"
exit
fi
INSTALL_FORCE="true"
}
System_Check() {
MYSQLD_CHECK=$(ps -ef | grep mysqld | grep -v grep | grep -v /www/server/mysql)
PHP_CHECK=$(ps -ef | grep php-fpm | grep master | grep -v /www/server/php)
NGINX_CHECK=$(ps -ef | grep nginx | grep master | grep -v /www/server/nginx)
HTTPD_CHECK=$(ps -ef | grep -E 'httpd|apache' | grep -v /www/server/apache | grep -v grep)
if [ "${PHP_CHECK}" ] || [ "${MYSQLD_CHECK}" ] || [ "${NGINX_CHECK}" ] || [ "${HTTPD_CHECK}" ]; then
Install_Check
fi
}
Set_Ssl() {
SET_SSL=true
if [ "${SSL_PL}" ];then
SET_SSL=""
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
}
Auto_Swap() {
swap=$(free | grep Swap | awk '{print $2}')
if [ "${swap}" -gt 1 ]; then
echo "Swap total sizse: $swap"
return
fi
if [ ! -d /www ]; then
mkdir /www
fi
swapFile="/www/swap"
dd if=/dev/zero of=$swapFile bs=1M count=1025
mkswap -f $swapFile
swapon $swapFile
echo "$swapFile swap swap defaults 0 0" >>/etc/fstab
swap=$(free | grep Swap | awk '{print $2}')
if [ $swap -gt 1 ]; then
echo "Swap total sizse: $swap"
return
fi
sed -i "/\/www\/swap/d" /etc/fstab
rm -f $swapFile
}
Service_Add() {
if Command_Exists systemctl ; then
wget --no-check-certificate -O /usr/lib/systemd/system/btpanel.service ${download_Url}/init/systemd/btpanel.service -t 5 -T 20
systemctl daemon-reload
systemctl enable btpanel
else
if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
chkconfig --add bt
chkconfig --level 2345 bt on
elif [ "${PM}" == "apt-get" ]; then
update-rc.d bt defaults
fi
fi
}
Set_Centos7_Repo(){
MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "[^#]mirror.centos.org")
if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
echo "Centos7 official repository source has been discontinued , Replacement in progress."
if [ -d "/etc/yumBak" ];then
mv /etc/yumBak /etc/yumBak_$(date +%Y_%m_%d_%H_%M_%S)
fi
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
sed -i 's/mirrorlist=/#mirrorlist=/g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
fi
MIRROR_CHECK22=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "mirrorlist.centos.org"|grep -v '^#')
if [ "${MIRROR_CHECK22}" ] && [ "${is64bit}" == "64" ];then
echo "Centos7 official repository source has been discontinued , Replacement in progress."
if [ -d "/etc/yumBak" ];then
mv /etc/yumBak /etc/yumBak_$(date +%Y_%m_%d_%H_%M_%S)
fi
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
\cp -rpa /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bt_bak
cat > /etc/yum.repos.d/CentOS-Base.repo << EOF
# CentOS-Base.repo
[base]
name=CentOS-\$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os&infra=\$infra
baseurl=http://vault.epel.cloud/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-\$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates&infra=\$infra
baseurl=http://vault.epel.cloud/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-\$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras&infra=\$infra
baseurl=http://vault.epel.cloud/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus&infra=\$infra
baseurl=http://vault.epel.cloud/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF
fi
ALI_CLOUD_CHECK=$(grep Alibaba /etc/motd)
Tencent_Cloud=$(cat /etc/hostname |grep -E VM-[0-9]+-[0-9]+)
if [ "${ALI_CLOUD_CHECK}" ] || [ "${Tencent_Cloud}" ];then
return
fi
yum install unzip -y
if [ "$?" != "0" ] ;then
TAR_CHECK=$(which tar)
if [ "$?" == "0" ] ;then
if [ -d "/etc/yumBak" ];then
mv /etc/yumBak /etc/yumBak_$(date +%Y_%m_%d_%H_%M_%S)
fi
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
if [ -z "${download_Url}" ];then
download_Url="https://node.aapanel.com"
fi
curl -Ssk --connect-timeout 20 -m 60 -O ${download_Url}/src/el7repo.tar.gz
if [ -f "/usr/bin/wget" ] && [ ! -s "el7repo.tar.gz" ];then
wget --no-check-certificate -O el7repo.tar.gz ${download_Url}/src/el7repo.tar.gz -t 3 -T 20
fi
rm -f /etc/yum.repos.d/*.repo
tar -xvzf el7repo.tar.gz -C /etc/yum.repos.d/
rm -f el7repo.tar.gz
fi
fi
}
Set_Centos8_Repo(){
HUAWEI_CHECK=$(cat /etc/motd |grep "Huawei Cloud")
if [ "${HUAWEI_CHECK}" ] && [ "${is64bit}" == "64" ];then
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
rm -f /etc/yum.repos.d/epel.repo
rm -f /etc/yum.repos.d/epel-*
fi
ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
if [ "${ALIYUN_CHECK}" ] && [ "${is64bit}" == "64" ] && [ ! -f "/etc/yum.repos.d/Centos-vault-8.5.2111.repo" ];then
rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo
fi
MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Linux-AppStream.repo |grep "[^#]mirror.centos.org")
if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
fi
yum install unzip tar -y
if [ "$?" != "0" ] ;then
if [ -z "${download_Url}" ];then
download_Url="https://node.aapanel.com"
fi
if [ ! -f "/usr/bin/tar" ] ;then
curl -Ss --connect-timeout 20 -m 60 -O ${download_Url}/src/tar-1.30-5.el8.x86_64.rpm
if [ -f "/usr/bin/wget" ] && [ ! -s "tar-1.30-5.el8.x86_64.rpm" ];then
wget --no-check-certificate -O tar-1.30-5.el8.x86_64.rpm ${download_Url}/src/tar-1.30-5.el8.x86_64.rpm -t 3 -T 20
fi
# yum install tar-1.30-5.el8.x86_64.rpm -y
rpm -ivh tar-1.30-5.el8.x86_64.rpm
rm -f tar-1.30-5.el8.x86_64.rpm
fi
if [ -d "/etc/yumBak" ];then
mv /etc/yumBak /etc/yumBak_$(date +%Y_%m_%d_%H_%M_%S)
fi
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
curl -Ss --connect-timeout 20 -m 60 -O ${download_Url}/src/el8repo.tar.gz
if [ -f "/usr/bin/wget" ] && [ ! -s "el8repo.tar.gz" ];then
wget --no-check-certificate -O el8repo.tar.gz ${download_Url}/src/el8repo.tar.gz -t 3 -T 20
fi
rm -f /etc/yum.repos.d/*.repo
tar -xvzf el8repo.tar.gz -C /etc/yum.repos.d/
rm -f el8repo.tar.gz
fi
}
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 ""
}
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 -v _apt | 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
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
}
get_node_url() {
download_Url='https://node.aapanel.com'
if [ ! -f /bin/curl ]; then
if [ "${PM}" = "yum" ]; then
yum install curl -y
elif [ "${PM}" = "apt-get" ]; then
apt-get install curl -y
fi
fi
if [ -f "/www/node.pl" ];then
download_Url=$(cat /www/node.pl)
echo "Download node: $download_Url";
echo '---------------------------------------------';
return
fi
# echo '---------------------------------------------';
# echo "Selected download node...";
# nodes=(https://node.aapanel.com);
# if [ "$1" ];then
# nodes=($(echo ${nodes[*]}|sed "s#${1}##"))
# fi
# 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 node in ${nodes[@]}; do
# NODE_CHECK=$(curl -k --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
# RES=$(echo ${NODE_CHECK} | awk '{print $1}')
# NODE_STATUS=$(echo ${NODE_CHECK} | awk '{print $2}')
# TIME_TOTAL=$(echo ${NODE_CHECK} | awk '{print $3 * 1000 - 500 }' | cut -d '.' -f 1)
# if [ "${NODE_STATUS}" == "200" ]; then
# if [ $TIME_TOTAL -lt 100 ]; then
# if [ $RES -ge 1500 ]; then
# echo "$RES $node" >>$tmp_file1
# fi
# else
# if [ $RES -ge 1500 ]; then
# echo "$TIME_TOTAL $node" >>$tmp_file2
# fi
# fi
# i=$(($i + 1))
# if [ $TIME_TOTAL -lt 100 ]; then
# if [ $RES -ge 3000 ]; then
# break
# fi
# fi
# fi
# done
# NODE_URL=$(cat $tmp_file1 | sort -r -g -t " " -k 1 | head -n 1 | awk '{print $2}')
# if [ -z "$NODE_URL" ]; then
# NODE_URL=$(cat $tmp_file2 | sort -g -t " " -k 1 | head -n 1 | awk '{print $2}')
# if [ -z "$NODE_URL" ]; then
# NODE_URL='https://node.aapanel.com'
# fi
# fi
# rm -f $tmp_file1
# rm -f $tmp_file2
# download_Url=$NODE_URL
# echo "Download node: $download_Url"
# echo '---------------------------------------------'
}
Remove_Package() {
local PackageNmae=$1
if [ "${PM}" == "yum" ]; then
isPackage=$(rpm -q ${PackageNmae} | grep "not installed")
if [ -z "${isPackage}" ]; then
yum remove ${PackageNmae} -y
fi
elif [ "${PM}" == "apt-get" ]; then
isPackage=$(dpkg -l | grep ${PackageNmae})
if [ "${PackageNmae}" ]; then
apt-get remove ${PackageNmae} -y
fi
fi
}
Install_RPM_Pack() {
yumPath=/etc/yum.conf
Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
CentOS_Stream_8=$(cat /etc/redhat-release | grep 'CentOS Stream release 8' | grep -iE 'centos|Red Hat')
if [ "${Centos8Check}" ] || [ "${CentOS_Stream_8}" ];then
Set_Centos8_Repo
fi
Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos|Red Hat')
if [ "${Centos7Check}" ];then
Set_Centos7_Repo
fi
isExc=$(cat $yumPath | grep httpd)
if [ "$isExc" = "" ]; then
echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >>$yumPath
fi
if [ -f "/etc/redhat-release" ] && [ $(cat /etc/os-release|grep PLATFORM_ID|grep -oE "el8") ];then
yum config-manager --set-enabled powertools
yum config-manager --set-enabled PowerTools
fi
if [ -f "/etc/redhat-release" ] && [ $(cat /etc/os-release|grep PLATFORM_ID|grep -oE "el9|el10") ];then
dnf config-manager --set-enabled crb -y
fi
#yumBaseUrl=$(cat /etc/yum.repos.d/CentOS-Base.repo|grep baseurl=http|cut -d '=' -f 2|cut -d '$' -f 1|head -n 1)
#[ "${yumBaseUrl}" ] && checkYumRepo=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${yumBaseUrl})
#if [ "${checkYumRepo}" != "200" ];then
# curl -Ss --connect-timeout 3 -m 60 http://node.aapanel.com/install/yumRepo_select.sh|bash
#fi
#尝试同步时间(从bt.cn)
# echo 'Synchronizing system time...'
# getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time)
# if [ "${getBtTime}" ];then
# date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"
# fi
#if [ -z "${Centos8Check}" ]; then
# yum install ntp -y
# rm -rf /etc/localtime
# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#尝试同步国际时间(从ntp服务器)
# ntpdate 0.asia.pool.ntp.org
# setenforce 0
#fi
setenforce 0
startTime=$(date +%s)
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#yum remove -y python-requests python3-requests python-greenlet python3-greenlet
yumPacks="libcurl-devel wget tar gcc make zip unzip openssl openssl-devel gcc libxml2 libxml2-devel libxslt* zlib zlib-devel libjpeg-devel libpng-devel libwebp libwebp-devel freetype freetype-devel lsof pcre pcre-devel vixie-cron crontabs icu libicu-devel c-ares libffi-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel firewalld ipset libpq-devel ca-certificates sudo at mariadb rsyslog autoconf xfsprogs quota"
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
if [ -f "/usr/bin/dnf" ]; then
dnf install -y redhat-rpm-config
fi
ALI_OS=$(cat /etc/redhat-release | grep "Alibaba Cloud Linux release 3")
if [ -z "${ALI_OS}" ]; then
yum install epel-release -y
fi
}
Install_Deb_Pack() {
Check_apt_status
ln -sf bash /bin/sh
UBUNTU_22=$(cat /etc/issue|grep "Ubuntu 22")
UBUNTU_24=$(cat /etc/issue|grep "Ubuntu 24")
if [ "${UBUNTU_22}" ] || [ "${UBUNTU_24}" ];then
apt-get remove needrestart -y
fi
apt-get update -y
apt-get install bash -y
if [ -f "/usr/bin/bash" ];then
ln -sf /usr/bin/bash /bin/sh
fi
FNOS_CHECK=$(grep fnOS /etc/issue)
if [ "${FNOS_CHECK}" ];then
apt-get install libc6 -y --allow-change-held-packages
apt-get install libc6-dev -y --allow-change-held-packages
fi
apt-get install ruby -y
apt-get install lsb-release -y
#apt-get install ntp ntpdate -y
#/etc/init.d/ntp stop
#update-rc.d ntp remove
#cat >>~/.profile<<EOF
#TZ='Asia/Shanghai'; export TZ
#EOF
#rm -rf /etc/localtime
#cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#echo 'Synchronizing system time...'
#ntpdate 0.asia.pool.ntp.org
#apt-get upgrade -y
LIBCURL_VER=$(dpkg -l | grep libcurl4 | awk '{print $3}')
if [ "${LIBCURL_VER}" == "7.68.0-1ubuntu2.8" ]; then
apt-get remove libcurl4 -y
apt-get install curl -y
fi
debPacks="wget curl libcurl4-openssl-dev gcc make zip unzip tar openssl libssl-dev gcc libxml2 libxml2-dev libxslt-dev zlib1g zlib1g-dev libjpeg-dev libpng-dev lsof libpcre3 libpcre3-dev cron net-tools swig build-essential libffi-dev libbz2-dev libncurses-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libdb++-dev libpcap-dev xz-utils git ufw ipset sqlite3 uuid-dev libpq-dev liblzma-dev ca-certificates sudo autoconf at mariadb-client rsyslog xfsprogs quota libssh2-1-dev"
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
DEBIAN_FRONTEND=noninteractive apt-get install -y $debPack --allow-downgrades --allow-remove-essential --allow-change-held-packages
fi
done
if [ ! -d '/etc/letsencrypt' ]; then
mkdir -p /etc/letsencryp
mkdir -p /var/spool/cron
if [ ! -f '/var/spool/cron/crontabs/root' ]; then
echo '' >/var/spool/cron/crontabs/root
chmod 600 /var/spool/cron/crontabs/root
fi
fi
}
Ubuntu_20_sources () {
cat > /etc/apt/sources.list << EOF
deb http://archive.ubuntu.com/ubuntu focal main restricted
# deb-src http://archive.ubuntu.com/ubuntu focal main restricted
deb http://ubuntu.mirror.constant.com focal main restricted
# deb-src http://ubuntu.mirror.constant.com focal main restricted
deb http://archive.ubuntu.com/ubuntu focal-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu focal-updates main restricted
deb http://ubuntu.mirror.constant.com focal-updates main restricted
# deb-src http://ubuntu.mirror.constant.com focal-updates main restricted
deb http://archive.ubuntu.com/ubuntu focal universe
# deb-src http://archive.ubuntu.com/ubuntu focal universe
deb http://archive.ubuntu.com/ubuntu focal-updates universe
# deb-src http://archive.ubuntu.com/ubuntu focal-updates universe
deb http://ubuntu.mirror.constant.com focal universe
# deb-src http://ubuntu.mirror.constant.com focal universe
deb http://ubuntu.mirror.constant.com focal-updates universe
# deb-src http://ubuntu.mirror.constant.com focal-updates universe
deb http://archive.ubuntu.com/ubuntu focal multiverse
# deb-src http://archive.ubuntu.com/ubuntu focal multiverse
deb http://archive.ubuntu.com/ubuntu focal-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu focal-updates multiverse
deb http://ubuntu.mirror.constant.com focal multiverse
# deb-src http://ubuntu.mirror.constant.com focal multiverse
deb http://ubuntu.mirror.constant.com focal-updates multiverse
# deb-src http://ubuntu.mirror.constant.com focal-updates multiverse
deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
deb http://ubuntu.mirror.constant.com focal-backports main restricted universe multiverse
# deb-src http://ubuntu.mirror.constant.com focal-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-security main restricted
# deb-src http://archive.ubuntu.com/ubuntu focal-security main restricted
deb http://archive.ubuntu.com/ubuntu focal-security universe
# deb-src http://archive.ubuntu.com/ubuntu focal-security universe
deb http://archive.ubuntu.com/ubuntu focal-security multiverse
# deb-src http://archive.ubuntu.com/ubuntu focal-security multiverse
deb http://ubuntu.mirror.constant.com focal-security main restricted
# deb-src http://ubuntu.mirror.constant.com focal-security main restricted
deb http://ubuntu.mirror.constant.com focal-security universe
# deb-src http://ubuntu.mirror.constant.com focal-security universe
deb http://ubuntu.mirror.constant.com focal-security multiverse
# deb-src http://ubuntu.mirror.constant.com focal-security multiverse
EOF
}
Ubuntu_22_sources () {
cat > /etc/apt/sources.list << EOF
deb http://archive.ubuntu.com/ubuntu jammy main restricted
# deb-src http://archive.ubuntu.com/ubuntu jammy main restricted
deb http://ubuntu.mirror.constant.com jammy main restricted
# deb-src http://ubuntu.mirror.constant.com jammy main restricted
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu jammy-updates main restricted
deb http://ubuntu.mirror.constant.com jammy-updates main restricted
# deb-src http://ubuntu.mirror.constant.com jammy-updates main restricted
deb http://archive.ubuntu.com/ubuntu jammy universe
# deb-src http://archive.ubuntu.com/ubuntu jammy universe
deb http://archive.ubuntu.com/ubuntu jammy-updates universe
# deb-src http://archive.ubuntu.com/ubuntu jammy-updates universe
deb http://ubuntu.mirror.constant.com jammy universe
# deb-src http://ubuntu.mirror.constant.com jammy universe
deb http://ubuntu.mirror.constant.com jammy-updates universe
# deb-src http://ubuntu.mirror.constant.com jammy-updates universe
deb http://archive.ubuntu.com/ubuntu jammy multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy-updates multiverse
deb http://ubuntu.mirror.constant.com jammy multiverse
# deb-src http://ubuntu.mirror.constant.com jammy multiverse
deb http://ubuntu.mirror.constant.com jammy-updates multiverse
# deb-src http://ubuntu.mirror.constant.com jammy-updates multiverse
deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
deb http://ubuntu.mirror.constant.com jammy-backports main restricted universe multiverse
# deb-src http://ubuntu.mirror.constant.com jammy-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://archive.ubuntu.com/ubuntu jammy-security main restricted
deb http://archive.ubuntu.com/ubuntu jammy-security universe
# deb-src http://archive.ubuntu.com/ubuntu jammy-security universe
deb http://archive.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy-security multiverse
deb http://ubuntu.mirror.constant.com jammy-security main restricted
# deb-src http://ubuntu.mirror.constant.com jammy-security main restricted
deb http://ubuntu.mirror.constant.com jammy-security universe
# deb-src http://ubuntu.mirror.constant.com jammy-security universe
deb http://ubuntu.mirror.constant.com jammy-security multiverse
# deb-src http://ubuntu.mirror.constant.com jammy-security multiverse
EOF
}
Ubuntu_24_sources () {
cat > /etc/apt/sources.list << EOF
deb http://archive.ubuntu.com/ubuntu noble main restricted
# deb-src http://archive.ubuntu.com/ubuntu noble main restricted
deb http://ubuntu.mirror.constant.com noble main restricted
# deb-src http://ubuntu.mirror.constant.com noble main restricted
deb http://archive.ubuntu.com/ubuntu noble-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu noble-updates main restricted
deb http://ubuntu.mirror.constant.com noble-updates main restricted
# deb-src http://ubuntu.mirror.constant.com noble-updates main restricted
deb http://archive.ubuntu.com/ubuntu noble universe
# deb-src http://archive.ubuntu.com/ubuntu noble universe
deb http://archive.ubuntu.com/ubuntu noble-updates universe
# deb-src http://archive.ubuntu.com/ubuntu noble-updates universe
deb http://ubuntu.mirror.constant.com noble universe
# deb-src http://ubuntu.mirror.constant.com noble universe
deb http://ubuntu.mirror.constant.com noble-updates universe
# deb-src http://ubuntu.mirror.constant.com noble-updates universe
deb http://archive.ubuntu.com/ubuntu noble multiverse
# deb-src http://archive.ubuntu.com/ubuntu noble multiverse
deb http://archive.ubuntu.com/ubuntu noble-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu noble-updates multiverse
deb http://ubuntu.mirror.constant.com noble multiverse
# deb-src http://ubuntu.mirror.constant.com noble multiverse
deb http://ubuntu.mirror.constant.com noble-updates multiverse
# deb-src http://ubuntu.mirror.constant.com noble-updates multiverse
deb http://archive.ubuntu.com/ubuntu noble-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu noble-backports main restricted universe multiverse
deb http://ubuntu.mirror.constant.com noble-backports main restricted universe multiverse
# deb-src http://ubuntu.mirror.constant.com noble-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu noble-security main restricted
# deb-src http://archive.ubuntu.com/ubuntu noble-security main restricted
deb http://archive.ubuntu.com/ubuntu noble-security universe
# deb-src http://archive.ubuntu.com/ubuntu noble-security universe
deb http://archive.ubuntu.com/ubuntu noble-security multiverse
# deb-src http://archive.ubuntu.com/ubuntu noble-security multiverse
deb http://ubuntu.mirror.constant.com noble-security main restricted
# deb-src http://ubuntu.mirror.constant.com noble-security main restricted
deb http://ubuntu.mirror.constant.com noble-security universe
# deb-src http://ubuntu.mirror.constant.com noble-security universe
deb http://ubuntu.mirror.constant.com noble-security multiverse
# deb-src http://ubuntu.mirror.constant.com noble-security multiverse
EOF
}
Debian_11_sources () {
cat > /etc/apt/sources.list << EOF
deb https://deb.debian.org/debian bullseye main contrib non-free
deb-src https://deb.debian.org/debian bullseye main contrib non-free
deb https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
deb-src https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
deb https://deb.debian.org/debian bullseye-updates main contrib non-free
deb-src https://deb.debian.org/debian bullseye-updates main contrib non-free
#deb https://deb.debian.org/debian bullseye-backports main contrib non-free
#deb-src https://deb.debian.org/debian bullseye-backports main contrib non-free
deb https://debian.mirror.constant.com bullseye main contrib non-free
deb-src https://debian.mirror.constant.com bullseye main contrib non-free
EOF
}
Debian_12_sources () {
cat > /etc/apt/sources.list << EOF
deb https://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb-src https://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb https://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src https://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb https://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb-src https://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
#deb https://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware
#deb-src https://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware
deb https://debian.mirror.constant.com bookworm main contrib non-free non-free-firmware
deb-src https://debian.mirror.constant.com bookworm main contrib non-free non-free-firmware
EOF
}
Change_sources () {
if [ -s /etc/os-release ] && [ -s /etc/issue ]; then
. /etc/os-release
echo "detected OS: $ID - $VERSION_ID"
UD_os_version=$(cat /etc/issue | grep Ubuntu | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
OS_v=Ubuntu
if [ "${UD_os_version}" = "" ]; then
OS_v=Debian
UD_os_version=$(cat /etc/issue | grep Debian | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '[0-9]+')
if [ "${UD_os_version}" = "" ]; then
UD_os_version=$(cat /etc/issue | grep Debian | grep -Eo '[0-9]+')
fi
fi
echo "detected OS version: $OS_v $UD_os_version"
if [ $ID == "debian" ] && [ $OS_v == "Debian" ]; then
if [ $VERSION_ID == "11" ] && [ $UD_os_version == "11" ]; then
Debian_11_sources
elif [ $VERSION_ID == "12" ] && [ $UD_os_version == "12" ]; then
Debian_12_sources
else
echo -e "\033[31mSorry: $OS_v $UD_os_version This system does not support changing apt source, please try to change it yourself. \033[0m"
Change_apt_sources="no"
fi
elif [ $ID == "ubuntu" ] && [ $OS_v == "Ubuntu" ]; then
if [ `echo "$VERSION_ID" | cut -b-2 ` == "20" ] && [ $UD_os_version == "20" ]; then
Ubuntu_20_sources
elif [ `echo "$VERSION_ID" | cut -b-2 ` == "22" ] && [ $UD_os_version == "22" ]; then
Ubuntu_22_sources
elif [ `echo "$VERSION_ID" | cut -b-2 ` == "24" ] && [ $UD_os_version == "24" ]; then
Ubuntu_24_sources
else
echo -e "\033[31mSorry: $OS_v $UD_os_version This system does not support changing apt source, please try to change it yourself. \033[0m"
Change_apt_sources="no"
fi
else
echo -e "\033[31mSorry: $OS_v $UD_os_version This system does not support changing apt source, please try to change it yourself. \033[0m"
Change_apt_sources="no"
fi
fi
}
Check_Change_official_sources () {
if [ -s /etc/apt/sources.list ]; then
ubuntu_sources=$(grep "\.ubuntu\.com" /etc/apt/sources.list | grep -v '^#' | grep -v "security\.ubuntu\.com")
debian_sources=$(grep "\.debian\.org" /etc/apt/sources.list | grep -v '^#' | grep -v "security\.debian\.org")
if [ "$ubuntu_sources" = "" ] && [ "$debian_sources" = "" ]; then
while [ "$yes2" != 'yes' ] && [ "$yes2" != 'no' ]; do
read -p "Found that apt source cannot be used. Do need to change it to the official source? [yes/no] " yes2
done
if [ "$yes2" = "yes" ]; then
Backup_sources_time=$(date +%Y_%m_%d_%H_%M_%S)
cp -arpf /etc/apt/sources.list /etc/apt/sources.list_aapanel_${Backup_sources_time}
echo -e "The sources.list file has been backup. The backup file name is:\033[31m /etc/apt/sources.list_aapanel_${Backup_sources_time} \033[0m"
Change_sources
if [ "${Change_apt_sources}" != "no" ]; then
Install_Deb_Pack
fi
fi
fi
fi
}
Check_Install_Sys_Packs() {
echo "Checking necessary dependency system packages"
# Define functions for installation packages
install_package() {
local package=$1
if [ "${PM}" = "yum" ]; then
yum install "$package" -y
elif [ "${PM}" = "apt-get" ]; then
dpkg --configure -a
apt-get update
apt-get install "$package" -y
fi
}
# Define a function to install and verify
install_and_verify() {
local package_name=$1