-
Notifications
You must be signed in to change notification settings - Fork 61
/
ols1clk.sh
executable file
·2546 lines (2348 loc) · 83.8 KB
/
ols1clk.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
##############################################################################
# Open LiteSpeed is an open source HTTP server. #
# Copyright (C) 2013 - 2024 LiteSpeed Technologies, Inc. #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see http://www.gnu.org/licenses/. #
##############################################################################
### Author: LiteSpeed
TEMPRANDSTR=
OSNAMEVER=UNKNOWN
OSNAME=
OSVER=
OSTYPE=$(uname -m)
MARIADBCPUARCH=
SERVER_ROOT=/usr/local/lsws
WEBCF="$SERVER_ROOT/conf/httpd_config.conf"
EXAMPLE_VHOSTCONF="$SERVER_ROOT/conf/vhosts/Example/vhconf.conf"
RULE_FILE='modsec_includes.conf'
OWASP_DIR="${SERVER_ROOT}/conf/owasp"
CRS_DIR='owasp-modsecurity-crs'
OLSINSTALLED=
MYSQLINSTALLED=
TESTGETERROR=no
DATABASENAME=olsdbname
USERNAME=olsdbuser
DBPREFIX=wp_
VERBOSE=0
PURE_DB=0
PURE_MYSQL=0
PURE_PERCONA=0
WITH_MYSQL=0
WITH_PERCONA=0
PROXY=0
PROXY_TYPE=''
PROXY_SERVER='http://127.0.0.1:8080'
WORDPRESSPATH=$SERVER_ROOT/wordpress
PWD_FILE=$SERVER_ROOT/password
WPPORT=80
SSLWPPORT=443
WORDPRESSINSTALLED=
INSTALLWORDPRESS=0
INSTALLWORDPRESSPLUS=0
FORCEYES=0
WPLANGUAGE=en_US
WPUSER=wpuser
WPTITLE=MySite
SITEDOMAIN=*
EMAIL=
ADMINUSER='admin'
ADMINPORT='7080'
ADMINPASSWORD=
ROOTPASSWORD=
USERPASSWORD=
WPPASSWORD=
LSPHPVERLIST=(71 72 73 74 80 81 82 83)
MARIADBVERLIST=(10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 11.0 11.1 11.2 11.3)
OLD_SYS_MARIADBVERLIST=(10.2 10.3 10.4 10.5)
LSPHPVER=83
MARIADBVER=10.11
#MYSQLVER=8.0
PERCONAVER=80
WEBADMIN_LSPHPVER=74
OWASP_V='4.2.0'
SET_OWASP=
ALLERRORS=0
TEMPPASSWORD=
ACTION=INSTALL
FOLLOWPARAM=
CONFFILE=myssl.conf
CSR=example.csr
KEY=example.key
CERT=example.crt
EPACE=' '
FPACE=' '
APT='apt-get -qq'
YUM='yum -q'
MYGITHUBURL=https://raw.githubusercontent.com/litespeedtech/ols1clk/master/ols1clk.sh
function echoY
{
FLAG=$1
shift
echo -e "\033[38;5;148m$FLAG\033[39m$@"
}
function echoG
{
FLAG=$1
shift
echo -e "\033[38;5;71m$FLAG\033[39m$@"
}
function echoB
{
FLAG=$1
shift
echo -e "\033[38;1;34m$FLAG\033[39m$@"
}
function echoR
{
FLAG=$1
shift
echo -e "\033[38;5;203m$FLAG\033[39m$@"
}
function echoW
{
FLAG=${1}
shift
echo -e "\033[1m${EPACE}${FLAG}\033[0m${@}"
}
function echoNW
{
FLAG=${1}
shift
echo -e "\033[1m${FLAG}\033[0m${@}"
}
function echoCYAN
{
FLAG=$1
shift
echo -e "\033[1;36m$FLAG\033[0m$@"
}
function silent
{
if [ "${VERBOSE}" = '1' ] ; then
"$@"
else
"$@" >/dev/null 2>&1
fi
}
function change_owner
{
chown -R ${USER}:${GROUP} ${1}
}
function check_root
{
local INST_USER=`id -u`
if [ $INST_USER != 0 ] ; then
echoR "Sorry, only the root user can install."
echo
exit 1
fi
}
function update_system(){
echoG 'System update'
if [ "$OSNAME" = "centos" ] ; then
silent ${YUM} update -y >/dev/null 2>&1
else
disable_needrestart
silent ${APT} update && ${APT} upgrade -y >/dev/null 2>&1
fi
}
function check_wget
{
which wget >/dev/null 2>&1
if [ $? != 0 ] ; then
if [ "$OSNAME" = "centos" ] ; then
silent ${YUM} -y install wget
else
${APT} -y install wget
fi
which wget >/dev/null 2>&1
if [ $? != 0 ] ; then
echoR "An error occured during wget installation."
ALLERRORS=1
fi
fi
}
function check_curl
{
which curl >/dev/null 2>&1
if [ $? != 0 ] ; then
if [ "$OSNAME" = "centos" ] ; then
silent ${YUM} -y install curl
else
${APT} -y install curl
fi
which curl >/dev/null 2>&1
if [ $? != 0 ] ; then
echoR "An error occured during curl installation."
ALLERRORS=1
fi
fi
}
function update_email
{
if [ "$EMAIL" = '' ] ; then
if [ "$SITEDOMAIN" = "*" ] ; then
EMAIL=root@localhost
else
EMAIL=root@$SITEDOMAIN
fi
fi
}
function restart_lsws
{
systemctl stop lsws >/dev/null 2>&1
systemctl start lsws
}
function usage
{
echo -e "\033[1mOPTIONS\033[0m"
echoW " --adminuser [USERNAME]" "${EPACE} To set the WebAdmin username for OpenLiteSpeed instead of admin."
echoNW " -A, --adminpassword [PASSWORD]" "${EPACE}To set the WebAdmin password for OpenLiteSpeed instead of using a random one."
echoW " --adminport [PORTNUMBER]" "${EPACE} To set the WebAdmin console port number instead of 7080."
echoNW " -E, --email [EMAIL] " "${EPACE} To set the administrator email."
echoW " --lsphp [VERSION] " "To set the LSPHP version, such as 82. We currently support versions '${LSPHPVERLIST[@]}'."
echoW " --mariadbver [VERSION] " "To set MariaDB version, such as 10.6. We currently support versions '${MARIADBVERLIST[@]}'."
echoNW " -W, --wordpress " "${EPACE} To install WordPress. You will still need to complete the WordPress setup by browser"
echoW " --wordpressplus [SITEDOMAIN] " "To install, setup, and configure WordPress, also LSCache will be enabled"
echoW " --wordpresspath [WP_PATH] " "To specify a location for the new WordPress installation or an existing WordPress."
echoNW " -R, --dbrootpassword [PASSWORD] " " To set the database root password instead of using a random one."
echoW " --dbname [DATABASENAME] " "To set the database name to be used by WordPress."
echoW " --dbuser [DBUSERNAME] " "To set the WordPress username in the database."
echoW " --dbpassword [PASSWORD] " "To set the WordPress table password in MySQL instead of using a random one."
echoW " --prefix [PREFIXNAME] " "To set the WordPress table prefix."
echoW " --listenport [PORT] " "To set the HTTP server listener port, default is 80."
echoW " --ssllistenport [PORT] " "To set the HTTPS server listener port, default is 443."
echoW " --wpuser [WORDPRESSUSER] " "To set the WordPress admin user for WordPress dashboard login. Default value is wpuser."
echoW " --wppassword [PASSWORD] " "To set the WordPress admin user password for WordPress dashboard login."
echoW " --wplang [WP_LANGUAGE] " "To set the WordPress language. Default value is \"en_US\" for English."
echoW " --sitetitle [WP_TITLE] " "To set the WordPress site title. Default value is mySite."
echoW " --pure-mariadb " "To install OpenLiteSpeed and MariaDB"
echoW " --pure-mysql " "To install OpenLiteSpeed and MySQL"
echoW " --pure-percona " "To install OpenLiteSpeed and Percona"
echoW " --with-mysql " "To install OpenLiteSpeed/App with MySQL"
echoW " --with-percona " "To install OpenLiteSpeed/App with Percona"
echoW " --owasp-enable " "To enable mod_security with OWASP rules. If OLS is installed, then enable the owasp directly"
echoW " --owasp-disable " "To disable mod_security with OWASP rules."
echoW " --proxy-r " "To set a proxy with rewrite type."
echoW " --proxy-c " "To set a proxy with config type."
echoNW " -U, --uninstall " "${EPACE} To uninstall OpenLiteSpeed and remove installation directory."
echoNW " -P, --purgeall " "${EPACE} To uninstall OpenLiteSpeed, remove installation directory, and purge all data in MySQL."
echoNW " -Q, --quiet " "${EPACE} To use quiet mode, won't prompt to input anything."
echoNW " -V, --version " "${EPACE} To display the script version information."
echoNW " -v, --verbose " "${EPACE} To display more messages during the installation."
echoW " --update " "To update ols1clk from github."
echoNW " -H, --help " "${EPACE} To display help messages."
echo
echo -e "\033[1mEXAMPLES\033[0m"
echoW "./ols1clk.sh " "To install OpenLiteSpeed with a random WebAdmin password."
echoW "./ols1clk.sh --lsphp 83 " "To install OpenLiteSpeed with lsphp83."
echoW "./ols1clk.sh -A 123456 -e [email protected] " "To install OpenLiteSpeed with WebAdmin password \"123456\" and email [email protected]."
echoW "./ols1clk.sh -R 123456 -W " "To install OpenLiteSpeed with WordPress and MySQL root password \"123456\"."
echoW "./ols1clk.sh --wordpressplus a.com " "To install OpenLiteSpeed with a fully configured WordPress installation at \"a.com\"."
echo
exit 0
}
function display_license
{
echoY '**********************************************************************************************'
echoY '* Open LiteSpeed One click installation, Version 3.1 *'
echoY '* Copyright (C) 2016 - 2024 LiteSpeed Technologies, Inc. *'
echoY '**********************************************************************************************'
}
function check_os
{
if [ -f /etc/centos-release ] ; then
OSNAME=centos
USER='nobody'
GROUP='nobody'
case $(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f1) in
7)
OSNAMEVER=CENTOS7
OSVER=7
;;
8)
OSNAMEVER=CENTOS8
OSVER=8
;;
9)
OSNAMEVER=CENTOS9
OSVER=9
;;
esac
elif [ -f /etc/redhat-release ] ; then
OSNAME=centos
USER='nobody'
GROUP='nobody'
case $(cat /etc/redhat-release | tr -dc '0-9.'|cut -d \. -f1) in
7)
OSNAMEVER=CENTOS7
OSVER=7
;;
8)
OSNAMEVER=CENTOS8
OSVER=8
;;
9)
OSNAMEVER=CENTOS9
OSVER=9
;;
esac
elif [ -f /etc/lsb-release ] ; then
OSNAME=ubuntu
USER='nobody'
GROUP='nogroup'
case $(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2) in
bionic)
OSNAMEVER=UBUNTU18
OSVER=bionic
MARIADBCPUARCH="arch=amd64"
;;
focal)
OSNAMEVER=UBUNTU20
OSVER=focal
MARIADBCPUARCH="arch=amd64"
;;
jammy)
OSNAMEVER=UBUNTU22
OSVER=jammy
MARIADBCPUARCH="arch=amd64"
;;
noble)
OSNAMEVER=UBUNTU24
OSVER=noble
MARIADBCPUARCH="arch=amd64"
;;
esac
elif [ -f /etc/debian_version ] ; then
OSNAME=debian
USER='nobody'
GROUP='nogroup'
case $(cat /etc/os-release | grep VERSION_CODENAME | cut -d = -f 2) in
stretch)
OSNAMEVER=DEBIAN9
OSVER=stretch
MARIADBCPUARCH="arch=amd64,i386"
;;
buster)
OSNAMEVER=DEBIAN10
OSVER=buster
MARIADBCPUARCH="arch=amd64,i386"
;;
bullseye)
OSNAMEVER=DEBIAN11
OSVER=bullseye
MARIADBCPUARCH="arch=amd64,i386"
;;
bookworm)
OSNAMEVER=DEBIAN12
OSVER=bookworm
MARIADBCPUARCH="arch=amd64,i386"
;;
esac
fi
if [ "$OSNAMEVER" = '' ] ; then
echoR "Sorry, currently one click installation only supports Centos(7-9), Debian(10-12) and Ubuntu(18,20,22,24)."
echoR "You can download the source code and build from it."
echoR "The url of the source code is https://github.com/litespeedtech/openlitespeed/releases."
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
}
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))
}
function update_centos_hashlib
{
if [ "$OSNAME" = 'centos' ] ; then
silent ${YUM} -y install python-hashlib
fi
}
function get_memory
{
RAM_KB=$(grep "MemTotal" /proc/meminfo | awk '{print $2}')
}
function check_memory
{
if [ "${OSNAMEVER}" = 'CENTOS9' ]; then
get_memory
if [ "$RAM_KB" -lt "1800000" ]; then
echoR 'remi package needs at least 2GB RAM to install it. Exit!'
exit 1
fi
fi
}
function install_ols_centos
{
local action=install
if [ "$1" = "Update" ] ; then
action=update
elif [ "$1" = "Reinstall" ] ; then
action=reinstall
fi
local JSON=
if [ "x$LSPHPVER" = "x70" ] || [ "x$LSPHPVER" = "x71" ] || [ "x$LSPHPVER" = "x72" ] || [ "x$LSPHPVER" = "x73" ] || [ "x$LSPHPVER" = "x74" ]; then
JSON=lsphp$LSPHPVER-json
fi
if [ "${OSNAMEVER}" = 'CENTOS9' ]; then
echoB "${FPACE} - add remi repo"
else
echoB "${FPACE} - add epel repo"
silent ${YUM} -y $action epel-release
fi
echoB "${FPACE} - add litespeedtech repo"
sudo wget -q -O - https://repo.litespeed.sh | sudo bash >/dev/null 2>&1
echoB "${FPACE} - $1 OpenLiteSpeed"
silent ${YUM} -y $action openlitespeed
if [ ! -e $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp ] ; then
action=install
fi
echoB "${FPACE} - $1 lsphp$LSPHPVER"
if [ "$action" = "reinstall" ] ; then
silent ${YUM} -y remove lsphp$LSPHPVER-mysqlnd
fi
silent ${YUM} -y install lsphp$LSPHPVER-mysqlnd
if [[ "$LSPHPVER" == 8* ]]; then
silent ${YUM} -y $action lsphp$LSPHPVER lsphp$LSPHPVER-common lsphp$LSPHPVER-gd lsphp$LSPHPVER-process lsphp$LSPHPVER-mbstring \
lsphp$LSPHPVER-xml lsphp$LSPHPVER-pdo lsphp$LSPHPVER-imap
else
silent ${YUM} -y $action lsphp$LSPHPVER lsphp$LSPHPVER-common lsphp$LSPHPVER-gd lsphp$LSPHPVER-process lsphp$LSPHPVER-mbstring \
lsphp$LSPHPVER-xml lsphp$LSPHPVER-mcrypt lsphp$LSPHPVER-pdo lsphp$LSPHPVER-imap $JSON
fi
if [ $? != 0 ] ; then
echoR "An error occured during OpenLiteSpeed installation."
ALLERRORS=1
else
echoB "${FPACE} - Setup lsphp symlink"
ln -sf $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp $SERVER_ROOT/fcgi-bin/lsphpnew
sed -i -e "s/fcgi-bin\/lsphp/fcgi-bin\/lsphpnew/g" "${WEBCF}"
sed -i -e "s/lsphp${WEBADMIN_LSPHPVER}\/bin\/lsphp/lsphp$LSPHPVER\/bin\/lsphp/g" "${WEBCF}"
if [ ! -f /usr/bin/php ]; then
ln -s ${SERVER_ROOT}/lsphp${LSPHPVER}/bin/php /usr/bin/php
fi
fi
if [ ${INSTALLWORDPRESS} = 1 ]; then
silent ${YUM} -y $action lsphp$LSPHPVER-imagick lsphp$LSPHPVER-opcache lsphp$LSPHPVER-redis lsphp$LSPHPVER-memcached lsphp$LSPHPVER-intl
fi
}
function uninstall_ols_centos
{
echoB "${FPACE} - Remove OpenLiteSpeed"
silent ${YUM} -y remove openlitespeed
if [ $? != 0 ] ; then
echoR "An error occured while uninstalling OpenLiteSpeed."
ALLERRORS=1
fi
rm -rf $SERVER_ROOT/
}
function uninstall_php_centos
{
ls "${SERVER_ROOT}" | grep lsphp >/dev/null
if [ $? = 0 ] ; then
local LSPHPSTR="$(ls ${SERVER_ROOT} | grep -i lsphp | tr '\n' ' ')"
for LSPHPVER in ${LSPHPSTR}; do
echoB "${FPACE} - Detect LSPHP version $LSPHPVER"
if [ "$LSPHPVER" = "lsphp80" ]; then
silent ${YUM} -y remove lsphp$LSPHPVER lsphp$LSPHPVER-common lsphp$LSPHPVER-gd lsphp$LSPHPVER-process lsphp$LSPHPVER-mbstring \
lsphp$LSPHPVER-mysqlnd lsphp$LSPHPVER-xml lsphp$LSPHPVER-pdo lsphp$LSPHPVER-imap lsphp*
else
silent ${YUM} -y remove lsphp$LSPHPVER lsphp$LSPHPVER-common lsphp$LSPHPVER-gd lsphp$LSPHPVER-process lsphp$LSPHPVER-mbstring \
lsphp$LSPHPVER-mysqlnd lsphp$LSPHPVER-xml lsphp$LSPHPVER-mcrypt lsphp$LSPHPVER-pdo lsphp$LSPHPVER-imap $JSON lsphp*
fi
if [ $? != 0 ] ; then
echoR "An error occured while uninstalling lsphp$LSPHPVER"
ALLERRORS=1
fi
done
else
echoB "${FPACE} - Uinstall LSPHP"
${YUM} -y remove lsphp*
echoR "Uninstallation cannot get the currently installed LSPHP version."
echoY "May not uninstall LSPHP correctly."
LSPHPVER=
fi
}
function install_ols_debian
{
local action=
local INSTALL_STATUS=0
if [ "$1" = "Update" ] ; then
action="--only-upgrade"
elif [ "$1" = "Reinstall" ] ; then
action="--reinstall"
fi
echoB "${FPACE} - add litespeedtech repo"
sudo wget -q -O - https://repo.litespeed.sh | sudo bash >/dev/null 2>&1
echoB "${FPACE} - update list"
${APT} -y update
echoB "${FPACE} - $1 OpenLiteSpeed"
silent ${APT} -y install $action openlitespeed
if [ ${?} != 0 ] ; then
echoR "An error occured during OpenLiteSpeed installation."
ALLERRORS=1
INSTALL_STATUS=1
fi
if [ ! -e $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp ] ; then
action=
fi
echoB "${FPACE} - $1 lsphp$LSPHPVER"
silent ${APT} -y install $action lsphp$LSPHPVER lsphp$LSPHPVER-mysql lsphp$LSPHPVER-imap lsphp$LSPHPVER-curl
if [ "$LSPHPVER" = "56" ]; then
silent ${APT} -y install $action lsphp$LSPHPVER-gd lsphp$LSPHPVER-mcrypt
elif [[ "$LSPHPVER" == 8* ]]; then
silent ${APT} -y install $action lsphp$LSPHPVER-common
else
silent ${APT} -y install $action lsphp$LSPHPVER-common lsphp$LSPHPVER-json
fi
if [ $? != 0 ] ; then
echoR "An error occured during lsphp$LSPHPVER installation."
ALLERRORS=1
fi
if [ -e $SERVER_ROOT/bin/openlitespeed ]; then
echoB "${FPACE} - Setup lsphp symlink"
ln -sf $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp $SERVER_ROOT/fcgi-bin/lsphpnew
sed -i -e "s/fcgi-bin\/lsphp/fcgi-bin\/lsphpnew/g" "${WEBCF}"
sed -i -e "s/lsphp${WEBADMIN_LSPHPVER}\/bin\/lsphp/lsphp$LSPHPVER\/bin\/lsphp/g" "${WEBCF}"
if [ ! -f /usr/bin/php ]; then
ln -s ${SERVER_ROOT}/lsphp${LSPHPVER}/bin/php /usr/bin/php
fi
fi
if [ ${INSTALLWORDPRESS} = 1 ]; then
silent ${APT} -y install $action lsphp$LSPHPVER-imagick lsphp$LSPHPVER-opcache lsphp$LSPHPVER-redis lsphp$LSPHPVER-memcached lsphp$LSPHPVER-intl
fi
}
function uninstall_ols_debian
{
echoB "${FPACE} - Uninstall OpenLiteSpeed"
silent ${APT} -y purge openlitespeed
silent ${APT} -y remove openlitespeed
${APT} clean
#rm -rf $SERVER_ROOT/
}
function uninstall_php_debian
{
echoB "${FPACE} - Uninstall LSPHP"
silent ${APT} -y --purge remove lsphp*
if [ -e /usr/bin/php ] && [ -L /usr/bin/php ]; then
rm -f /usr/bin/php
fi
}
function action_uninstall
{
if [ "$ACTION" = "UNINSTALL" ] ; then
uninstall_warn
uninstall
uninstall_result
exit 0
fi
}
function action_purgeall
{
if [ "$ACTION" = "PURGEALL" ] ; then
uninstall_warn
if [ "$ROOTPASSWORD" = '' ] ; then
passwd=
echoY "Please input the MySQL root password: "
read passwd
ROOTPASSWORD=$passwd
fi
uninstall
purgedatabase
uninstall_result
exit 0
fi
}
function config_php
{
echoB "${FPACE} - Config php.ini"
if [ -f /etc/redhat-release ] ; then
PHPINICONF="${SERVER_ROOT}/lsphp${LSPHPVER}/etc/php.ini"
else
PHPMVER=$(php -v | head -n 1 | cut -d " " -f 2 | cut -f1-2 -d".")
PHPINICONF="${SERVER_ROOT}/lsphp${LSPHPVER}/etc/php/${PHPMVER}/litespeed/php.ini"
fi
if [ -e "${PHPINICONF}" ]; then
sed -i 's|memory_limit = 128M|memory_limit = 256M|g' ${PHPINICONF}
sed -i 's|max_execution_time = 30|max_execution_time = 120|g' ${PHPINICONF}
sed -i 's|max_input_time = 60|max_input_time = 240|g' ${PHPINICONF}
sed -i 's|post_max_size = 8M|post_max_size = 256M|g' ${PHPINICONF}
sed -i 's|upload_max_filesize = 2M|upload_max_filesize = 256M|g' ${PHPINICONF}
else
echoY "${PHPINICONF} does not exist, skip!"
fi
}
function disable_needrestart
{
if [ -d /etc/needrestart/conf.d ]; then
echoG 'List Restart services only'
cat >> /etc/needrestart/conf.d/disable.conf <<END
# Restart services (l)ist only, (i)nteractive or (a)utomatically.
\$nrconf{restart} = 'l';
# Disable hints on pending kernel upgrades.
\$nrconf{kernelhints} = 0;
END
fi
}
function download_wordpress
{
echoG 'Start Download WordPress file'
if [ ! -e "$WORDPRESSPATH" ] ; then
local WPDIRNAME=$(dirname $WORDPRESSPATH)
local WPBASENAME=$(basename $WORDPRESSPATH)
mkdir -p "$WORDPRESSPATH";
cd "$WORDPRESSPATH"
else
echoG "$WORDPRESSPATH exists, will use it."
fi
if [ "${WORDPRESSINSTALLED}" = '0' ];then
wp core download \
--locale=$WPLANGUAGE \
--path=$WORDPRESSPATH \
--allow-root \
--quiet
fi
echoG 'End Download WordPress file'
}
function create_wordpress_cf
{
echoG 'Start Create Wordpress config'
cd "$WORDPRESSPATH"
wp config create \
--dbname=$DATABASENAME \
--dbuser=$USERNAME \
--dbpass=$USERPASSWORD \
--dbprefix=$DBPREFIX \
--locale=ro_RO \
--allow-root \
--quiet
echoG 'Done Create Wordpress config'
}
function install_wordpress_core
{
echoG 'Start Setting Core Wordpress'
cd "$WORDPRESSPATH"
wp core install \
--url=$SITEDOMAIN \
--title=$WPTITLE \
--admin_user=$WPUSER \
--admin_password=$WPPASSWORD \
--admin_email=$EMAIL \
--skip-email \
--allow-root
echoG 'Install wordpress Cache plugin'
wp plugin install litespeed-cache \
--allow-root \
--activate \
--quiet
echoG 'End Setting Core Wordpress'
}
function random_password
{
if [ ! -z ${1} ]; then
TEMPPASSWORD="${1}"
else
TEMPPASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 ; echo '')
fi
}
function random_strong_password
{
if [ ! -z ${1} ]; then
TEMPPASSWORD="${1}"
else
TEMPPASSWORD=$(openssl rand -base64 32)
fi
}
function main_gen_password
{
random_password "${ADMINPASSWORD}"
ADMINPASSWORD="${TEMPPASSWORD}"
random_strong_password "${ROOTPASSWORD}"
ROOTPASSWORD="${TEMPPASSWORD}"
random_strong_password "${USERPASSWORD}"
USERPASSWORD="${TEMPPASSWORD}"
random_password "${WPPASSWORD}"
WPPASSWORD="${TEMPPASSWORD}"
read_password "$ADMINPASSWORD" "webAdmin password"
ADMINPASSWORD=$TEMPPASSWORD
if [ "$INSTALLWORDPRESS" = "1" ] ; then
read_password "$ROOTPASSWORD" "MySQL root password"
ROOTPASSWORD=$TEMPPASSWORD
read_password "$USERPASSWORD" "MySQL user password"
USERPASSWORD=$TEMPPASSWORD
fi
if [ "$INSTALLWORDPRESSPLUS" = "1" ] ; then
read_password "$WPPASSWORD" "WordPress admin password"
WPPASSWORD=$TEMPPASSWORD
fi
}
function main_ols_password
{
echo "WebAdmin username is [admin], password is [$ADMINPASSWORD]." >> ${PWD_FILE}
set_ols_password
}
function test_mysql_password
{
CURROOTPASSWORD=$ROOTPASSWORD
TESTPASSWORDERROR=0
mysqladmin -uroot -p$CURROOTPASSWORD password $CURROOTPASSWORD
if [ $? != 0 ] ; then
#Sometimes, mysql will treat the password error and restart will fix it.
service mysql restart
if [ $? != 0 ] && [ "$OSNAME" = "centos" ] ; then
service mysqld restart
fi
mysqladmin -uroot -p$CURROOTPASSWORD password $CURROOTPASSWORD
if [ $? != 0 ] ; then
printf '\033[31mPlease input the current root password:\033[0m'
read answer
mysqladmin -uroot -p$answer password $answer
if [ $? = 0 ] ; then
CURROOTPASSWORD=$answer
else
echoR "root password is incorrect. 2 attempts remaining."
printf '\033[31mPlease input the current root password:\033[0m'
read answer
mysqladmin -uroot -p$answer password $answer
if [ $? = 0 ] ; then
CURROOTPASSWORD=$answer
else
echoR "root password is incorrect. 1 attempt remaining."
printf '\033[31mPlease input the current root password:\033[0m'
read answer
mysqladmin -uroot -p$answer password $answer
if [ $? = 0 ] ; then
CURROOTPASSWORD=$answer
else
echoR "root password is incorrect. 0 attempts remaining."
echo
TESTPASSWORDERROR=1
fi
fi
fi
fi
fi
export TESTPASSWORDERROR=$TESTPASSWORDERROR
if [ "x$TESTPASSWORDERROR" = "x1" ] ; then
export CURROOTPASSWORD=
else
export CURROOTPASSWORD=$CURROOTPASSWORD
fi
}
function centos_install_mariadb
{
echoB "${FPACE} - Add MariaDB repo"
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-$MARIADBVER" >/dev/null 2>&1
# local REPOFILE=/etc/yum.repos.d/MariaDB.repo
# if [ ! -f $REPOFILE ] ; then
# local CENTOSVER=
# 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 >> $REPOFILE <<END
#[mariadb]
#name = MariaDB
#baseurl = https://downloads.mariadb.com/MariaDB/mariadb-$MARIADBVER/yum/rhel/\$releasever/\$basearch
#gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
#gpgcheck=1
#enabled = 1
#module_hotfixes = 1
#END
# else
# cat >> $REPOFILE <<END
#[mariadb]
#name = MariaDB
#baseurl = http://yum.mariadb.org/$MARIADBVER/$CENTOSVER
#gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
#gpgcheck=1
#END
# fi
# fi
echoB "${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
echoB "${FPACE} - Start MariaDB"
if [ "$OSNAMEVER" = "CENTOS9" ] || [ "$OSNAMEVER" = "CENTOS8" ] || [ "$OSNAMEVER" = "CENTOS7" ] ; then
silent systemctl enable mariadb
silent systemctl start mariadb
else
service mysql start
fi
}
function centos_install_mysql
{
echoB "${FPACE} - Add MySQL repo"
if [ "${OSVER}" = '9' ]; then
silent ${YUM} install -y https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
elif [ "${OSVER}" = '8' ]; then
silent ${YUM} install -y https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm
elif [ "${OSVER}" = '7' ]; then
silent ${YUM} install -y https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
else
echoR 'No repo found, exit!'; exit 1
fi
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 >/dev/null
yum-config-manager --disable mysql57-community >/dev/null
yum-config-manager --enable mysql80-community >/dev/null
if yum search 'mysql-community-server' | grep 'mysql-community-server\.' >/dev/null 2>&1; then
silent ${YUM} install -y mysql-community-server
else
silent ${YUM} install -y mysql-server
fi
service mysqld start 2>/dev/null
}
function centos_install_percona
{
echoB "${FPACE} - Add Percona repo"
silent ${YUM} install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm
echoB "${FPACE} - Enable Percona repo"
percona-release setup ps${PERCONAVER} -y >/dev/null 2>&1
silent ${YUM} install -y percona-server-server
service mysqld start 2>/dev/null
}
function centos_install_unzip
{
if [ ! -f /usr/bin/unzip ]; then
echoB "${FPACE} - Install Unzip"
yum update >/dev/null 2>&1
yum install unzip -y >/dev/null 2>&1
fi
}
function debian_install_mariadb
{
echoB "${FPACE} - Install software properties"
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
echoB "${FPACE} - Add MariaDB repo"
if [ "${OSNAMEVER}" = 'UBUNTU24' ]; then
#https://forum.hestiacp.com/t/mariadb-repos-failing/13097
echoB "${FPACE} - Skip adding MariaDB repo"
else
echoB "${FPACE} - Add MariaDB repo"
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-$MARIADBVER" >/dev/null 2>&1
fi
#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/$MARIADBVER/$OSNAME $OSVER main" > /etc/apt/sources.list.d/mariadb.list
# fi
#else
# echo "deb [$MARIADBCPUARCH signed-by=${MARIADB_KEY}] http://mirror.mariadb.org/repo/$MARIADBVER/$OSNAME $OSVER main" > /etc/apt/sources.list.d/mariadb.list
#fi
echoB "${FPACE} - Update packages"
${APT} update
echoB "${FPACE} - Install MariaDB"
silent ${APT} -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
echoB "${FPACE} - Start MariaDB"
service mysql start
if [ ${?} != 0 ]; then
service mariadb start
fi
}
function debian_install_mysql
{
echoB "${FPACE} - Install software properties"
#local MYSQL_REPO='/etc/apt/sources.list.d/mysql.list'
silent ${APT} -y -f install software-properties-common
#apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3A79BD29 >/dev/null 2>&1
#apt-key list 2>&1 | grep MySQL >/dev/null
#if [ ${?} != 0 ]; then
# echoY 'Key add failed from keyserver.ubuntu.com, try pgp.mit.edu!'
# apt-key adv --keyserver pgp.mit.edu --recv-keys 3A79BD29
# apt-key list 2>&1 | grep MySQL >/dev/null
# if [ ${?} != 0 ]; then
# echoR 'Key add failed from pgp.mit.edu, please check the key issue, exit!'
# exit 1
# fi
#fi
#echoB "${FPACE} - Add mysql ${MYSQLVER} repo"
#if [ -e "${MYSQL_REPO}" ]; then
# grep -Fq "repo.mysql.com" "${MYSQL_REPO}" >/dev/null 2>&1
# if [ $? != 0 ] ; then
# echo "deb http://repo.mysql.com/apt/$OSNAME $OSVER mysql-${MYSQLVER}" > "${MYSQL_REPO}"
# fi
#else
# echo "deb http://repo.mysql.com/apt/$OSNAME $OSVER mysql-${MYSQLVER}" > "${MYSQL_REPO}"
#fi
#echoB "${FPACE} - Update packages"
#${APT} update
echoB "${FPACE} - Install Mysql"
#debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password ${ROOTPASSWORD}"
#debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password ${ROOTPASSWORD}"
DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server > /dev/null 2>&1
if [ $? != 0 ] ; then
echoR "An error occured during installation of MYSQL. Please fix this error and try again."
echoR "You may want to manually run the command 'apt-get -y -f --allow-unauthenticated install mysql-server' to check. Aborting installation!"
exit 1
fi
echoB "${FPACE} - Start Mysql"
service mysql start