forked from litespeedtech/ols1clk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathols1clk.sh
executable file
·1704 lines (1566 loc) · 54.7 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 - 2021 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: [email protected] (David Shue)
TEMPRANDSTR=
OSNAMEVER=UNKNOWN
OSNAME=
OSVER=
OSTYPE=$(uname -m)
MARIADBCPUARCH=
SERVER_ROOT=/usr/local/lsws
WEBCF="$SERVER_ROOT/conf/httpd_config.conf"
OLSINSTALLED=
MYSQLINSTALLED=
TESTGETERROR=no
DATABASENAME=olsdbname
USERNAME=olsdbuser
VERBOSE=0
PURE_DB=0
WORDPRESSPATH=$SERVER_ROOT/wordpress
WPPORT=80
SSLWPPORT=443
WORDPRESSINSTALLED=
INSTALLWORDPRESS=0
INSTALLWORDPRESSPLUS=0
FORCEYES=0
WPLANGUAGE=en_US
WPUSER=wpuser
WPTITLE=MySite
SITEDOMAIN=*
EMAIL=
ADMINPASSWORD=
ROOTPASSWORD=
USERPASSWORD=
WPPASSWORD=
LSPHPVERLIST=(56 70 71 72 73 74 80)
MARIADBVERLIST=(10.1 10.2 10.3 10.4 10.5)
LSPHPVER=74
MARIADBVER=10.4
WEBADMIN_LSPHPVER=73
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
INST_USER=$(id -u)
if [ "$INST_USER" != 0 ] ; then
echo "Sorry, only the root user can install."
echo
exit 1
fi
}
function update_system(){
echo 'System update'
if [ "$OSNAME" = "centos" ] ; then
silent "${YUM}" update >/dev/null 2>&1
else
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
echo "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
echo "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"
echo " -A, --adminpassword [PASSWORD]" "${EPACE}To set the WebAdmin password for OpenLiteSpeed instead of using a random one."
echo " -E, --email [EMAIL] " "${EPACE} To set the administrator email."
echo " --lsphp [VERSION] " "To set the LSPHP version, such as 80. We currently support versions '${LSPHPVERLIST[@]}'."
echo " --mariadbver [VERSION] " "To set MariaDB version, such as 10.5. We currently support versions '${MARIADBVERLIST[@]}'."
echo " -W, --wordpress " "${EPACE} To install WordPress. You will still need to complete the WordPress setup by browser"
echo " --wordpressplus [SITEDOMAIN] " "To install, setup, and configure WordPress, also LSCache will be enabled"
echo " --wordpresspath [WP_PATH] " "To specify a location for the new WordPress installation or an existing WordPress."
echo " -R, --dbrootpassword [PASSWORD] " " To set the database root password instead of using a random one."
echo " --dbname [DATABASENAME] " "To set the database name to be used by WordPress."
echo " --dbuser [DBUSERNAME] " "To set the WordPress username in the database."
echo " --dbpassword [PASSWORD] " "To set the WordPress table password in MySQL instead of using a random one."
echo " --listenport [PORT] " "To set the HTTP server listener port, default is 80."
echo " --ssllistenport [PORT] " "To set the HTTPS server listener port, default is 443."
echo " --wpuser [WORDPRESSUSER] " "To set the WordPress admin user for WordPress dashboard login. Default value is wpuser."
echo " --wppassword [PASSWORD] " "To set the WordPress admin user password for WordPress dashboard login."
echo " --wplang [WP_LANGUAGE] " "To set the WordPress language. Default value is \"en_US\" for English."
echo " --sitetitle [WP_TITLE] " "To set the WordPress site title. Default value is mySite."
echo " -U, --uninstall " "${EPACE} To uninstall OpenLiteSpeed and remove installation directory."
echo " -P, --purgeall " "${EPACE} To uninstall OpenLiteSpeed, remove installation directory, and purge all data in MySQL."
echo " -Q, --quiet " "${EPACE} To use quiet mode, won't prompt to input anything."
echo " -V, --version " "${EPACE} To display the script version information."
echo " -v, --verbose " "${EPACE} To display more messages during the installation."
echo " --update " "To update ols1clk from github."
echo " -H, --help " "${EPACE} To display help messages."
echo
echo -e "\033[1mEXAMPLES\033[0m"
echo "./ols1clk.sh " "To install OpenLiteSpeed with a random WebAdmin password."
echo "./ols1clk.sh --lsphp 80 " "To install OpenLiteSpeed with lsphp80."
echo "./ols1clk.sh -A 123456 -e [email protected] " "To install OpenLiteSpeed with WebAdmin password \"123456\" and email [email protected]."
echo "./ols1clk.sh -R 123456 -W " "To install OpenLiteSpeed with WordPress and MySQL root password \"123456\"."
echo "./ols1clk.sh --wordpressplus a.com " "To install OpenLiteSpeed with a fully configured WordPress installation at \"a.com\"."
echo
exit 0
}
function display_license
{
echo '**********************************************************************************************'
echo '* Open LiteSpeed One click installation, Version 3.0 *'
echo '* Copyright (C) 2016 - 2021 LiteSpeed Technologies, Inc. *'
echo '**********************************************************************************************'
}
function check_os
{
if [ -f /etc/redhat-release ] ; then
OSNAME=centos
USER='nobody'
GROUP='nobody'
case $(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f1) in
6)
OSNAMEVER=CENTOS6
OSVER=6
;;
7)
OSNAMEVER=CENTOS7
OSVER=7
;;
8)
OSNAMEVER=CENTOS8
OSVER=8
;;
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
trusty)
OSNAMEVER=UBUNTU14
OSVER=trusty
MARIADBCPUARCH="arch=amd64,i386,ppc64el"
;;
xenial)
OSNAMEVER=UBUNTU16
OSVER=xenial
MARIADBCPUARCH="arch=amd64,i386,ppc64el"
;;
bionic)
OSNAMEVER=UBUNTU18
OSVER=bionic
MARIADBCPUARCH="arch=amd64"
;;
focal)
OSNAMEVER=UBUNTU20
OSVER=focal
MARIADBCPUARCH="arch=amd64"
;;
esac
elif [ -f /etc/debian_version ] ; then
OSNAME=debian
case $(cat /etc/os-release | grep VERSION_CODENAME | cut -d = -f 2) in
wheezy)
OSNAMEVER=DEBIAN7
OSVER=wheezy
MARIADBCPUARCH="arch=amd64,i386"
;;
jessie)
OSNAMEVER=DEBIAN8
OSVER=jessie
MARIADBCPUARCH="arch=amd64,i386"
;;
stretch)
OSNAMEVER=DEBIAN9
OSVER=stretch
MARIADBCPUARCH="arch=amd64,i386"
;;
buster)
OSNAMEVER=DEBIAN10
OSVER=buster
MARIADBCPUARCH="arch=amd64,i386"
;;
esac
fi
if [ "$OSNAMEVER" = '' ] ; then
echo "Sorry, currently one click installation only supports Centos(6-8), Debian(7-10) and Ubuntu(14,16,18,20)."
echo "You can download the source code and build from it."
echo "The url of the source code is https://github.com/litespeedtech/openlitespeed/releases."
exit 1
else
if [ "$OSNAME" = "centos" ] ; then
echo "Current platform is " "$OSNAME $OSVER."
else
export DEBIAN_FRONTEND=noninteractive
echo "Current platform is " "$OSNAMEVER $OSNAME $OSVER."
fi
fi
}
function update_centos_hashlib
{
if [ "$OSNAME" = 'centos' ] ; then
silent ${YUM} -y install python-hashlib
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
echo "${FPACE} - add epel repo"
silent ${YUM} -y $action epel-release
echo "${FPACE} - add litespeedtech repo"
rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el$OSVER.noarch.rpm >/dev/null 2>&1
echo "${FPACE} - $1 OpenLiteSpeed"
silent ${YUM} -y $action openlitespeed
if [ ! -e $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp ] ; then
action=install
fi
echo "${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" = "80" ]; 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
echo "${FPACE} - Setup lsphp symlink"
if [ $? != 0 ] ; then
echo "An error occured during OpenLiteSpeed installation."
ALLERRORS=1
else
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}"
fi
}
function uninstall_ols_centos
{
echo "${FPACE} - Remove OpenLiteSpeed"
silent ${YUM} -y remove openlitespeed
if [ $? != 0 ] ; then
echo "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
echo "${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
echo "An error occured while uninstalling lsphp$LSPHPVER"
ALLERRORS=1
fi
done
else
echo "${FPACE} - Uinstall LSPHP"
${YUM} -y remove lsphp*
echo "Uninstallation cannot get the currently installed LSPHP version."
echo "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
echo "${FPACE} - add litespeedtech repo"
grep -Fq "http://rpms.litespeedtech.com/debian/" /etc/apt/sources.list.d/lst_debian_repo.list 2>/dev/null
if [ $? != 0 ] ; then
echo "deb http://rpms.litespeedtech.com/debian/ $OSVER main" > /etc/apt/sources.list.d/lst_debian_repo.list
fi
wget -qO /etc/apt/trusted.gpg.d/lst_debian_repo.gpg http://rpms.litespeedtech.com/debian/lst_debian_repo.gpg
wget -qO /etc/apt/trusted.gpg.d/lst_repo.gpg http://rpms.litespeedtech.com/debian/lst_repo.gpg
echo "${FPACE} - update list"
${APT} -y update
echo "${FPACE} - $1 OpenLiteSpeed"
silent ${APT} -y install $action openlitespeed
if [ ${?} != 0 ] ; then
echo "An error occured during OpenLiteSpeed installation."
ALLERRORS=1
INSTALL_STATUS=1
fi
if [ ! -e $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp ] ; then
action=
fi
echo "${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" = "80" ]; 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
echo "An error occured during lsphp$LSPHPVER installation."
ALLERRORS=1
fi
echo "${FPACE} - Setup lsphp symlink"
#if [ ${INSTALL_STATUS} = 0 ]; then
if [ -e $SERVER_ROOT/bin/openlitespeed ]; then
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}"
fi
}
function uninstall_ols_debian
{
echo "${FPACE} - Uninstall OpenLiteSpeed"
silent ${APT} -y purge openlitespeed
silent ${APT} -y remove openlitespeed
${APT} clean
#rm -rf $SERVER_ROOT/
}
function uninstall_php_debian
{
echo "${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=
echo "Please input the MySQL root password: "
read passwd
ROOTPASSWORD=$passwd
fi
uninstall
purgedatabase
uninstall_result
exit 0
fi
}
function download_wordpress
{
echo 'Start Download WordPress file'
if [ ! -e "$WORDPRESSPATH" ] ; then
local WPDIRNAME=$(dirname $WORDPRESSPATH)
local WPBASENAME=$(basename $WORDPRESSPATH)
mkdir -p "$WORDPRESSPATH";
cd "$WORDPRESSPATH"
else
echo "$WORDPRESSPATH exists, will use it."
fi
if [ "${WORDPRESSINSTALLED}" = '0' ];then
wp core download \
--locale=$WPLANGUAGE \
--path=$WORDPRESSPATH \
--allow-root \
--quiet
fi
echo 'End Download WordPress file'
}
function create_wordpress_cf
{
echo 'Start Create Wordpress config'
cd "$WORDPRESSPATH"
wp config create \
--dbname=$DATABASENAME \
--dbuser=$USERNAME \
--dbpass=$USERPASSWORD \
--locale=ro_RO \
--allow-root \
--quiet
echo 'Done Create Wordpress config'
}
function install_wordpress_core
{
echo '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
echo 'Install wordpress Cache plugin'
wp plugin install litespeed-cache \
--allow-root \
--activate \
--quiet
echo '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 main_gen_password
{
random_password "${ADMINPASSWORD}"
ADMINPASSWORD="${TEMPPASSWORD}"
random_password "${ROOTPASSWORD}"
ROOTPASSWORD="${TEMPPASSWORD}"
random_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_set_password
{
echo "WebAdmin username is [admin], password is [$ADMINPASSWORD]." > $SERVER_ROOT/password
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
echo "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
echo "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
echo "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_mysql
{
echo "${FPACE} - Add MariaDB repo"
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" ] ; 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
echo "${FPACE} - Install MariaDB"
if [ "$OSNAMEVER" = "CENTOS8" ] ; 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
echo "An error occured during installation of MariaDB. Please fix this error and try again."
echo "You may want to manually run the command '${YUM} -y install MariaDB-server MariaDB-client' to check. Aborting installation!"
exit 1
fi
echo "${FPACE} - Start MariaDB"
if [ "$OSNAMEVER" = "CENTOS8" ] || [ "$OSNAMEVER" = "CENTOS7" ] ; then
silent systemctl enable mariadb
silent systemctl start mariadb
else
service mysql start
fi
}
function debian_install_mysql
{
echo "${FPACE} - Install software properties"
if [ "$OSNAMEVER" = "DEBIAN7" ] ; then
silent ${APT} -y -f install python-software-properties
silent apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
elif [ "$OSNAMEVER" = "DEBIAN8" ] ; then
silent ${APT} -y -f install software-properties-common
silent apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
elif [ "$OSNAMEVER" = "DEBIAN9" ] ; then
silent ${APT} -y -f install software-properties-common gnupg
silent apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
elif [ "$OSNAMEVER" = "DEBIAN10" ] ; then
silent ${APT} -y -f install software-properties-common gnupg
silent apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
elif [ "$OSNAMEVER" = "UBUNTU14" ] ; then
silent ${APT} -y -f install software-properties-common
silent apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
elif [ "$OSNAMEVER" = "UBUNTU16" ] ; then
silent ${APT} -y -f install software-properties-common
silent apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
elif [ "$OSNAMEVER" = "UBUNTU18" ] ; then
silent ${APT} -y -f install software-properties-common
silent apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
elif [ "$OSNAMEVER" = "UBUNTU20" ] ; then
silent ${APT} -y -f install software-properties-common
silent apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
fi
echo "${FPACE} - Add MariaDB repo"
if [ -e /etc/apt/sources.list.d/mariadb_repo.list ]; then
grep -Fq "http://mirror.jaleco.com/mariadb/repo/" /etc/apt/sources.list.d/mariadb_repo.list >/dev/null 2>&1
if [ $? != 0 ] ; then
echo "deb [$MARIADBCPUARCH] http://mirror.jaleco.com/mariadb/repo/$MARIADBVER/$OSNAME $OSVER main" > /etc/apt/sources.list.d/mariadb_repo.list
fi
else
echo "deb [$MARIADBCPUARCH] http://mirror.jaleco.com/mariadb/repo/$MARIADBVER/$OSNAME $OSVER main" > /etc/apt/sources.list.d/mariadb_repo.list
fi
echo "${FPACE} - Update packages"
${APT} update
echo "${FPACE} - Install MariaDB"
silent ${APT} -y -f install mariadb-server
if [ $? != 0 ] ; then
echo "An error occured during installation of MariaDB. Please fix this error and try again."
echo "You may want to manually run the command 'apt-get -y -f --allow-unauthenticated install mariadb-server' to check. Aborting installation!"
exit 1
fi
echo "${FPACE} - Start MariaDB"
service mysql start
}
function install_mysql
{
echo "Start Install MariaDB"
if [ "$OSNAME" = 'centos' ] ; then
centos_install_mysql
else
debian_install_mysql
fi
if [ $? != 0 ] ; then
echo "An error occured when starting the MariaDB service. "
echo "Please fix this error and try again. Aborting installation!"
exit 1
fi
echo "${FPACE} - Set MariaDB root"
mysql -uroot -e "flush privileges;"
mysqladmin -uroot password $ROOTPASSWORD
if [ $? = 0 ] ; then
CURROOTPASSWORD=$ROOTPASSWORD
else
#test it is the current password
mysqladmin -uroot -p$ROOTPASSWORD password $ROOTPASSWORD
if [ $? = 0 ] ; then
#echo "MySQL root password is $ROOTPASSWORD"
CURROOTPASSWORD=$ROOTPASSWORD
else
echo "Failed to set MySQL root password to $ROOTPASSWORD, it may already have a root password."
printf '\033[31mInstallation must know the password for the next step.\033[0m'
test_mysql_password
if [ "$TESTPASSWORDERROR" = "1" ] ; then
echo "If you forget your password you may stop the mysqld service and run the following command to reset it,"
echo "mysqld_safe --skip-grant-tables &"
echo "mysql --user=root mysql"
echo "update user set Password=PASSWORD('new-password') where user='root'; flush privileges; exit; "
echo "Aborting installation."
echo
exit 1
fi
if [ "$CURROOTPASSWORD" != "$ROOTPASSWORD" ] ; then
echo "Current MySQL root password is $CURROOTPASSWORD, it will be changed to $ROOTPASSWORD."
printf '\033[31mDo you still want to change it?[y/N]\033[0m '
read answer
echo
if [ "$answer" != "Y" ] && [ "$answer" != "y" ] ; then
echo "OK, MySQL root password not changed."
ROOTPASSWORD=$CURROOTPASSWORD
else
mysqladmin -uroot -p$CURROOTPASSWORD password $ROOTPASSWORD
if [ $? = 0 ] ; then
echo "OK, MySQL root password changed to $ROOTPASSWORD."
else
echo "Failed to change MySQL root password, it is still $CURROOTPASSWORD."
ROOTPASSWORD=$CURROOTPASSWORD
fi
fi
fi
fi
fi
echo "End Install MariaDB"
}
function setup_mysql
{
echo "Start setup mysql"
local ERROR=
#delete user if exists
mysql -uroot -p$ROOTPASSWORD -e "DELETE FROM mysql.user WHERE User = '$USERNAME@localhost';"
echo `mysql -uroot -p$ROOTPASSWORD -e "SELECT user FROM mysql.user"` | grep "$USERNAME" >/dev/null
if [ $? = 0 ] ; then
echo "user $USERNAME exists in mysql.user"
else
mysql -uroot -p$ROOTPASSWORD -e "CREATE USER $USERNAME@localhost IDENTIFIED BY '$USERPASSWORD';"
if [ $? = 0 ] ; then
mysql -uroot -p$ROOTPASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO '$USERNAME'@localhost IDENTIFIED BY '$USERPASSWORD';"
else
echo "Failed to create MySQL user $USERNAME. This user may already exist. If it does not, another problem occured."
echo "Please check this and update the wp-config.php file."
ERROR="Create user error"
fi
fi
mysql -uroot -p$ROOTPASSWORD -e "CREATE DATABASE IF NOT EXISTS $DATABASENAME;"
if [ $? = 0 ] ; then
mysql -uroot -p$ROOTPASSWORD -e "GRANT ALL PRIVILEGES ON $DATABASENAME.* TO '$USERNAME'@localhost IDENTIFIED BY '$USERPASSWORD';"
else
echo "Failed to create database $DATABASENAME. It may already exist. If it does not, another problem occured."
echo "Please check this and update the wp-config.php file."
if [ "x$ERROR" = "x" ] ; then
ERROR="Create database error"
else
ERROR="$ERROR and create database error"
fi
fi
mysql -uroot -p$ROOTPASSWORD -e "flush privileges;"
if [ "x$ERROR" = "x" ] ; then
echo "Finished MySQL setup without error."
else
echo "Finished MySQL setup - some error(s) occured."
fi
echo "End setup mysql"
}
function resetmysqlroot
{
if [ "x$OSNAMEVER" = "xCENTOS8" ]; then
MYSQLNAME='mariadb'
else
MYSQLNAME=mysql
fi
service $MYSQLNAME stop
if [ $? != 0 ] && [ "x$OSNAME" = "xcentos" ] ; then
service $MYSQLNAME stop
fi
DEFAULTPASSWD=$1
echo "update user set Password=PASSWORD('$DEFAULTPASSWD') where user='root'; flush privileges; exit; " > /tmp/resetmysqlroot.sql
mysqld_safe --skip-grant-tables &
#mysql --user=root mysql < /tmp/resetmysqlroot.sql
mysql --user=root mysql -e "update user set Password=PASSWORD('$DEFAULTPASSWD') where user='root'; flush privileges; exit; "
sleep 1
service $MYSQLNAME restart
}
function purgedatabase
{
if [ "$MYSQLINSTALLED" != "1" ] ; then
echo "MySQL-server not installed."
else
local ERROR=0
test_mysql_password
if [ "$TESTPASSWORDERROR" = "1" ] ; then
echo "Failed to purge database."
echo
ERROR=1
ALLERRORS=1
else
ROOTPASSWORD=$CURROOTPASSWORD
fi
if [ "$ERROR" = "0" ] ; then
mysql -uroot -p$ROOTPASSWORD -e "DELETE FROM mysql.user WHERE User = '$USERNAME@localhost';"
mysql -uroot -p$ROOTPASSWORD -e "DROP DATABASE IF EXISTS $DATABASENAME;"
echo "Database purged."
fi
fi
}
function pure_mariadb
{
if [ "$MYSQLINSTALLED" = "0" ] ; then
install_mysql
ROOTPASSWORD=$CURROOTPASSWORD
setup_mysql
else
echo 'MariaDB already exist, skip!'
fi
}
function uninstall_result
{
if [ "$ALLERRORS" != "0" ] ; then
echo "Some error(s) occured. Please check these as you may need to manually fix them."
fi
echo 'End OpenLiteSpeed one click Uninstallation << << << << << << <<'
}
function install_openlitespeed
{
echo "Start setup OpenLiteSpeed"
local STATUS=Install
if [ "$OLSINSTALLED" = "1" ] ; then
OLS_VERSION=$(cat "$SERVER_ROOT"/VERSION)
wget -qO "$SERVER_ROOT"/release.tmp http://open.litespeedtech.com/packages/release?ver=$OLS_VERSION
LATEST_VERSION=$(cat "$SERVER_ROOT"/release.tmp)
rm "$SERVER_ROOT"/release.tmp
if [ "$OLS_VERSION" = "$LATEST_VERSION" ] ; then
STATUS=Reinstall
echo "OpenLiteSpeed is already installed with the latest version, will attempt to reinstall it."
else
STATUS=Update
echo "OpenLiteSpeed is already installed and newer version is available, will attempt to update it."
fi
fi
if [ "$OSNAME" = "centos" ] ; then
install_ols_centos $STATUS
else
install_ols_debian $STATUS
fi
silent killall -9 lsphp
echo "End setup OpenLiteSpeed"
}
function gen_selfsigned_cert
{
if [ -e $CONFFILE ] ; then
source $CONFFILE 2>/dev/null
if [ $? != 0 ]; then
. $CONFFILE
fi
fi
SSL_COUNTRY="${SSL_COUNTRY:-US}"
SSL_STATE="${SSL_STATE:-New Jersey}"
SSL_LOCALITY="${SSL_LOCALITY:-Virtual}"
SSL_ORG="${SSL_ORG:-LiteSpeedCommunity}"
SSL_ORGUNIT="${SSL_ORGUNIT:-Testing}"
SSL_HOSTNAME="${SSL_HOSTNAME:-webadmin}"