-
Notifications
You must be signed in to change notification settings - Fork 7
/
lsws1clk.sh
executable file
·2137 lines (1978 loc) · 61.9 KB
/
lsws1clk.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
# /***************************************************************
# LiteSpeed Latest
# WordPress Latest
# Magento stable
# LSCache Latest
# Memcached stable
# Redis stable
# PHPMyAdmin Latest
# ****************************************************************/
### Author: Cold Egg
CMDFD='/opt'
WWWFD='/var/www'
DOCROOT='/var/www/html'
PHPMYFD='/var/www/phpmyadmin'
PHPMYCONF="${PHPMYFD}/config.inc.php"
LSDIR='/usr/local/lsws'
LSCONF="${LSDIR}/conf/httpd_config.xml"
LSVCONF="${LSDIR}/DEFAULT/conf/vhconf.xml"
USER=''
GROUP=''
LSUSER=''
LSPASS=''
LSGROUP=''
THEME='twentytwenty'
MARIAVER='10.9'
DF_PHPVER='83'
PHPVER='83'
PHP_M='8'
PHP_S='3'
FIREWALLLIST="22 80 443 7080 9200"
PHP_MEMORY='1999'
PHP_BIN="${LSDIR}/lsphp${PHPVER}/bin/php"
PHPINICONF=""
WPCFPATH="${DOCROOT}/wp-config.php"
REPOPATH=''
WP_CLI='/usr/local/bin/wp'
MA_COMPOSER='/usr/local/bin/composer'
LS_VER='6.3.1'
MA_VER='2.4.7'
#OC_VER='4.0.2.3'
OC_VER='3.0.4.0'
PS_VER='8.2'
COMPOSER_VER='2.4.2'
EMAIL='[email protected]'
APP_ACCT=''
APP_PASS=''
MA_BACK_URL=''
OC_BACK_URL='admin'
PS_BACK_URL='admin'
MEMCACHECONF=''
REDISSERVICE=''
REDISCONF=''
WPCONSTCONF="${DOCROOT}/wp-content/plugins/litespeed-cache/data/const.default.ini"
PLUGIN='litespeed-cache.zip'
BANNERNAME='litespeed'
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
BANNERDST=''
SKIP_WP=0
SKIP_REDIS=0
SKIP_MEMCA=0
app_skip=0
SAMPLE='false'
LICENSE='TRIAL'
UNINSTALL_ALL=''
OSNAMEVER=''
OSNAME=''
OSVER=''
DRUSHVER=12
APP='wordpress'
EPACE=' '
FPACE=' '
silent() {
if [[ $debug ]] ; then
"$@"
else
"$@" >/dev/null 2>&1
fi
}
check_input(){
if [ -z "${1}" ];then
help_message 2
exit 1
fi
}
create_doc_fd(){
if [ ! -d ${DOCROOT} ]; then
echoG "Create ${DOCROOT} folder"
mkdir -p ${DOCROOT}
fi
}
echoY() {
echo -e "\033[38;5;148m${1}\033[39m"
}
echoG() {
echo -e "\033[38;5;71m${1}\033[39m"
}
echoR()
{
echo -e "\033[38;5;203m${1}\033[39m"
}
echow(){
FLAG=${1}
shift
echo -e "\033[1m${EPACE}${FLAG}\033[0m${@}"
}
help_message(){
case ${1} in
"1")
echoY 'Installation finished, please reopen the ssh console to see the banner.'
if [ "${APP}" = 'opencart' ]; then
echo "Follow https://docs.litespeedtech.com/lscache/lscoc/installation/ to seutp the cache."
fi
;;
"2")
echo 'This script is for testing porpuse, so we just use www-data as the user.'
echo -e "\033[1mOPTIONS\033[0m"
echow '-W, --wordpress'
echo "${EPACE}${EPACE}Example: lsws1clk.sh -W. If no input, script will still install wordpress by default"
echow '-M, --magento'
echo "${EPACE}${EPACE}Example: lsws1clk.sh -M"
echow '-M, --magento -S, --sample'
echo "${EPACE}${EPACE}Example: lsws1clk.sh -M -S, to install sample data"
echow '-O, --opencart'
echo "${EPACE}${EPACE}Example: lsws1clk.sh -O"
echow '-P, --prestashop'
echo "${EPACE}${EPACE}Example: lsws1clk.sh -P"
echow '--mautic'
echo "${EPACE}${EPACE}Example: lsws1clk.sh -D"
echow '-D, --drupal'
echo "${EPACE}${EPACE}Example: lsws1clk.sh --mautic"
echow '-L, --license'
echo "${EPACE}${EPACE}Example: lsws1clk.sh -L, to use specified LSWS serial number."
echow '--pure'
echo "${EPACE}${EPACE}Example: lsws1clk.sh --pure. It will install pure LSWS + PHP only."
echow '--uninstall'
echo "${EPACE}${EPACE}Example: lsws1clk.sh --uninstall. It will uninstall pure LSWS + PHP only."
echow '--uninstall-all'
echo "${EPACE}${EPACE}Example: lsws1clk.sh --uninstall-all. It will uninstall LSWS + PHP + all packages and document."
echow '-H, --help'
echo "${EPACE}${EPACE}Display help and exit."
exit 0
;;
esac
}
uninstall_msg(){
if [ ${UNINSTALL_ALL} = 'True' ]; then
printf '\033[31mUninstall LSWS, PHP, MariaDB, Postfix, Certbot and Document Folder, do you still want to continue?[y/N]\033[0m '
else
printf '\033[31mUninstall LSWS and PHP, do you still want to continue?[y/N]\033[0m '
fi
read answer
echo
if [ "$answer" != "Y" ] && [ "$answer" != "y" ] ; then
echoG "OK, exit script!"
exit 0
else
echoG "Ok, will start uninstall process .."
sleep 5
fi
}
get_ip(){
MYIP=$(curl -s http://checkip.amazonaws.com || printf "0.0.0.0")
}
function fst_match_line
{
FIRST_LINE_NUM=$(grep -n -m 1 "${1}" ${2} | awk -F ':' '{print $1}')
}
function fst_match_after
{
FIRST_NUM_AFTER=$(tail -n +${1} ${2} | grep -n -m 1 ${3} | awk -F ':' '{print $1}')
}
function lst_match_line
{
fst_match_after ${1} ${2} ${3}
LAST_LINE_NUM=$((${FIRST_LINE_NUM}+${FIRST_NUM_AFTER}-1))
}
line_change(){
LINENUM=$(grep -v '#' ${2} | grep -n "${1}" | cut -d: -f 1)
if [ -n "$LINENUM" ] && [ "$LINENUM" -eq "$LINENUM" ] 2>/dev/null; then
sed -i "${LINENUM}d" ${2}
sed -i "${LINENUM}i${3}" ${2}
fi
}
cked()
{
if [ -f /bin/ed ]; then
echoG "ed exist"
else
echoG "no ed, ready to install"
if [ "${OSNAME}" = 'ubuntu' ] || [ "${OSNAME}" = 'debian' ]; then
apt-get install ed -y > /dev/null 2>&1
elif [ "${OSNAME}" = 'centos' ]; then
yum install ed -y > /dev/null 2>&1
fi
fi
}
check_os()
{
OSTYPE=$(uname -m)
MARIADBCPUARCH=
if [ -f /etc/redhat-release ] ; then
OSVER=$(cat /etc/redhat-release | tr -dc '0-9.'|cut -d \. -f1)
if [ ${?} = 0 ] ; then
OSNAMEVER=CENTOS${OSVER}
OSNAME=centos
sudo wget -q -O - https://repo.litespeed.sh | sudo bash >/dev/null 2>&1
fi
elif [ -f /etc/lsb-release ] ; then
OSNAME=ubuntu
sudo wget -q -O - https://repo.litespeed.sh | sudo bash >/dev/null 2>&1
UBUNTU_V=$(grep 'DISTRIB_RELEASE' /etc/lsb-release | awk -F '=' '{print substr($2,1,2)}')
if [ ${UBUNTU_V} = 18 ] ; then
OSNAMEVER=UBUNTU18
OSVER=bionic
MARIADBCPUARCH="arch=amd64"
elif [ ${UBUNTU_V} = 20 ] ; then
OSNAMEVER=UBUNTU20
OSVER=focal
MARIADBCPUARCH="arch=amd64"
elif [ ${UBUNTU_V} = 22 ] ; then
OSNAMEVER=UBUNTU22
OSVER=jammy
MARIADBCPUARCH="arch=amd64"
elif [ ${UBUNTU_V} = 24 ] ; then
OSNAMEVER=UBUNTU24
OSVER=noble
MARIADBCPUARCH="arch=amd64"
fi
elif [ -f /etc/debian_version ] ; then
OSNAME=debian
wget -O - http://rpms.litespeedtech.com/debian/enable_lst_debain_repo.sh | bash >/dev/null 2>&1
DEBIAN_V=$(awk -F '.' '{print $1}' /etc/debian_version)
if [ ${DEBIAN_V} = 9 ] ; then
OSNAMEVER=DEBIAN9
OSVER=stretch
MARIADBCPUARCH="arch=amd64,i386"
elif [ ${DEBIAN_V} = 10 ] ; then
OSNAMEVER=DEBIAN10
OSVER=buster
elif [ ${DEBIAN_V} = 11 ] ; then
OSNAMEVER=DEBIAN11
OSVER=bullseye
elif [ ${DEBIAN_V} = 12 ] ; then
OSNAMEVER=DEBIAN12
OSVER=bookworm
fi
fi
if [ "${OSNAMEVER}" = "" ] ; then
echoR "Sorry, currently one click installation only supports Centos(6-9), Debian(9-11) and Ubuntu(18,20,22,24)."
echoR "You can download the source code and build from it."
exit 1
else
if [ "${OSNAME}" = "centos" ] ; then
echoG "Current platform is ${OSNAME} ${OSVER}"
else
export DEBIAN_FRONTEND=noninteractive
echoG "Current platform is ${OSNAMEVER} ${OSNAME} ${OSVER}."
fi
fi
}
path_update(){
if [ "${OSNAME}" = "centos" ] ; then
USER='nobody'
GROUP='nobody'
REPOPATH='/etc/yum.repos.d'
PHPINICONF="${LSDIR}/lsphp${PHPVER}/etc/php.ini"
REDISSERVICE='/lib/systemd/system/redis.service'
REDISCONF='/etc/redis.conf'
MEMCACHESERVICE='/etc/systemd/system/memcached.service'
MEMCACHECONF='/etc/sysconfig/memcached'
BANNERDST='/etc/profile.d/99-one-click.sh'
elif [ "${OSNAME}" = 'ubuntu' ] || [ "${OSNAME}" = 'debian' ]; then
USER='www-data'
GROUP='www-data'
REPOPATH='/etc/apt/sources.list.d'
PHPINICONF="${LSDIR}/lsphp${PHPVER}/etc/php/${PHP_M}.${PHP_S}/litespeed/php.ini"
REDISSERVICE='/lib/systemd/system/redis-server.service'
REDISCONF='/etc/redis/redis.conf'
MEMCACHECONF='/etc/memcached.conf'
BANNERDST='/etc/update-motd.d/99-one-click'
fi
if [ "${LSUSER}" = "" ]; then
LSUSER="${USER}"
LSGROUP="${GROUP}"
fi
}
provider_ck()
{
if [ -e /sys/devices/virtual/dmi/id/product_uuid ] && [ "$(sudo cat /sys/devices/virtual/dmi/id/product_uuid | cut -c 1-3)" = 'EC2' ]; then
PROVIDER='aws'
elif [ "$(dmidecode -s bios-vendor)" = 'Google' ];then
PROVIDER='google'
elif [ "$(dmidecode -s bios-vendor)" = 'DigitalOcean' ];then
PROVIDER='do'
elif [ "$(dmidecode -s system-product-name | cut -c 1-7)" = 'Alibaba' ];then
PROVIDER='aliyun'
elif [ "$(dmidecode -s system-manufacturer)" = 'Microsoft Corporation' ];then
PROVIDER='azure'
else
PROVIDER='undefined'
fi
}
phpver_ck(){
if [ "${APP}" = 'prestashop' ]; then
echoG 'Current Prestashop support PHP 81 only, update to 81!'
PHPVER='81'
PHP_M='8'
PHP_S='1'
fi
}
os_hm_path()
{
if [ ${PROVIDER} = 'aws' ] && [ -d /home/ubuntu ]; then
HMPATH='/home/ubuntu'
elif [ ${PROVIDER} = 'google' ] && [ -d /home/ubuntu ]; then
HMPATH='/home/ubuntu'
elif [ ${PROVIDER} = 'aliyun' ] && [ -d /home/ubuntu ]; then
HMPATH='/home/ubuntu'
else
HMPATH='/root'
fi
ADMIN_PASS_PATH="${HMPATH}/.litespeed_password"
DB_PASS_PATH="${HMPATH}/.db_password"
}
KILL_PROCESS(){
PROC_NUM=$(pidof ${1})
if [ ${?} = 0 ]; then
kill -9 ${PROC_NUM}
fi
}
var_update(){
if [ "${APP}" = 'magento' ]; then
echoG Update MariaDB version to '10.6' for Magento.
MARIAVER='10.6'
fi
}
ubuntu_var_update(){
var_update
}
centos_var_update(){
var_update
}
ubuntu_sysupdate(){
echoG 'System update'
silent apt-get update
silent DEBIAN_FRONTEND=noninteractive apt-get -y \
-o Dpkg::Options::='--force-confdef' \
-o Dpkg::Options::='--force-confold' upgrade
silent DEBIAN_FRONTEND=noninteractive apt-get -y \
-o Dpkg::Options::='--force-confdef' \
-o Dpkg::Options::='--force-confold' dist-upgrade
}
centos_sysupdate(){
echoG 'System update'
silent yum update -y
setenforce 0
}
remove_file(){
if [ -e ${1} ]; then
rm -rf ${1}
fi
}
backup_old(){
if [ -f ${1} ] && [ ! -f ${1}_old ]; then
mv ${1} ${1}_old
fi
}
linechange(){
LINENUM=$(grep -n "${1}" ${2} | cut -d: -f 1)
if [ -n "$LINENUM" ] && [ "$LINENUM" -eq "$LINENUM" ] 2>/dev/null; then
sed -i "${LINENUM}d" ${2}
sed -i "${LINENUM}i${3}" ${2}
fi
}
gen_password(){
if [ ! -f ${ADMIN_PASS_PATH} ]; then
ADMIN_PASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 ; echo '')
APP_STR=$(shuf -i 100-999 -n1)
APP_PASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 ; echo '')
APP_ACCT="admin${APP_STR}"
MA_BACK_URL="admin_${APP_STR}"
LSPASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 ; echo '')
else
ADMIN_PASS=$(grep admin_pass ${ADMIN_PASS_PATH} | awk -F'"' '{print $2}')
fi
if [ ! -f ${DB_PASS_PATH} ]; then
MYSQL_ROOT_PASS=$(openssl rand -hex 24)
MYSQL_USER_PASS=$(openssl rand -hex 24)
else
MYSQL_ROOT_PASS=$(grep root_mysql_pass ${DB_PASS_PATH} | awk -F'=' '{print $2}')
MYSQL_USER_PASS=$(grep wordpress_mysql_pass ${DB_PASS_PATH} | awk -F'=' '{print $2}')
fi
}
gen_salt(){
GEN_SALT=$(</dev/urandom tr -dc 'a-zA-Z0-9!@#%^&*()-_[]{}<>~+=' | head -c 64 | sed -e 's/[\/&]/\&/g')
}
gen_pass_file(){
if [ -f "${ADMIN_PASS_PATH}" ]; then
rm -f ${ADMIN_PASS_PATH}
fi
if [ -f "${DB_PASS_PATH}" ]; then
rm -f ${DB_PASS_PATH}
fi
echoG 'Generate .litespeed_password file'
touch ${ADMIN_PASS_PATH}
echoG 'Generate .db_password file'
touch ${DB_PASS_PATH}
}
update_pass_file(){
if [ "${APP}" = 'wordpress' ]; then
cat >> ${ADMIN_PASS_PATH} <<EOM
admin_pass="${ADMIN_PASS}"
EOM
elif [ "${APP}" = 'magento' ]; then
cat >> ${ADMIN_PASS_PATH} <<EOM
admin_pass="${ADMIN_PASS}"
Magento_admin_url="${MA_BACK_URL}"
MagentO_admin="${APP_ACCT}"
Magento_passd="${APP_PASS}${APP_STR}"
doc_user_name="${LSUSER}"
doc_user_pass="${LSPASS}"
EOM
elif [ "${APP}" = 'opencart' ]; then
cat >> ${ADMIN_PASS_PATH} <<EOM
admin_pass="${ADMIN_PASS}"
opencart_admin_url="${OC_BACK_URL}"
opencart_admin="${APP_ACCT}"
opencart_passd="${APP_PASS}"
EOM
elif [ "${APP}" = 'prestashop' ]; then
cat >> ${ADMIN_PASS_PATH} <<EOM
admin_pass="${ADMIN_PASS}"
prestashop_admin_url="${PS_BACK_URL}"
prestashop_admin="${EMAIL}"
prestashop_passd="${APP_PASS}"
EOM
elif [ "${APP}" = 'mautic' ]; then
cat >> ${ADMIN_PASS_PATH} <<EOM
admin_pass="${ADMIN_PASS}"
EOM
elif [ "${APP}" = 'drupal' ]; then
cat >> ${ADMIN_PASS_PATH} <<EOM
admin_pass="${ADMIN_PASS}"
EOM
fi
if [ "${APP}" = 'wordpress' ]; then
cat >> ${DB_PASS_PATH} <<EOM
root_mysql_pass="${MYSQL_ROOT_PASS}"
APP_DB_NAME="${APP}"
APP_DB_USER_NAME="${APP}"
APP_DB_pass="${MYSQL_USER_PASS}"
EOM
elif [ "${APP}" = 'magento' ]; then
cat >> ${DB_PASS_PATH} <<EOM
root_mysql_pass="${MYSQL_ROOT_PASS}"
APP_DB_NAME="${APP}"
APP_DB_USER_NAME="${APP}"
APP_DB_pass="${MYSQL_USER_PASS}"
EOM
elif [ "${APP}" = 'opencart' ]; then
cat >> ${DB_PASS_PATH} <<EOM
root_mysql_pass="${MYSQL_ROOT_PASS}"
APP_DB_NAME="${APP}"
APP_DB_USER_NAME="${APP}"
APP_DB_pass="${MYSQL_USER_PASS}"
EOM
elif [ "${APP}" = 'prestashop' ]; then
cat >> ${DB_PASS_PATH} <<EOM
root_mysql_pass="${MYSQL_ROOT_PASS}"
APP_DB_NAME="${APP}"
APP_DB_USER_NAME="${APP}"
APP_DB_pass="${MYSQL_USER_PASS}"
EOM
elif [ "${APP}" = 'mautic' ]; then
cat >> ${DB_PASS_PATH} <<EOM
root_mysql_pass="${MYSQL_ROOT_PASS}"
APP_DB_NAME="${APP}"
APP_DB_USER_NAME="${APP}"
APP_DB_pass="${MYSQL_USER_PASS}"
EOM
elif [ "${APP}" = 'drupal' ]; then
cat >> ${DB_PASS_PATH} <<EOM
root_mysql_pass="${MYSQL_ROOT_PASS}"
APP_DB_NAME="${APP}"
APP_DB_USER_NAME="${APP}"
APP_DB_pass="${MYSQL_USER_PASS}"
EOM
fi
}
rm_old_pkg(){
silent systemctl stop ${1}
if [ ${OSNAME} = 'centos' ]; then
silent yum remove ${1} -y
else
silent apt remove ${1} -y
fi
if [ $(systemctl is-active ${1}) != 'active' ]; then
echoG "[OK] remove ${1}"
else
echoR "[Failed] remove ${1}"
fi
}
restart_lsws(){
echoG 'Restart LiteSpeed Web Server'
${LSDIR}/bin/lswsctrl restart >/dev/null 2>&1
}
test_page(){
local URL=$1
local KEYWORD=$2
local PAGENAME=$3
rm -rf tmp.tmp
wget --no-check-certificate -O tmp.tmp $URL >/dev/null 2>&1
grep "$KEYWORD" tmp.tmp >/dev/null 2>&1
if [ $? != 0 ] ; then
echoR "Error: $PAGENAME failed."
TESTGETERROR=yes
else
echoG "OK: $PAGENAME passed."
fi
rm tmp.tmp
}
test_ols_admin(){
test_page https://localhost:7080/ "LiteSpeed WebAdmin" "test webAdmin page"
}
test_wp_page(){
test_page http://localhost:80/ 'data-continue' "test WordPress HTTP page"
test_page https://localhost:443/ 'data-continue' "test WordPress HTTPS page"
}
test_magento_page(){
test_page http://localhost:80/ 'Magento, Inc' "test Magento HTTP page"
test_page https://localhost:443/ 'Magento, Inc' "test Magento HTTPS page"
cd ${DOCROOT}; rm -rf var/cache/* var/page_cache/* var/generation/*
}
test_opencart_page(){
test_page http://localhost:80/ 'OpenCart' "test OpenCart HTTP page"
#test_page https://localhost:443/ 'Opencart' "test Opencart HTTPS page"
}
test_prestashop_page(){
test_page http://localhost:80/ 'PrestaShop' "test PrestaShop HTTP page"
test_page https://localhost:443/ 'PrestaShop' "test PrestaShop HTTPS page"
}
test_mautic_page(){
test_page http://localhost:80/ 'mautic' "test Mautic HTTP page"
test_page https://localhost:443/ 'mautic' "test Mautic HTTPS page"
}
ubuntu_pkg_basic(){
echoG 'Install basic packages'
silent apt-get install lsb-release -y
silent apt-get install curl wget unzip -y
silent apt-get install curl unzip software-properties-common -y
}
ubuntu_pkg_postfix(){
if [ -e /usr/sbin/postfix ]; then
echoG 'Postfix already installed'
else
echoG 'Installing postfix'
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::='--force-confdef' \
-o Dpkg::Options::='--force-confold' install postfix >/dev/null 2>&1
[[ -e /usr/sbin/postfix ]] && echoG 'Install postfix Success' || echoR 'Install postfix Failed'
fi
}
ubuntu_pkg_memcached(){
echoG 'Install Memcached'
apt-get -y install memcached > /dev/null 2>&1
if [ ${?} != 0 ]; then
echoR 'Memcache install failed, please check!'
SKIP_MEMCA=1
else
systemctl start memcached > /dev/null 2>&1
systemctl enable memcached > /dev/null 2>&1
fi
}
ubuntu_pkg_redis(){
echoG 'Install Redis'
apt-get -y install redis > /dev/null 2>&1
if [ ${?} != 0 ]; then
echoR 'Redis install failed, please check!'
SKIP_REDIS=1
else
systemctl start redis > /dev/null 2>&1
fi
}
pkg_phpmyadmin(){
if [ ! -f ${PHPMYFD}/changelog.php ]; then
cd ${CMDFD}/
echoG 'Install phpmyadmin'
wget -q --no-check-certificate https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
unzip phpMyAdmin-latest-all-languages.zip > /dev/null 2>&1
rm -f phpMyAdmin-latest-all-languages.zip
mv phpMyAdmin-*-all-languages ${PHPMYFD}
mv ${PHPMYFD}/config.sample.inc.php ${PHPMYCONF}
else
echoY "phpMyAdmin exist, skip!"
fi
}
ubuntu_pkg_phpmyadmin(){
pkg_phpmyadmin
}
ubuntu_pkg_ufw(){
if [ ! -f /usr/sbin/ufw ]; then
echoG 'Install ufw'
apt-get install ufw -y > /dev/null 2>&1
fi
}
ubuntu_pkg_certbot(){
echoG "Install CertBot"
apt-get -y install certbot > /dev/null 2>&1
if [ -e /usr/bin/certbot ] || [ -e /usr/local/bin/certbot ]; then
echoG 'Install CertBot finished'
else
echoR 'Please check CertBot'
fi
}
ubuntu_pkg_system(){
if [ -e /usr/sbin/dmidecode ]; then
echoG 'dmidecode already installed'
else
echoG 'Install dmidecode'
silent apt-get install dmidecode -y
[[ -e /usr/sbin/dmidecode ]] && echoG 'Install dmidecode Success' || echoR 'Install dmidecode Failed'
fi
}
ubuntu_pkg_mariadb(){
apt list --installed 2>/dev/null | grep mariadb-server >/dev/null 2>&1
if [ ${?} = 0 ]; then
echoG "Mariadb ${MARIAVER} already installed"
else
if [ "$OSNAMEVER" = "DEBIAN8" ]; then
silent ${APT} -y -f install software-properties-common
elif [ "$OSNAME" = "debian" ]; then
silent ${APT} -y -f install software-properties-common gnupg
elif [ "$OSNAME" = "ubuntu" ]; then
silent ${APT} -y -f install software-properties-common
fi
MARIADB_KEY='/usr/share/keyrings/mariadb.gpg'
wget -q -O- https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor > "${MARIADB_KEY}"
if [ ! -e "${MARIADB_KEY}" ]; then
echoR "${MARIADB_KEY} does not exist, please check the key, exit!"
exit 1
fi
echoG "${FPACE} - Add MariaDB repo"
if [ -e /etc/apt/sources.list.d/mariadb.list ]; then
grep -Fq "mirror.mariadb.org" /etc/apt/sources.list.d/mariadb.list >/dev/null 2>&1
if [ $? != 0 ] ; then
echo "deb [$MARIADBCPUARCH signed-by=${MARIADB_KEY}] http://mirror.mariadb.org/repo/$MARIAVER/$OSNAME $OSVER main" > /etc/apt/sources.list.d/mariadb.list
fi
else
echo "deb [$MARIADBCPUARCH signed-by=${MARIADB_KEY}] http://mirror.mariadb.org/repo/$MARIAVER/$OSNAME $OSVER main" > /etc/apt/sources.list.d/mariadb.list
fi
echoG "${FPACE} - Update packages"
apt-get update > /dev/null 2>&1
echoG "${FPACE} - Install MariaDB"
silent apt-get -y -f install mariadb-server
if [ $? != 0 ] ; then
echoR "An error occured during installation of MariaDB. Please fix this error and try again."
echoR "You may want to manually run the command 'apt-get -y -f --allow-unauthenticated install mariadb-server' to check. Aborting installation!"
exit 1
fi
echoG "${FPACE} - Start MariaDB"
service mysql start
fi
}
centos_pkg_basic(){
echoG 'Install basic packages'
silent yum install epel-release -y
silent yum update -y
silent yum install curl yum-utils wget unzip libnsl -y
if [[ -z "$(rpm -qa epel-release)" ]]; then
silent yum install epel-release -y
fi
if [ ! -e /usr/bin/yum-config-manager ]; then
silent yum install yum-utils -y
fi
if [ ! -e /usr/bin/curl ]; then
silent yum install curl -y
fi
}
centos_pkg_postfix(){
if [ -e /usr/sbin/postfix ]; then
echoG 'Postfix already installed'
else
echoG 'Installing postfix'
yum install postfix -y >/dev/null 2>&1
[[ -e /usr/sbin/postfix ]] && echoG 'Install postfix Success' || echoR 'Install postfix Failed'
fi
}
centos_pkg_memcached(){
echoG 'Install Memcached'
yum -y install memcached > /dev/null 2>&1
if [ ${?} != 0 ]; then
echoR 'Memcache install failed, please check!'
SKIP_MEMCA=1
else
systemctl start memcached > /dev/null 2>&1
systemctl enable memcached > /dev/null 2>&1
fi
}
centos_pkg_redis(){
echoG 'Install Redis'
yum -y install redis > /dev/null 2>&1
if [ ${?} != 0 ]; then
echoR 'Redis install failed, please check!'
SKIP_REDIS=1
else
systemctl start redis > /dev/null 2>&1
fi
}
centos_pkg_phpmyadmin(){
pkg_phpmyadmin
}
centos_pkg_certbot(){
echoG "Install CertBot"
if [ ${OSVER} = 8 ]; then
wget -q https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot
chown root /usr/local/bin/certbot
chmod 0755 /usr/local/bin/certbot
echo "y" | /usr/local/bin/certbot > /dev/null 2>&1
else
yum -y install certbot > /dev/null 2>&1
fi
if [ -e /usr/bin/certbot ] || [ -e /usr/local/bin/certbot ]; then
echoG 'Install CertBot finished'
else
echoR 'Please check CertBot'
fi
}
centos_pkg_system(){
if [ -e /usr/sbin/dmidecode ]; then
echoG 'dmidecode already installed'
else
echoG 'Install dmidecode'
silent yum install dmidecode -y
[[ -e /usr/sbin/dmidecode ]] && echoG 'Install dmidecode Success' || echoR 'Install dmidecode Failed'
fi
}
centos_pkg_mariadb(){
silent rpm -qa | grep mariadb-server-${MARIAVER}
if [ ${?} = 0 ]; then
echoG "Mariadb ${MARIAVER} already installed"
else
if [ "$OSTYPE" != "x86_64" ] ; then
CENTOSVER=centos$OSVER-x86
else
CENTOSVER=centos$OSVER-amd64
fi
if [ "$OSNAMEVER" = "CENTOS8" ] || [ "$OSNAMEVER" = "CENTOS9" ]; then
rpm --quiet --import https://downloads.mariadb.com/MariaDB/MariaDB-Server-GPG-KEY
cat > ${REPOPATH}/MariaDB.repo <<END
[mariadb]
name = MariaDB
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-$MARIAVER/yum/rhel/\$releasever/\$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
gpgcheck=1
enabled = 1
module_hotfixes = 1
END
else
cat > ${REPOPATH}/MariaDB.repo <<END
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/$MARIAVER/$CENTOSVER
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
END
fi
fi
echoG "${FPACE} - Install MariaDB"
if [ "$OSNAMEVER" = "CENTOS8" ] || [ "$OSNAMEVER" = "CENTOS9" ]; then
silent yum install -y boost-program-options
silent yum --disablerepo=AppStream install -y MariaDB-server MariaDB-client
else
silent yum -y install MariaDB-server MariaDB-client
fi
if [ $? != 0 ] ; then
echoR "An error occured during installation of MariaDB. Please fix this error and try again."
echoR "You may want to manually run the command 'yum -y install MariaDB-server MariaDB-client' to check. Aborting installation!"
exit 1
fi
echoG "${FPACE} - Start MariaDB"
if [ "$OSNAMEVER" = "CENTOS9" ] || [ "$OSNAMEVER" = "CENTOS8" ] || [ "$OSNAMEVER" = "CENTOS7" ] ; then
silent systemctl enable mariadb
silent systemctl start mariadb
else
service mysql start
fi
}
set_mariadb_root(){
SQLVER=$(mysql -u root -e 'status' | grep 'Server version')
SQLVER_1=$(echo ${SQLVER} | awk '{print substr ($3,1,2)}')
SQLVER_2=$(echo ${SQLVER} | awk -F '.' '{print $2}')
if (( ${SQLVER_1} >=11 )); then
mysql -u root -e "ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD('${MYSQL_ROOT_PASS}');"
elif (( ${SQLVER_1} ==10 )) && (( ${SQLVER_2} >=4 && ${SQLVER_2}<=9 )); then
mysql -u root -e "ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD('${MYSQL_ROOT_PASS}');"
elif (( ${SQLVER_1} ==10 )) && (( ${SQLVER_2} ==3 )); then
mysql -u root -e "UPDATE mysql.user SET authentication_string = '' WHERE user = 'root';"
mysql -u root -e "UPDATE mysql.user SET plugin = '' WHERE user = 'root';"
elif (( ${SQLVER_1} == 10 )) && (( ${SQLVER_2} == 2 )); then
mysql -u root -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('${MYSQL_ROOT_PASS}');"
else
echo 'Please check DB version!'
mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASS}';"
fi
}
install_lsws(){
cd ${CMDFD}/
if [ -e ${CMDFD}/lsws* ] || [ -d ${LSDIR} ]; then
echoY 'Remove existing LSWS'
silent systemctl stop lsws
KILL_PROCESS litespeed
rm -rf ${CMDFD}/lsws*
rm -rf ${LSDIR}
fi
echoG 'Download LiteSpeed Web Server'
wget -q --no-check-certificate https://www.litespeedtech.com/packages/6.0/lsws-${LS_VER}-ent-x86_64-linux.tar.gz -P ${CMDFD}/
silent tar -zxvf lsws-*-ent-x86_64-linux.tar.gz
rm -f lsws-*.tar.gz
cd lsws-*
if [ "${LICENSE}" == 'TRIAL' ]; then
wget -q --no-check-certificate http://license.litespeedtech.com/reseller/trial.key
else
echo "${LICENSE}" > serial.no
fi
sed -i '/^license$/d' install.sh
sed -i 's/read TMPS/TMPS=0/g' install.sh
sed -i 's/read TMP_YN/TMP_YN=N/g' install.sh
sed -i '/read [A-Z]/d' functions.sh
sed -i 's/HTTP_PORT=$TMP_PORT/HTTP_PORT=443/g' functions.sh
sed -i 's/ADMIN_PORT=$TMP_PORT/ADMIN_PORT=7080/g' functions.sh
sed -i "/^license()/i\
PASS_ONE=${ADMIN_PASS}\
PASS_TWO=${ADMIN_PASS}\
TMP_USER=${USER}\
TMP_GROUP=${GROUP}\
TMP_PORT=''\
TMP_DEST=''\
ADMIN_USER=''\
ADMIN_EMAIL=''
" functions.sh
echoG 'Install LiteSpeed Web Server'
silent /bin/bash install.sh
echoG 'Upgrade to Latest stable release'
silent ${LSDIR}/admin/misc/lsup.sh -f
silent ${LSDIR}/bin/lswsctrl start
SERVERV=$(cat /usr/local/lsws/VERSION)
echoG "Version: lsws ${SERVERV}"
rm -rf ${CMDFD}/lsws-*
cd /
}
ubuntu_install_lsws(){
install_lsws
}
centos_install_lsws(){
install_lsws
}
ubuntu_reinstall(){
apt --installed list 2>/dev/null | grep ${1} >/dev/null
if [ ${?} = 0 ]; then
OPTIONAL='--reinstall'
else
OPTIONAL=''
fi
}
centos_reinstall(){
rpm -qa | grep ${1} >/dev/null
if [ ${?} = 0 ]; then
OPTIONAL='reinstall'
else
OPTIONAL='install'
fi
}
uninstall_lsws(){
echoG 'Uninstall LiteSpeed Web Server'
if [ -d ${LSDIR} ]; then
silent systemctl stop lsws
rm -rf ${LSDIR}
fi
}
ubuntu_uninstall_lsws(){
uninstall_lsws
}
centos_uninstall_lsws(){
uninstall_lsws
}
ubuntu_install_php(){
echoG 'Install PHP & Packages for LSWS'
ubuntu_reinstall "lsphp${PHPVER}"
for PKG in '' -common -curl -gd -json -mysql -imagick -imap -memcached -msgpack -redis -mcrypt -opcache -intl; do
/usr/bin/apt ${OPTIONAL} install -y lsphp${PHPVER}${PKG} >/dev/null 2>&1
done
rm -f /usr/bin/php
}
centos_install_php(){
echoG 'Install PHP & Packages'
for PKG in '' -common -gd -pdo -imap -mbstring -imagick -mysqlnd -bcmath -soap -memcached -mcrypt -process -opcache -redis -json -xml -xmlrpc -intl; do
/usr/bin/yum install lsphp${PHPVER}${PKG} -y >/dev/null 2>&1
done
rm -f /usr/bin/php
}
ubuntu_uninstall_php(){
echoG 'Uninstall LSPHP'
apt-get purge --auto-remove lsphp* -y >/dev/null 2>&1
}
centos_uninstall_php(){
echoG 'Uninstall LSPHP'
yum remove lsphp* -y >/dev/null 2>&1
}
ubuntu_uninstall_pkg(){
echoG 'Uninstall packages'
apt-get purge --auto-remove mariadb-server certbot postfix -y >/dev/null 2>&1
rm -rf /var/lib/mysql/ /etc/mysql/
}
centos_uninstall_pkg(){
echoG 'Uninstall packages'
yum remove MariaDB-server MariaDB-client certbot postfix -y >/dev/null 2>&1
rm -rf /var/lib/mysql/ /etc/mysql/
}