forked from usmannasir/cyberpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyberpanel.sh
2122 lines (1805 loc) · 75.9 KB
/
cyberpanel.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
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
#set -e -o pipefail
#set -x
#set -u
#CyberPanel installer script for CentOS 7, CentOS 8, CloudLinux 7, AlmaLinux 8, RockyLinux 8, Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, openEuler 20.03 and openEuler 22.03
#For whoever may edit this script, please follow:
#Please use Pre_Install_xxx() and Post_Install_xxx() if you want to something respectively before or after the panel installation
#and update below accordingly
#Please use variable/functions name as MySomething or My_Something, and please try not to use too-short abbreviation :)
#Please use On/Off, True/False, Yes/No.
#workflow:
#Set_Default_Variables() ---> set some default variable for later use
#Check_Root() ---> check for root
#Check_Server_IP() ---> check for server IP and geolocation at country level
#Check_OS() ---> check system , support on CentOS 7/8, RockyLinux 8, AlmaLinux 8, Ubuntu 18/20, openEuler 20.03/22.03 and CloudLinux 7, 8 is untested.
#Check_Virtualization() ---> check for virtualizaon , #LXC not supported# , some edit needed on OVZ
#Check_Panel() ---> check to make sure no other panel is installed
#Check_Process() ---> check no other process like Apache is running
#Check_Provider() ---> check the provider, certain provider like Alibaba or Tencent Cloud may need some special change
#Check_Argument() ---> parse argument and go to Argument_Mode() or Interactive_Mode() respectively
#Pre_Install_Setup_Repository() ---> setup/install repositories for CentOS and openEuler system.
#go to Pre_Install_Setup_CN_Repository() if server is within China.
#Pre_Install_Setup_Git_URL() ---> form up github URL , use Gitee for servers within China.
#Pre_Install_Required_Components() ---> install required softwares and git clone it
#Pre_Install_System_Tweak() ---> set up SWAP and apply some system tweak depends on providers
#Main_Installation() ---> change some code within python files for CN servers and start to install
#Post_Install_Addon_Memcached() ---> Install Memcached extension and process
#Post_Install_Addon_Redis() ---> Install Redis extension and process
#Post_Install_Required_Components() ---> install some required softwares.
#Post_Install_PHP_Session_Setup() ---> set up PHP session
#Post_Install_PHP_TimezoneDB() ---> set up PHP timezoneDB
#Post_Install_Regenerate_Cert() ---> regenerate cert for :7080 and :8090 to avoid Chrome on macOS blocking.
#Post_Install_Regenerate_Webadmin_Console_Passwd() ---> regenerate the webadmin console password
#Post_Install_Setup_Watchdog() ---> set up watchdog script for webserver and MariaDB.
#Post_Install_Setup_Utility() ---> set up utility script for some handy features
#Post_Install_Tweak() ---> some patches/fixes on certain systems
#Post_Install_Display_Final_Info() ---> display installation successful information.
Sudo_Test=$(set)
#for SUDO check
Set_Default_Variables() {
echo -e "Fetching latest data from CyberPanel server...\n"
echo -e "This may take few seconds..."
Silent="Off"
Server_Edition="OLS"
Admin_Pass="1234567"
Memcached="Off"
Redis="Off"
Postfix_Switch="On"
PowerDNS_Switch="On"
PureFTPd_Switch="On"
Server_IP=""
Server_Country="Unknow"
Server_OS=""
Server_OS_Version=""
Server_Provider='Undefined'
Watchdog="On"
Redis_Hosting="No"
Temp_Value=$(curl --silent --max-time 30 -4 https://cyberpanel.net/version.txt)
Panel_Version=${Temp_Value:12:3}
Panel_Build=${Temp_Value:25:1}
Branch_Name="v${Panel_Version}.${Panel_Build}"
if [[ $Branch_Name = v*.*.* ]] ; then
echo -e "\nBranch name fetched...$Branch_Name"
else
echo -e "\nUnable to fetch Branch name..."
echo -e "\nPlease try again in few moments, if this error still happens, please contact support"
exit
fi
Base_Number="1.9.3"
Total_RAM=$(free -m | awk '/Mem:/ { print $2 }')
Remote_MySQL="Off"
Final_Flags=()
Git_User=""
Git_Content_URL=""
Git_Clone_URL=""
LSWS_Latest_URL="https://cyberpanel.sh/update.litespeedtech.com/ws/latest.php"
LSWS_Tmp=$(curl --silent --max-time 30 -4 "$LSWS_Latest_URL")
LSWS_Stable_Line=$(echo "$LSWS_Tmp" | grep "LSWS_STABLE")
LSWS_Stable_Version=$(expr "$LSWS_Stable_Line" : '.*LSWS_STABLE=\(.*\) BUILD .*')
#grab the LSWS latest stable version.
Enterprise_Flag=""
License_Key=""
Debug_Log2 "Starting installation..,1"
}
Debug_Log() {
echo -e "\n${1}=${2}\n" >> "/var/log/cyberpanel_debug_$(date +"%Y-%m-%d")_${Random_Log_Name}.log"
}
Debug_Log2() {
Check_Server_IP "$@" >/dev/null 2>&1
echo -e "\n${1}" >> /var/log/installLogs.txt
curl --max-time 20 -d '{"ipAddress": "'"$Server_IP"'", "InstallCyberPanelStatus": "'"$1"'"}' -H "Content-Type: application/json" -X POST https://cloud.cyberpanel.net/servers/RecvData >/dev/null 2>&1
}
Branch_Check() {
if [[ "$1" = *.*.* ]]; then
#check input if it's valid format as X.Y.Z
Output=$(awk -v num1="$Base_Number" -v num2="${1//[[:space:]]/}" '
BEGIN {
print "num1", (num1 < num2 ? "<" : ">="), "num2"
}
')
if [[ $Output = *">="* ]]; then
echo -e "\nYou must use version number higher than 1.9.4"
exit
else
Branch_Name="v${1//[[:space:]]/}"
echo -e "\nSet branch name to $Branch_Name..."
fi
else
echo -e "\nPlease input a valid format version number."
exit
fi
}
License_Check() {
License_Key="$1"
echo -e "\nChecking LiteSpeed Enterprise license key..."
if echo "$License_Key" | grep -q "^....-....-....-....$" && [[ ${#License_Key} = "19" ]]; then
echo -e "\nLicense key set...\n"
elif [[ ${License_Key,,} = "trial" ]] ; then
echo -e "\nTrial license set..."
License_Key="Trial"
else
echo -e "\nLicense key seems incorrect, please verify"
echo -e "\nIf you are copying/pasting, please make sure you didn't paste blank space...\n"
exit
fi
}
Check_Return() {
#check previous command result , 0 = ok , non-0 = something wrong.
# shellcheck disable=SC2181
if [[ $? != "0" ]]; then
if [[ -n "$1" ]] ; then
echo -e "\n\n\n$1"
fi
echo -e "above command failed..."
Debug_Log2 "command failed, exiting. For more information read /var/log/installLogs.txt [404]"
if [[ "$2" = "no_exit" ]] ; then
echo -e"\nRetrying..."
else
exit
fi
fi
}
# check command success or not
Retry_Command() {
# shellcheck disable=SC2034
for i in {1..50};
do
if [[ "$i" = "50" ]] ; then
echo "command $1 failed for 50 times, exit..."
exit 2
else
$1 && break || echo -e "\n$1 has failed for $i times\nWait for 3 seconds and try again...\n"; sleep 3;
fi
done
}
Check_Root() {
echo -e "\nChecking root privileges..."
if echo "$Sudo_Test" | grep SUDO >/dev/null; then
echo -e "\nYou are using SUDO , please run as root user...\n"
echo -e "\nIf you don't have direct access to root user, please run \e[31msudo su -\e[39m command (do NOT miss the \e[31m-\e[39m at end or it will fail) and then run installation command again."
exit
fi
if [[ $(id -u) != 0 ]] >/dev/null; then
echo -e "\nYou must run on root user to install CyberPanel...\n"
echo -e "or run following command: (do NOT miss the quotes)"
echo -e "\e[31msudo su -c \"sh <(curl https://cyberpanel.sh || wget -O - https://cyberpanel.sh)\"\e[39m"
exit 1
else
echo -e "\nYou are runing as root...\n"
fi
}
Check_Server_IP() {
Server_IP=$(curl --silent --max-time 30 -4 https://cyberpanel.sh/?ip)
if [[ $Server_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo -e "Valid IP detected..."
else
echo -e "Can not detect IP, exit..."
Debug_Log2 "Can not detect IP. [404]"
exit
fi
echo -e "\nChecking server location...\n"
if [[ "$Server_Country" != "CN" ]] ; then
Server_Country=$(curl --silent --max-time 10 -4 https://cyberpanel.sh/?country)
if [[ ${#Server_Country} != "2" ]] ; then
Server_Country="Unknow"
fi
fi
#to avoid repeated check_ip called by debug_log2 to break force mirror for CN servers.
if [[ "$Debug" = "On" ]] ; then
Debug_Log "Server_IP" "$Server_IP"
Debug_Log "Server_Country" "$Server_Country"
fi
if [[ "$*" = *"--mirror"* ]] ; then
Server_Country="CN"
echo -e "Force to use mirror server due to --mirror argument...\n"
fi
if [[ "$Server_Country" = *"CN"* ]] ; then
Server_Country="CN"
echo -e "Setting up to use mirror server...\n"
fi
}
Check_OS() {
if [[ ! -f /etc/os-release ]] ; then
echo -e "Unable to detect the operating system...\n"
exit
fi
# Reference: https://unix.stackexchange.com/questions/116539/how-to-detect-the-desktop-environment-in-a-bash-script
if [ -z "$XDG_CURRENT_DESKTOP" ]; then
echo -e "Desktop OS not detected. Proceeding\n"
else
echo "$XDG_CURRENT_DESKTOP defined appears to be a desktop OS. Bailing as CyberPanel is incompatible."
echo -e "\nCyberPanel is supported on server OS types only. Such as Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, Ubuntu 20.10 x86_64, Ubuntu 22.04 x86_64, CentOS 8.x, AlmaLinux 8.x and CloudLinux 7.x...\n"
exit
fi
if ! uname -m | grep -qE 'x86_64|aarch64' ; then
echo -e "x86_64 or ARM system is required...\n"
exit
fi
if grep -q -E "CentOS Linux 7|CentOS Linux 8|CentOS Stream" /etc/os-release ; then
Server_OS="CentOS"
elif grep -q "Red Hat Enterprise Linux" /etc/os-release ; then
Server_OS="RedHat"
elif grep -q "AlmaLinux-8" /etc/os-release ; then
Server_OS="AlmaLinux"
elif grep -q "AlmaLinux-9" /etc/os-release ; then
Server_OS="AlmaLinux"
elif grep -q -E "CloudLinux 7|CloudLinux 8" /etc/os-release ; then
Server_OS="CloudLinux"
elif grep -q -E "Rocky Linux" /etc/os-release ; then
Server_OS="RockyLinux"
elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04|Ubuntu 20.10|Ubuntu 22.04" /etc/os-release ; then
Server_OS="Ubuntu"
elif grep -q -E "openEuler 20.03|openEuler 22.03" /etc/os-release ; then
Server_OS="openEuler"
else
echo -e "Unable to detect your system..."
echo -e "\nCyberPanel is supported on x86_64 based Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, Ubuntu 22.04, CentOS 7, CentOS 8, CentOS 9, RHEL 8, RHEL 9, AlmaLinux 8, AlmaLinux 9, RockyLinux 8, CloudLinux 7, CloudLinux 8, openEuler 20.03, openEuler 22.03...\n"
Debug_Log2 "CyberPanel is supported on x86_64 based Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, Ubuntu 22.04, CentOS 7, CentOS 8, CentOS 9, RHEL 8, RHEL 9, AlmaLinux 8, RockyLinux 8, AlmaLinux 9, CloudLinux 7, CloudLinux 8, openEuler 20.03, openEuler 22.03... [404]"
exit
fi
Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | head -c2 | tr -d . )
#to make 20.04 display as 20, etc.
echo -e "System: $Server_OS $Server_OS_Version detected...\n"
if [[ $Server_OS = "CloudLinux" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "RockyLinux" ]] || [[ "$Server_OS" = "RedHat" ]] ; then
Server_OS="CentOS"
#CloudLinux gives version id like 7.8, 7.9, so cut it to show first number only
#treat CloudLinux, Rocky and Alma as CentOS
fi
if [[ "$Debug" = "On" ]] ; then
Debug_Log "Server_OS" "$Server_OS $Server_OS_Version"
fi
}
Check_Virtualization() {
echo -e "Checking virtualization type..."
#if hostnamectl | grep -q "Virtualization: lxc"; then
# echo -e "\nLXC detected..."
# echo -e "CyberPanel does not support LXC"
# echo -e "Exiting..."
# Debug_Log2 "CyberPanel does not support LXC.. [404]"
# exit
#fi
#remove per https://github.com/usmannasir/cyberpanel/issues/589
if hostnamectl | grep -q "Virtualization: openvz"; then
echo -e "OpenVZ detected...\n"
if [[ ! -d /etc/systemd/system/pure-ftpd.service.d ]]; then
mkdir /etc/systemd/system/pure-ftpd.service.d
echo "[Service]
PIDFile=/run/pure-ftpd.pid" >/etc/systemd/system/pure-ftpd.service.d/override.conf
echo -e "PureFTPd service file modified for OpenVZ..."
fi
if [[ ! -d /etc/systemd/system/lshttpd.service.d ]]; then
mkdir /etc/systemd/system/lshttpd.service.d
echo "[Service]
PIDFile=/tmp/lshttpd/lshttpd.pid" >/etc/systemd/system/lshttpd.service.d/override.conf
echo -e "LiteSPeed service file modified for OpenVZ..."
fi
if [[ ! -d /etc/systemd/system/spamassassin.service.d ]]; then
mkdir /etc/systemd/system/spamassassin.service.d
echo "[Service]
PIDFile=/run/spamassassin.pid" >/etc/systemd/system/spamassassin.service.d/override.conf
echo -e "SpamAssassin service file modified for OpenVZ..."
fi
fi
if [[ "$Debug" = "On" ]] ; then
Debug_Log "Server_Virtualization" "$(hostnamectl | grep "Virtualization")"
fi
}
Check_Panel() {
if [[ -d /usr/local/cpanel ]]; then
echo -e "\ncPanel detected...\n"
Debug_Log2 "cPanel detected...exit... [404]"
exit
elif [[ -d /usr/local/directadmin ]]; then
echo -e "\nDirectAdmin detected...\n"
Debug_Log2 "DirectAdmin detected...exit... [404]"
exit
elif [[ -d /etc/httpd/conf/plesk.conf.d/ ]] || [[ -d /etc/apache2/plesk.conf.d/ ]]; then
echo -e "\nPlesk detected...\n"
Debug_Log2 "Plesk detected...exit... [404]"
exit
elif [[ -d /usr/local/panel/ ]]; then
echo -e "\nOpenPanel detected...\n"
Debug_Log2 "OpenPanel detected...exit... [404]"
exit
fi
}
Check_Process() {
if systemctl is-active --quiet httpd; then
systemctl disable httpd
systemctl stop httpd
systemctl mask httpd
echo -e "\nhttpd process detected, disabling...\n"
fi
if systemctl is-active --quiet apache2; then
systemctl disable apache2
systemctl stop apache2
systemctl mask apache2
echo -e "\napache2 process detected, disabling...\n"
fi
if systemctl is-active --quiet named; then
systemctl stop named
systemctl disable named
systemctl mask named
echo -e "\nnamed process detected, disabling...\n"
fi
if systemctl is-active --quiet exim; then
systemctl stop exim
systemctl disable exim
systemctl mask exim
echo -e "\nexim process detected, disabling...\n"
fi
}
Check_Provider() {
if hash dmidecode >/dev/null 2>&1; then
if [[ "$(dmidecode -s bios-vendor)" = "Google" ]]; then
Server_Provider="Google Cloud Platform"
elif [[ "$(dmidecode -s bios-vendor)" = "DigitalOcean" ]]; then
Server_Provider="Digital Ocean"
elif [[ "$(dmidecode -s system-product-name | cut -c 1-7)" = "Alibaba" ]]; then
Server_Provider="Alibaba Cloud"
elif [[ "$(dmidecode -s system-manufacturer)" = "Microsoft Corporation" ]]; then
Server_Provider="Microsoft Azure"
elif [[ -d /usr/local/qcloud ]]; then
Server_Provider="Tencent Cloud"
else
Server_Provider="Undefined"
fi
else
Server_Provider='Undefined'
fi
if [[ -f /sys/devices/virtual/dmi/id/product_uuid ]]; then
if [[ "$(cut -c 1-3 /sys/devices/virtual/dmi/id/product_uuid)" = 'EC2' ]] && [[ -d /home/ubuntu ]]; then
Server_Provider='Amazon Web Service'
fi
fi
if [[ "$Debug" = "On" ]] ; then
Debug_Log "Server_Provider" "$Server_Provider"
fi
}
Show_Help() {
echo -e "\nCyberPanel Installer Script Help\n"
echo -e "\nUsage: sh <(curl cyberpanel.sh) --argument"
echo -e "\n\e[31m-v\e[39m or \e[31m--version\e[39m : choose to install CyberPanel OpenLiteSpeed or CyberPanel Enterprise, available options are \e[31mols\e[39m , \e[31mTRIAL\e[39m and \e[31mSERIAL_NUMBER\e[39m, default ols"
echo -e "Please be aware, this serial number must be obtained from LiteSpeed Store."
echo -e "And if this serial number has been used before, it must be released/migrated in Store first, otherwise it will fail to start."
echo -e "\n\e[31m-a\e[39m or \e[31m--addons\e[39m : install addons: memcached, redis, PHP extension for memcached and redis"
echo -e "\n\e[31m-p\e[39m or \e[31m--password\e[39m : set password of new installation, empty for default 1234567, [r] or [random] for randomly generated 16 digital password, any other value besides [d] and [r(andom)] will be accept as password, default use 1234567."
echo -e "e.g. \e[31m-p r\e[39m will generate a random password"
echo -e " \e[31m-p 123456789\e[39m will set password to 123456789"
echo -e "\n\e[31m-m\e[39m or \e[31m--minimal\e[39m : set to minimal mode which will not install PowerDNS, Pure-FTPd and Postfix"
echo -e "\n\e[31m-m postfix/pureftpd/powerdns\e[39m will do minimal install also with compoenent given"
echo -e "e.g. \e[31m-m postfix\e[39m will do minimal install also with Postfix"
echo -e " \e[31m-m powerdns\e[39m will do minimal install also with PowerDNS"
echo -e " \e[31m-m postfix\e[39m powerdns will do minimal install also with Postfix and PowerDNS"
echo -e "\n\e[31m-b\e[39m or \e[31m--branch\e[39m : install with given branch/version , must be higher than 1.9.4"
echo -e "e.g. \e[31m-b 2.0.2\e[39m will install 2.0.2 version"
echo -e "\n\e[31m--mirror\e[39m : this argument force to use mirror server for majority of repositories, only suggest to use for servers within China"
echo -e "\nExample:"
echo -e "\nsh <(curl cyberpanel.sh) -v ols -p r or ./cyberpanel.sh --version ols --password random"
echo -e "\nThis will install CyberPanel OpenLiteSpeed and randomly generate the password."
echo -e "\nsh <(curl cyberpanel.sh) -v LICENSE_KEY -a -p my_pass_word"
echo -e "\nThis will install LiteSpeed Enterise , replace LICENSE_KEY to actual license key and set password to my_pass_word\n"
}
Check_Argument() {
if [[ "$#" = "0" ]] || [[ "$#" = "1" && "$1" = "--debug" ]] || [[ "$#" = "1" && "$1" = "--mirror" ]]; then
echo -e "\nInitialized...\n"
else
if [[ $1 = "help" ]]; then
Show_Help
exit
elif [[ $1 = "default" ]]; then
echo -e "\nThis will start default installation...\n"
Silent="On"
Postfix_Switch="On"
PowerDNS_Switch="On"
PureFTPd_Switch="On"
Server_Edition="OLS"
Admin_Pass="1234567"
Memcached="On"
Redis="On"
else
while [[ -n "${1}" ]]; do
case $1 in
-v | --version)
shift
if [[ "${1}" = "" ]]; then
Show_Help
exit
elif [[ "${1^^}" = "OLS" ]] ; then
Server_Edition="OLS"
Silent="On"
echo -e "\nSet to use OpenLiteSpeed..."
else
Server_Edition="Enterprise"
License_Key="${1}"
Silent="On"
echo -e "\nSet to use LiteSpeed Enterprise..."
echo -e "\nSet to use license key ${1}..."
fi
;;
-p | --password)
shift
if [[ ${1} = "" ]]; then
Admin_Pass="1234567"
elif [[ ${1} = "r" ]] || [[ $1 = "random" ]]; then
Admin_Pass=$(
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16
echo ''
)
elif [[ ${1} = "d" ]]; then
Admin_Pass="1234567"
else
if [[ ${#1} -lt 8 ]]; then
echo -e "\nPassword length less than 8 digital, please choose a more complicated password.\n"
exit
fi
Admin_Pass="${1}"
fi
echo -e "\nSet to use password ${1}..."
;;
-b | --branch)
shift
Branch_Check "${1}"
;;
-m | --minimal)
if ! echo "$@" | grep -q -i "postfix\|pureftpd\|powerdns" ; then
Postfix_Switch="Off"
PowerDNS_Switch="Off"
PureFTPd_Switch="Off"
echo -e "\nSet to use minimal installation..."
else
if [[ "${*^^}" = *"POSTFIX"* ]] ; then
Postfix_Switch="On"
echo -e "\nEnable Postfix..."
fi
if [[ "${*^^}" = *"PUREFTPD"* ]] ; then
PureFTPd_Switch="On"
echo -e "\nEnable PureFTPd..."
fi
if [[ "${*^^}" = *"POWERDNS"* ]] ; then
PowerDNS_Switch="On"
echo -e "\nEnable PowerDNS..."
fi
fi
;;
-a | --addons)
Memcached="On"
Redis="On"
echo -e "\nEnable Addons..."
;;
-h | --help)
Show_Help
exit
;;
--debug)
echo -e "\nEnable Debug log...\n"
;;
--mirror)
echo -e "\nForce to use mirror server...\n"
;;
*)
if [[ "${1^^}" = *"POSTFIX"* ]] || [[ "${1^^}" = *"PUREFTPD"* ]] || [[ "${1^^}" = *"POWERDNS"* ]] ; then
:
#this is ugly workaround , leave it for now , to-do for further improvement.
else
echo -e "\nUnknown argument...\n"
Show_Help
exit
fi
;;
esac
shift
done
fi
fi
if [[ "$Debug" = "On" ]] ; then
Debug_Log "Arguments" "${@}"
fi
Debug_Log2 "Initialization completed..,2"
}
Argument_Mode() {
if [[ "${Server_Edition^^}" = "OLS" ]] ; then
Server_Edition="OLS"
echo -e "\nSet to OpenLiteSpeed..."
else
License_Check "$License_Key"
fi
if [[ $Admin_Pass = "d" ]]; then
Admin_Pass="1234567"
echo -e "\nSet to default password..."
echo -e "\nAdmin password will be set to \e[31m$Admin_Pass\e[39m\n"
elif [[ $Admin_Pass = "r" ]]; then
Admin_Pass=$(
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16
echo ''
)
echo -e "\nSet to random-generated password..."
echo -e "\nAdmin password will be set to \e[31m$Admin_Pass\e[39m"
else
echo -e "\nAdmin password will be set to \e[31m$Admin_Pass\e[39m"
fi
}
Interactive_Mode() {
echo -e " CyberPanel Installer v$Panel_Version.$Panel_Build
1. Install CyberPanel.
2. Exit.
"
read -r -p " Please enter the number[1-2]: " Input_Number
echo ""
case "$Input_Number" in
1)
Interactive_Mode_Set_Parameter
;;
2)
exit
;;
*)
echo -e " Please enter the right number [1-2]\n"
exit
;;
esac
}
Interactive_Mode_Set_Parameter() {
echo -e " CyberPanel Installer v$Panel_Version.$Panel_Build
RAM check : $(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }')
Disk check : $(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}') (Minimal \e[31m10GB\e[39m free space)
1. Install CyberPanel with \e[31mOpenLiteSpeed\e[39m.
2. Install Cyberpanel with \e[31mLiteSpeed Enterprise\e[39m.
3. Exit.
"
read -r -p " Please enter the number[1-3]: " Input_Number
echo ""
case "$Input_Number" in
1)
Server_Edition="OLS"
;;
2)
Interactive_Mode_License_Input
;;
3)
exit
;;
*)
echo -e " Please enter the right number [1-3]\n"
exit
;;
esac
echo -e "\nInstall Full service for CyberPanel? This will include PowerDNS, Postfix and Pure-FTPd."
echo -e ""
printf "%s" "Full installation [Y/n]: "
read -r Tmp_Input
if [[ $(expr "x$Tmp_Input" : 'x[Yy]') -gt 1 ]] || [[ $Tmp_Input = "" ]]; then
echo -e "\nFull installation selected..."
Postfix_Switch="On"
PowerDNS_Switch="On"
PureFTPd_Switch="On"
else
echo -e ""
printf "%s" "Install Postfix? [Y/n]: "
read -r Tmp_Input
if [[ $Tmp_Input =~ ^(no|n|N) ]]; then
Postfix_Switch="Off"
else
Postfix_Switch="On"
fi
echo -e ""
printf "%s" "Install PowerDNS? [Y/n]: "
read -r Tmp_Input
if [[ $Tmp_Input =~ ^(no|n|N) ]]; then
PowerDNS_Switch="Off"
else
PowerDNS_Switch="On"
fi
echo -e ""
printf "%s" "Install PureFTPd? [Y/n]: "
read -r Tmp_Input
if [[ $Tmp_Input =~ ^(no|n|N) ]]; then
PureFTPd_Switch="Off"
else
PureFTPd_Switch="On"
fi
fi
### Ask if you want to set up this CyberPanel with remote MySQL
echo -e "\nDo you want to setup Remote MySQL? (This will skip installation of local MySQL)"
echo -e ""
printf "%s" "(Default = No) Remote MySQL [y/N]: "
read -r Tmp_Input
if [[ $(expr "x$Tmp_Input" : 'x[Yy]') -gt 1 ]]; then
echo -e "\nRemote MySQL selected..."
Remote_MySQL="On"
echo -e ""
printf "%s" "Remote MySQL Hostname: "
read -r MySQL_Host
echo -e ""
printf "%s" "Remote MySQL Database that contains meta information regarding MYSQL. (usually mysql): "
read -r MySQL_DB
echo -e ""
printf "%s" "Remote MySQL Username: "
read -r MySQL_User
echo -e ""
printf "%s" "Remote MySQL Password: "
read -r -s -p "Password: " MySQL_Password
echo -e ""
printf "%s" "Remote MySQL Port: "
read -r MySQL_Port
else
echo -e "\nLocal MySQL selected..."
fi
echo -e "\nPress \e[31mEnter\e[39m key to continue with latest version or Enter specific version such as: \e[31m1.9.4\e[39m , \e[31m2.0.1\e[39m , \e[31m2.0.2\e[39m ...etc"
printf "%s" ""
read -r Tmp_Input
if [[ $Tmp_Input = "" ]]; then
echo -e "Branch name set to $Branch_Name"
else
Branch_Check "$Tmp_Input"
fi
echo -e "\nPlease choose to use default admin password \e[31m1234567\e[39m, randomly generate one \e[31m(recommended)\e[39m or specify the admin password?"
printf "%s" "Choose [d]fault, [r]andom or [s]et password: [d/r/s] "
Tmp_Input="r"
if [[ $Tmp_Input =~ ^(d|D| ) ]] || [[ -z $Tmp_Input ]]; then
Admin_Pass="1234567"
echo -e "\nAdmin password will be set to $Admin_Pass\n"
elif [[ $Tmp_Input =~ ^(r|R) ]]; then
Admin_Pass=$(
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16
echo ''
)
echo -e "\nAdmin password will be provided once installation is completed...\n"
elif [[ $Tmp_Input =~ ^(s|S) ]]; then
Custom_Pass="True"
echo -e "\nPlease enter your password:"
printf "%s" ""
read -r -s -p "Password: " Tmp_Input
if [[ -z "$Tmp_Input" ]]; then
echo -e "\nPlease do not use empty string...\n"
exit
fi
if [[ ${#Tmp_Input} -lt 8 ]]; then
echo -e "\nPassword length less than 8 digital, please choose a more complicated password.\n"
exit
fi
Tmp_Input1=$Tmp_Input
read -r -s -p "Confirm Password:" Tmp_Input
if [[ -z "$Tmp_Input" ]]; then
echo -e "\nPlease do not use empty string...\n"
exit
fi
if [[ "$Tmp_Input" = "$Tmp_Input1" ]]; then
Admin_Pass=$Tmp_Input
else
echo -e "\nRepeated password didn't match , please check...\n"
exit
fi
else
Admin_Pass="1234567"
echo -e "\nAdmin password will be set to $Admin_Pass\n"
fi
echo -e "\nDo you wish to install Memcached process and its PHP extension?"
printf "%s" "Please select [Y/n]: "
read -r Tmp_Input
if [[ $Tmp_Input =~ ^(no|n|N) ]]; then
Memcached="Off"
else
Memcached="On"
echo -e "\nInstall Memcached process and its PHP extension set to Yes...\n"
fi
echo -e "\nDo you wish to install Redis process and its PHP extension?"
printf "%s" "Please select [Y/n]: "
read -r Tmp_Input
if [[ $Tmp_Input =~ ^(no|n|N) ]]; then
Redis="Off"
else
Redis="On"
echo -e "\nInstall Redis process and its PHP extension set to Yes...\n"
fi
echo -e "\nWould you like to set up a WatchDog \e[31m(beta)\e[39m for Web service and Database service ?"
echo -e "The watchdog script will be automatically started up after installation and server reboot"
echo -e "If you want to kill the watchdog , run \e[31mwatchdog kill\e[39m"
echo -e "Please type Yes or no (with capital \e[31mY\e[39m, default Yes): "
read -r Tmp_Input
if [[ $Tmp_Input = "Yes" ]] || [[ $Tmp_Input = "" ]]; then
Watchdog="On"
echo -e "\nInstall Watchdog set to Yes...\n"
else
Watchdog="Off"
fi
}
Interactive_Mode_License_Input() {
Server_Edition="Enterprise"
echo -e "\nPlease note that your server has \e[31m$Total_RAM MB\e[39m RAM"
echo -e "REMINDER: The \e[31mFree Start\e[39m license requires \e[31m2GB or less\e[39m of RAM and the \e[31mSite Owner\e[39m and \e[31mWeb Host Lite\e[39m licenses require \e[31m8GB or less\e[39m.\n"
echo -e "If you do not have any license, you can also use trial license (if server has not used trial license before), type \e[31mTRIAL\e[39m\n"
printf "%s" "Please input your serial number for LiteSpeed WebServer Enterprise: "
read -r License_Key
if [[ -z "$License_Key" ]]; then
echo -e "\nPlease provide license key\n"
exit
fi
echo -e "The serial number you input is: \e[31m$License_Key\e[39m\n"
printf "%s" "Please verify it is correct. [y/N]: "
read -r Tmp_Input
if [[ -z "$Tmp_Input" ]]; then
echo -e "\nPlease type \e[31my\e[39m\n"
exit
fi
License_Check "$License_Key"
#echo -e "\nWould you like use Redis Mass Hosting?"
#echo -e "Please type Yes or No (with capital \e[31mY\e[39m, default No):"
#read -r Redis_Hosting
#if [[ "$Redis_Hosting" = "Yes" ]]; then
# echo -e "\nRedis Mass Hosting is set to Yes...\n"
#fi
# hide it for now
}
Pre_Install_Setup_Repository() {
if [[ $Server_OS = "CentOS" ]] ; then
rpm --import https://cyberpanel.sh/rpms.litespeedtech.com/centos/RPM-GPG-KEY-litespeed
#import the LiteSpeed GPG key
yum clean all
yum autoremove -y epel-release
rm -f /etc/yum.repos.d/epel.repo
rm -f /etc/yum.repos.d/epel.repo.rpmsave
if [[ "$Server_OS_Version" = "9" ]]; then
# Check if architecture is aarch64
if uname -m | grep -q 'aarch64' ; then
# Run the following commands if architecture is aarch64
/usr/bin/crb enable
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
dnf install libxcrypt-compat -y
fi
subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms || yum config-manager --set-enabled crb > /dev/null 2>&1
yum install -y https://cyberpanel.sh/dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
Check_Return "yum repo" "no_exit"
yum install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Check_Return "yum repo" "no_exit"
#!/bin/bash
# Check if architecture is x86_64
if uname -m | grep -q 'x86_64' ; then
# Create the MariaDB repository configuration file for x86_64 architecture
cat <<EOF >/etc/yum.repos.d/MariaDB.repo
# MariaDB 10.11 CentOS repository list - created 2021-08-06 02:01 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.11/rhel9-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=1
gpgcheck=1
EOF
echo "MariaDB repository file created for x86_64 architecture."
fi
fi
if [[ "$Server_OS_Version" = "8" ]]; then
rpm --import https://cyberpanel.sh/www.centos.org/keys/RPM-GPG-KEY-CentOS-Official
rpm --import https://cyberpanel.sh/dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8
yum install -y https://cyberpanel.sh/dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Check_Return "yum repo" "no_exit"
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* > /dev/null 2>&1
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* > /dev/null 2>&1
# ref: https://stackoverflow.com/questions/70926799/centos-through-vm-no-urls-in-mirrorlist
dnf config-manager --set-enabled PowerTools > /dev/null 2>&1
dnf config-manager --set-enabled powertools > /dev/null 2>&1
# cat <<EOF >/etc/yum.repos.d/CentOS-PowerTools-CyberPanel.repo
#[powertools-for-cyberpanel]
#name=CentOS Linux \$releasever - PowerTools
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=PowerTools&infra=\$infra
#baseurl=http://mirror.centos.org/\$contentdir/\$releasever/PowerTools/\$basearch/os/
#gpgcheck=1
#enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
#EOF
fi
if [[ "$Server_OS_Version" = "7" ]]; then
rpm --import https://cyberpanel.sh/dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Check_Return "yum repo" "no_exit"
yum install -y yum-plugin-copr
Check_Return "yum repo" "no_exit"
yum copr enable -y copart/restic
Check_Return "yum repo" "no_exit"
yum install -y yum-plugin-priorities
Check_Return "yum repo" "no_exit"
curl -o /etc/yum.repos.d/powerdns-auth-43.repo https://cyberpanel.sh/repo.powerdns.com/repo-files/centos-auth-43.repo
Check_Return "yum repo" "no_exit"
cat <<EOF >/etc/yum.repos.d/MariaDB.repo
# MariaDB 10.4 CentOS repository list - created 2021-08-06 02:01 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
yum install --nogpg -y https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm
Check_Return "yum repo" "no_exit"
rpm -ivh https://cyberpanel.sh/repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm
Check_Return "yum repo" "no_exit"
rpm -ivh https://cyberpanel.sh/repo.ius.io/ius-release-el7.rpm
Check_Return "yum repo" "no_exit"
fi
fi
if [[ $Server_OS = "openEuler" ]]; then
rpm --import https://cyberpanel.sh/rpms.litespeedtech.com/centos/RPM-GPG-KEY-litespeed
#import the LiteSpeed GPG key
yum clean all
sed -i "s|gpgcheck=1|gpgcheck=0|g" /etc/yum.repos.d/openEuler.repo
sed -i "s|repo.openeuler.org|mirror.efaith.com.hk/openeuler|g" /etc/yum.repos.d/openEuler.repo
if [[ "$Server_OS_Version" = "20" ]]; then
dnf install --nogpg -y https://repo.yaro.ee/yaro-release-20.03LTS-latest.oe1.noarch.rpm
Check_Return "yum repo" "no_exit"
fi
if [[ "$Server_OS_Version" = "22" ]]; then
dnf install --nogpg -y https://repo.yaro.ee/yaro-release-22.03LTS-latest.oe2203.noarch.rpm
Check_Return "yum repo" "no_exit"
fi
fi
Debug_Log2 "Setting up repositories...,1"
if [[ "$Server_Country" = "CN" ]] ; then
Pre_Install_Setup_CN_Repository
Debug_Log2 "Setting up repositories for CN server...,1"
fi
if [[ "$Server_Country" = "CN" ]] || [[ "$Server_Provider" = "Alibaba Cloud" ]] || [[ "$Server_Provider" = "Tencent Cloud" ]]; then
Setup_Pip
fi
}
Setup_Pip() {
rm -rf /root/.pip
mkdir -p /root/.pip
cat <<EOF >/root/.pip/pip.conf
[global]
index-url=https://cyberpanel.sh/pip-repo/pypi/simple/
EOF
#default to self-host pip for CN
if [[ "$Server_Provider" = "Alibaba Cloud" ]] ; then
sed -i 's|https://cyberpanel.sh/pip-repo/pypi/simple/|http://mirrors.cloud.aliyuncs.com/pypi/simple/|g' /root/.pip/pip.conf
echo "trusted-host = mirrors.cloud.aliyuncs.com" >> /root/.pip/pip.conf
fi
if [[ "$Server_Provider" = "Tencent Cloud" ]] ; then
sed -i 's|https://cyberpanel.sh/pip-repo/pypi/simple/|https://mirrors.cloud.tencent.com/pypi/simple/|g' /root/.pip/pip.conf
fi
#set Alibaba and Tencent to their private mirror
Debug_Log2 "Setting up PIP repo...,3"
#set up pip for Alibaba, Tencent worldwide and Chinese server
if [[ "$Debug" = "On" ]] ; then
Debug_Log "Pip Source" "$(grep "index-url" /root/.pip/pip.conf)"
fi
}
Pre_Install_Setup_CN_Repository() {
if [[ "$Server_OS" = "CentOS" ]] && [[ "$Server_OS_Version" = "7" ]]; then
sed -i 's|http://yum.mariadb.org|https://cyberpanel.sh/yum.mariadb.org|g' /etc/yum.repos.d/MariaDB.repo
sed -i 's|https://yum.mariadb.org/RPM-GPG-KEY-MariaDB|https://cyberpanel.sh/yum.mariadb.org/RPM-GPG-KEY-MariaDB|g' /etc/yum.repos.d/MariaDB.repo