forked from litespeedtech/ols1clk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ols1clk.sh
executable file
·1382 lines (1164 loc) · 46.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 - 2016 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: dxu@litespeedtech.com (David Shue)
TEMPRANDSTR=
function getRandPassword
{
dd if=/dev/urandom bs=8 count=1 of=/tmp/randpasswdtmpfile >/dev/null 2>&1
TEMPRANDSTR=`cat /tmp/randpasswdtmpfile`
rm /tmp/randpasswdtmpfile
local DATE=`date`
TEMPRANDSTR=`echo "$TEMPRANDSTR$RANDOM$DATE" | md5sum | base64 | head -c 8`
}
OSNAMEVER=UNKNOWN
OSNAME=
OSVER=
OSTYPE=`uname -m`
MARIADBCPUARCH=
SERVER_ROOT=/usr/local/lsws
#Current status
OLSINSTALLED=
MYSQLINSTALLED=
getRandPassword
ADMINPASSWORD=$TEMPRANDSTR
getRandPassword
ROOTPASSWORD=$TEMPRANDSTR
getRandPassword
USERPASSWORD=$TEMPRANDSTR
getRandPassword
WPPASSWORD=$TEMPRANDSTR
DATABASENAME=olsdbname
USERNAME=olsdbuser
WORDPRESSPATH=$SERVER_ROOT/wordpress
WPPORT=80
INSTALLWORDPRESS=0
INSTALLWORDPRESSPLUS=0
FORCEYES=0
WPLANGUAGE=en
WPUSER=wpuser
WPTITLE=MySite
SITEDOMAIN=*
EMAIL=
#All lsphp versions, keep using two digits to identify a version!!!
#otherwise, need to update the uninstall function which will check the version
LSPHPVERLIST=(54 55 56 70 71)
#default version
LSPHPVER=56
USEDEFAULTLSPHP=1
ALLERRORS=0
TEMPPASSWORD=
ACTION=INSTALL
FOLLOWPARAM=
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 echoR
{
FLAG=$1
shift
echo -e "\033[38;5;203m$FLAG\033[39m$@"
}
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 check_wget
{
which wget >/dev/null 2>&1
if [ $? != 0 ] ; then
if [ "x$OSNAME" = "xcentos" ] ; then
yum -y install wget
else
apt-get -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 display_license
{
echoY '**********************************************************************************************'
echoY '* Open LiteSpeed One click installation, Version 1.6 *'
echoY '* Copyright (C) 2016 LiteSpeed Technologies, Inc. *'
echoY '**********************************************************************************************'
}
function check_os
{
OSNAMEVER=
OSNAME=
OSVER=
MARIADBCPUARCH=
if [ -f /etc/redhat-release ] ; then
cat /etc/redhat-release | grep " 5." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=CENTOS5
OSNAME=centos
OSVER=5
else
cat /etc/redhat-release | grep " 6." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=CENTOS6
OSNAME=centos
OSVER=6
else
cat /etc/redhat-release | grep " 7." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=CENTOS7
OSNAME=centos
OSVER=7
fi
fi
fi
elif [ -f /etc/lsb-release ] ; then
cat /etc/lsb-release | grep "DISTRIB_RELEASE=12." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=UBUNTU12
OSNAME=ubuntu
OSVER=precise
MARIADBCPUARCH="arch=amd64,i386"
else
cat /etc/lsb-release | grep "DISTRIB_RELEASE=14." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=UBUNTU14
OSNAME=ubuntu
OSVER=trusty
MARIADBCPUARCH="arch=amd64,i386,ppc64el"
else
cat /etc/lsb-release | grep "DISTRIB_RELEASE=16." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=UBUNTU16
OSNAME=ubuntu
OSVER=xenial
MARIADBCPUARCH="arch=amd64,i386,ppc64el"
fi
fi
fi
elif [ -f /etc/debian_version ] ; then
cat /etc/debian_version | grep "^7." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=DEBIAN7
OSNAME=debian
OSVER=wheezy
MARIADBCPUARCH="arch=amd64,i386"
else
cat /etc/debian_version | grep "^8." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=DEBIAN8
OSNAME=debian
OSVER=jessie
MARIADBCPUARCH="arch=amd64,i386"
else
cat /etc/debian_version | grep "^9." >/dev/null
if [ $? = 0 ] ; then
OSNAMEVER=DEBIAN9
OSNAME=debian
OSVER=stretch
MARIADBCPUARCH="arch=amd64,i386"
fi
fi
fi
fi
if [ "x$OSNAMEVER" = "x" ] ; then
echoR "Sorry, currently one click installation only supports Centos(5-7), Debian(7-9) and Ubuntu(12,14,16)."
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."
echo
exit 1
else
if [ "x$OSNAME" = "xcentos" ] ; then
echoG "Current platform is " "$OSNAME $OSVER."
else
export DEBIAN_FRONTEND=noninteractive
echoG "Current platform is " "$OSNAMEVER $OSNAME $OSVER."
fi
fi
}
function update_centos_hashlib
{
if [ "x$OSNAME" = "xcentos" ] ; then
yum -y install python-hashlib
fi
}
function install_ols_centos
{
local action=install
if [ "x$1" = "xUpdate" ] ; then
action=update
elif [ "x$1" = "xReinstall" ] ; then
action=reinstall
fi
local ND=
if [ "x$LSPHPVER" = "x70" ] || [ "x$LSPHPVER" = "x71" ] ; then
ND=nd
if [ "x$OSVER" = "x5" ] ; then
rpm -Uvh http://repo.mysql.com/mysql-community-release-el5.rpm
fi
fi
yum -y $action epel-release
rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el$OSVER.noarch.rpm
yum -y $action openlitespeed
if [ ! -e $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp ] ; then
action=install
fi
#special case for lsphp56
if [ "x$action" = "xreinstall" ] && [ "x$LSPHPVER" = "x56" ] ; then
yum -y remove lsphp56-mysql
yum -y install lsphp56-mysql
fi
yum -y $action lsphp$LSPHPVER lsphp$LSPHPVER-common lsphp$LSPHPVER-gd lsphp$LSPHPVER-process lsphp$LSPHPVER-mbstring lsphp$LSPHPVER-mysql$ND lsphp$LSPHPVER-xml lsphp$LSPHPVER-mcrypt lsphp$LSPHPVER-pdo lsphp$LSPHPVER-imap
if [ $? != 0 ] ; then
echoR "An error occured during openlitespeed installation."
ALLERRORS=1
else
ln -sf $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp $SERVER_ROOT/fcgi-bin/lsphp5
fi
}
function uninstall_ols_centos
{
yum -y remove openlitespeed
if [ $? != 0 ] ; then
echoR "An error occured while uninstalling openlitespeed."
ALLERRORS=1
fi
#Need to find what is current lsphp version
yum list installed | grep lsphp | grep process >/dev/null 2>&1
if [ $? = 0 ] ; then
local LSPHPSTR=`yum list installed | grep lsphp | grep process`
LSPHPVER=`echo $LSPHPSTR | awk '{print substr($0,6,2)}'`
echoY "The installed version of lsphp is $LSPHPVER"
local ND=
if [ "x$LSPHPVER" = "x70" ] || [ "x$LSPHPVER" = "x71" ] ; then
ND=nd
fi
yum -y remove lsphp$LSPHPVER lsphp$LSPHPVER-common lsphp$LSPHPVER-gd lsphp$LSPHPVER-process lsphp$LSPHPVER-mbstring lsphp$LSPHPVER-mysql$ND lsphp$LSPHPVER-xml lsphp$LSPHPVER-mcrypt lsphp$LSPHPVER-pdo lsphp$LSPHPVER-imap lsphp*
if [ $? != 0 ] ; then
echoR "An error occured while uninstalling lsphp$LSPHPVER"
ALLERRORS=1
fi
else
yum -y remove lsphp*
echoR "Uninstallation cannot get the version of the currently installed lsphp."
echoY "May not uninstall lsphp correctly."
LSPHPVER=
fi
rm -rf $SERVER_ROOT/
}
function install_ols_debian
{
local action=
if [ "x$1" = "xUpdate" ] ; then
action="--only-upgrade"
elif [ "x$1" = "xReinstall" ] ; then
action="--reinstall"
fi
grep -Fq "http://rpms.litespeedtech.com/debian/" /etc/apt/sources.list.d/lst_debian_repo.list
if [ $? != 0 ] ; then
echo "deb http://rpms.litespeedtech.com/debian/ $OSVER main" > /etc/apt/sources.list.d/lst_debian_repo.list
fi
wget -O /etc/apt/trusted.gpg.d/lst_debian_repo.gpg http://rpms.litespeedtech.com/debian/lst_debian_repo.gpg
wget -O /etc/apt/trusted.gpg.d/lst_repo.gpg http://rpms.litespeedtech.com/debian/lst_repo.gpg
apt-get -y update
apt-get -y install $action openlitespeed
if [ ! -e $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp ] ; then
action=
fi
apt-get -y install $action lsphp$LSPHPVER lsphp$LSPHPVER-mysql lsphp$LSPHPVER-imap
if [ "x$LSPHPVER" != "x70" ] && [ "x$LSPHPVER" != "x71" ] ; then
apt-get -y install $action lsphp$LSPHPVER-gd lsphp$LSPHPVER-mcrypt
else
apt-get -y install $action lsphp$LSPHPVER-common
fi
if [ $? != 0 ] ; then
echoR "An error occured during openlitespeed installation."
ALLERRORS=1
else
ln -sf $SERVER_ROOT/lsphp$LSPHPVER/bin/lsphp $SERVER_ROOT/fcgi-bin/lsphp5
fi
}
function uninstall_ols_debian
{
apt-get -y --purge remove openlitespeed
dpkg -l | grep lsphp | grep mysql >/dev/null 2>&1
if [ $? = 0 ] ; then
local LSPHPSTR=`dpkg -l | grep lsphp | grep mysql`
LSPHPVER=`echo $LSPHPSTR | awk '{print substr($2,6,2)}'`
echoY "The installed version of lsphp is $LSPHPVER"
if [ "x$LSPHPVER" != "x70" ] && [ "x$LSPHPVER" != "x71" ] ; then
apt-get -y --purge remove lsphp$LSPHPVER-gd lsphp$LSPHPVER-mcrypt
else
apt-get -y --purge remove lsphp$LSPHPVER-common
fi
apt-get -y --purge remove lsphp$LSPHPVER lsphp$LSPHPVER-mysql lsphp$LSPHPVER-imap 'lsphp*'
if [ $? != 0 ] ; then
echoR "An error occured while uninstalling openlitespeed/lsphp."
ALLERRORS=1
fi
else
apt-get -y --purge remove lsphp*
echoR "Uninstallation cannot get the version of the currently installed lsphp."
echoR "May not uninstall lsphp correctly."
LSPHPVER=
fi
rm -rf $SERVER_ROOT/
}
function install_wordpress
{
if [ ! -e "$WORDPRESSPATH" ] ; then
local WPDIRNAME=`dirname $WORDPRESSPATH`
local WPBASENAME=`basename $WORDPRESSPATH`
mkdir -p "$WPDIRNAME"
cd "$WPDIRNAME"
wget --no-check-certificate http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz >/dev/null 2>&1
rm latest.tar.gz
if [ "x$WPBASENAME" != "xwordpress" ] ; then
mv wordpress/ $WPBASENAME/
fi
wget -q -r -nH --cut-dirs=2 --no-parent https://plugins.svn.wordpress.org/litespeed-cache/trunk/ --reject html -P $WORDPRESSPATH/wp-content/plugins/litespeed-cache/
chown -R --reference=$SERVER_ROOT/autoupdate $WORDPRESSPATH
cd -
else
echoY "$WORDPRESSPATH exists, will use it."
fi
}
function setup_wordpress
{
if [ -e "$WORDPRESSPATH/wp-config-sample.php" ] ; then
sed -e "s/database_name_here/$DATABASENAME/" -e "s/username_here/$USERNAME/" -e "s/password_here/$USERPASSWORD/" "$WORDPRESSPATH/wp-config-sample.php" > "$WORDPRESSPATH/wp-config.php"
if [ -e "$WORDPRESSPATH/wp-config.php" ] ; then
chown -R --reference="$WORDPRESSPATH/wp-config-sample.php" "$WORDPRESSPATH/wp-config.php"
echoG "Finished setting up WordPress."
else
echoR "WordPress setup failed. You may not have sufficient privileges to access $WORDPRESSPATH/wp-config.php."
ALLERRORS=1
fi
else
echoR "WordPress setup failed. File $WORDPRESSPATH/wp-config-sample.php does not exist."
ALLERRORS=1
fi
}
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 ] && [ "x$OSNAME" = "xcentos" ] ; 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 install_mysql
{
if [ "x$OSNAME" = "xcentos" ] ; then
#Add mariadb repo here if not exist
local REPOFILE=/etc/yum.repos.d/MariaDB.repo
if [ ! -f $REPOFILE ] ; then
local CENTOSVER=
if [ "x$OSTYPE" != "xx86_64" ] ; then
CENTOSVER=centos$OSVER-x86
else
CENTOSVER=centos$OSVER-amd64
fi
cat >> $REPOFILE <<END
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/$CENTOSVER
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
END
fi
yum -y install MariaDB-server MariaDB-client
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
else
if [ "x$OSNAMEVER" = "xDEBIAN7" ] ; then
apt-get install python-software-properties
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
elif [ "x$OSNAMEVER" = "xDEBIAN8" ] ; then
apt-get install software-properties-common
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
elif [ "x$OSNAMEVER" = "xDEBIAN9" ] ; then
apt-get install software-properties-common
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
elif [ "x$OSNAMEVER" = "xUBUNTU12" ] ; then
apt-get install python-software-properties
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
elif [ "x$OSNAMEVER" = "xUBUNTU14" ] ; then
apt-get install software-properties-common
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
elif [ "x$OSNAMEVER" = "xUBUNTU16" ] ; then
apt-get install software-properties-common
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
fi
grep -Fq "http://mirror.jaleco.com/mariadb/repo/" /etc/apt/sources.list.d/mariadb_repo.list
if [ $? != 0 ] ; then
echo "deb [$MARIADBCPUARCH] http://mirror.jaleco.com/mariadb/repo/10.1/$OSNAME $OSVER main" > /etc/apt/sources.list.d/mariadb_repo.list
fi
apt-get -y -f --force-yes 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 --force-yes install mariadb-server' to check. Aborting installation!"
exit 1
fi
fi
service mysql start
if [ $? != 0 ] ; then
echoR "An error occured when starting the MariaDB service. "
echoR "Please fix this error and try again. Aborting installation!"
exit 1
fi
#mysql_secure_installation
#mysql_install_db
mysql -uroot -e "update mysql.user set plugin='' where user='root';"
mysql -uroot -e "flush privileges;"
#service mysql restart
mysqladmin -uroot password $ROOTPASSWORD
if [ $? = 0 ] ; then
echoG "Mysql root password set to $ROOTPASSWORD"
CURROOTPASSWORD=$ROOTPASSWORD
else
#test it is the current password
mysqladmin -uroot -p$ROOTPASSWORD password $ROOTPASSWORD
if [ $? = 0 ] ; then
echoG "Mysql root password is $ROOTPASSWORD"
CURROOTPASSWORD=$ROOTPASSWORD
else
echoR "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 [ "x$TESTPASSWORDERROR" = "x1" ] ; then
echoY "If you forget your password you may stop the mysqld service and run the following command to reset it,"
echoY "mysqld_safe --skip-grant-tables &"
echoY "mysql --user=root mysql"
echoY "update user set Password=PASSWORD('new-password') where user='root'; flush privileges; exit; "
echoR "Aborting installation."
echo
exit 1
fi
if [ "x$CURROOTPASSWORD" != "x$ROOTPASSWORD" ] ; then
echoY "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 [ "x$answer" != "xY" ] && [ "x$answer" != "xy" ] ; then
echoG "OK, mysql root password not changed."
ROOTPASSWORD=$CURROOTPASSWORD
else
mysqladmin -uroot -p$CURROOTPASSWORD password $ROOTPASSWORD
if [ $? = 0 ] ; then
echoG "OK, mysql root password changed to $ROOTPASSWORD."
else
echoR "Failed to change mysql root password, it is still $CURROOTPASSWORD."
ROOTPASSWORD=$CURROOTPASSWORD
fi
fi
fi
fi
fi
}
function setup_mysql
{
local ERROR=
#delete user if exists because I need to set the password
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
echoG "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
echoR "Failed to create mysql user $USERNAME. This user may already exist. If it does not, another problem occured."
echoR "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
echoR "Failed to create database $DATABASENAME. It may already exist. If it does not, another problem occured."
echoR "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
echoG "Finished mysql setup without error."
else
echoR "Finished mysql setup - some error(s) occured."
fi
}
function resetmysqlroot
{
MYSQLNAME=mysql
service $MYSQLNAME stop
if [ $? != 0 ] && [ "x$OSNAME" = "xcentos" ] ; then
MYSQLNAME=mysqld
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 [ "x$MYSQLINSTALLED" != "x1" ] ; then
echoY "Mysql-server not installed."
else
local ERROR=0
test_mysql_password
if [ "x$TESTPASSWORDERROR" = "x1" ] ; then
echoR "Failed to purge database."
echo
ERROR=1
ALLERRORS=1
#ROOTPASSWORD=123456
#resetmysqlroot $ROOTPASSWORD
else
ROOTPASSWORD=$CURROOTPASSWORD
fi
if [ "x$ERROR" = "x0" ] ; then
mysql -uroot -p$ROOTPASSWORD -e "DELETE FROM mysql.user WHERE User = '$USERNAME@localhost';"
mysql -uroot -p$ROOTPASSWORD -e "DROP DATABASE IF EXISTS $DATABASENAME;"
echoY "Database purged."
fi
fi
}
function uninstall_result
{
if [ "x$ALLERRORS" = "x0" ] ; then
echoG "Uninstallation finished."
else
echoY "Uninstallation finished - some error(s) occured. Please check these as you may need to manually fix them."
fi
echo
}
function install_ols
{
local STATUS=Install
if [ "x$OLSINSTALLED" = "x1" ] ; then
OLS_VERSION=$(cat "$SERVER_ROOT"/VERSION)
wget -O "$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 [ "x$OLS_VERSION" = "x$LATEST_VERSION" ] ; then
STATUS=Reinstall
echoY "OpenLiteSpeed is already installed with the latest version, will attempt to reinstall it."
else
STATUS=Update
echoY "OpenLiteSpeed is already installed and newer version is available, will attempt to update it."
fi
fi
if [ "x$OSNAME" = "xcentos" ] ; then
echo "$STATUS on Centos"
install_ols_centos $STATUS
else
echo "$STATUS on Debian/Ubuntu"
install_ols_debian $STATUS
fi
}
function config_server
{
if [ -e "$SERVER_ROOT/conf/httpd_config.conf" ] ; then
cat $SERVER_ROOT/conf/httpd_config.conf | grep "virtualhost wordpress" >/dev/null
if [ $? != 0 ] ; then
sed -i -e "s/adminEmails/adminEmails $EMAIL\n#adminEmails/" "$SERVER_ROOT/conf/httpd_config.conf"
VHOSTCONF=$SERVER_ROOT/conf/vhosts/wordpress/vhconf.conf
cat >> $SERVER_ROOT/conf/httpd_config.conf <<END
virtualhost wordpress {
vhRoot $WORDPRESSPATH
configFile $VHOSTCONF
allowSymbolLink 1
enableScript 1
restrained 0
setUIDMode 2
}
listener wordpress {
address *:$WPPORT
secure 0
map wordpress $SITEDOMAIN
}
module cache {
param <<<PARAMFLAG
enableCache 0
qsCache 1
reqCookieCache 1
respCookieCache 1
ignoreReqCacheCtrl 0
ignoreRespCacheCtrl 0
expireInSeconds 3600
maxStaleAge 200
enablePrivateCache 0
privateExpireInSeconds 3600
checkPrivateCache 1
checkPublicCache 1
maxCacheObjSize 100000000
PARAMFLAG
}
END
mkdir -p $SERVER_ROOT/conf/vhosts/wordpress/
cat > $VHOSTCONF <<END
docRoot \$VH_ROOT/
index {
useServer 0
indexFiles index.php
}
context / {
type NULL
location \$VH_ROOT
allowBrowse 1
indexFiles index.php
rewrite {
enable 1
inherit 1
rules <<<END_rules
rewriteFile $WORDPRESSPATH/.htaccess
END_rules
}
}
END
chown -R lsadm:lsadm $SERVER_ROOT/conf/
fi
#setup password
ENCRYPT_PASS=`"$SERVER_ROOT/admin/fcgi-bin/admin_php" -q "$SERVER_ROOT/admin/misc/htpasswd.php" $ADMINPASSWORD`
if [ $? = 0 ] ; then
echo "admin:$ENCRYPT_PASS" > "$SERVER_ROOT/admin/conf/htpasswd"
if [ $? = 0 ] ; then
echoY "Finished setting OpenLiteSpeed webAdmin password to $ADMINPASSWORD."
echoY "Finished updating server configuration."
else
echoY "OpenLiteSpeed webAdmin password not changed."
fi
fi
else
echoR "$SERVER_ROOT/conf/httpd_config.conf is missing, it seems that something went wrong during openlitespeed installation."
ALLERRORS=1
fi
}
function activate_cache
{
cat > $WORDPRESSPATH/activate_cache.php <<END
<?php
include '$WORDPRESSPATH/wp-load.php';
include_once '$WORDPRESSPATH/wp-admin/includes/plugin.php';
include_once '$WORDPRESSPATH/wp-admin/includes/file.php';
define('WP_ADMIN', true);
activate_plugin('litespeed-cache/litespeed-cache.php', '', false, false);
END
$SERVER_ROOT/fcgi-bin/lsphp5 $WORDPRESSPATH/activate_cache.php
rm $WORDPRESSPATH/activate_cache.php
}
function getCurStatus
{
if [ -e $SERVER_ROOT/bin/openlitespeed ] ; then
OLSINSTALLED=1
else
OLSINSTALLED=0
fi
which mysqladmin >/dev/null 2>&1
if [ $? = 0 ] ; then
MYSQLINSTALLED=1
else
MYSQLINSTALLED=0
fi
}
function changeOlsPassword
{
LSWS_HOME=$SERVER_ROOT
ENCRYPT_PASS=`"$LSWS_HOME/admin/fcgi-bin/admin_php" -q "$LSWS_HOME/admin/misc/htpasswd.php" $ADMINPASSWORD`
echo "$ADMIN_USER:$ENCRYPT_PASS" > "$LSWS_HOME/admin/conf/htpasswd"
echoY "Finished setting OpenLiteSpeed webAdmin password to $ADMINPASSWORD."
}
function uninstall
{
if [ "x$OLSINSTALLED" = "x1" ] ; then
echoY "Uninstalling ..."
$SERVER_ROOT/bin/lswsctrl stop
if [ "x$OSNAME" = "xcentos" ] ; then
echo "Uninstall on Centos"
uninstall_ols_centos
else
echo "Uninstall on Debian/Ubuntu"
uninstall_ols_debian
fi
echoG Uninstalled.
else
echoY "OpenLiteSpeed not installed."
fi
}
function read_password
{
if [ "x$1" != "x" ] ; then
TEMPPASSWORD=$1
else
passwd=
echoY "Please input password for $2(press enter to get a random one):"
read passwd
if [ "x$passwd" = "x" ] ; then
local RAND=$RANDOM
local DATE0=`date`
TEMPPASSWORD=`echo "$RAND0$DATE0" | md5sum | base64 | head -c 8`
else
TEMPPASSWORD=$passwd
fi
fi
}
function check_value_follow
{
FOLLOWPARAM=$1
local PARAM=$1
local KEYWORD=$2
#test if first letter is - or not.
if [ "x$1" = "x-n" ] || [ "x$1" = "x-e" ] || [ "x$1" = "x-E" ] ; then
FOLLOWPARAM=
else
local PARAMCHAR=`echo $1 | awk '{print substr($0,1,1)}'`
if [ "x$PARAMCHAR" = "x-" ] ; then
FOLLOWPARAM=
fi
fi
if [ "x$FOLLOWPARAM" = "x" ] ; then
if [ "x$KEYWORD" != "x" ] ; then
echoR "Error: '$PARAM' is not a valid '$KEYWORD', please check and try again."
usage
exit 1
fi
fi
}
function usage
{
echoY "USAGE: " "$0 [options] [options] ..."
echoY "OPTIONS "
echoG " --adminpassword(-a) [PASSWORD] " "To set the webAdmin password for openlitespeed instead of using a random one."
echoG " " "If you omit [PASSWORD], ols1clk will prompt you to provide this password during installation."
echoG " --email(-e) EMAIL " "To set the email of the administrator."
echoG " --lsphp VERSION " "To set the version of lsphp, such as 56, now we support '${LSPHPVERLIST[@]}'."
echoG " --wordpress(-w) " "To install and setup wordpress, you will still need to access the /wp-admin/wp-config.php"
echoG " " "file to finish your wordpress installation."
echoG " --wordpressplus SITEDOMAIN " "To install, setup, and configure wordpress, eliminating the need to use the wp-config.php setup."
echoG " --wordpresspath WORDPRESSPATH " "To specify a location for the new wordpress installation or use an existing wordpress installation."
echoG " --dbrootpassword(-r) [PASSWORD] " "To set the database root password instead of using a random one."
echoG " " "If you omit [PASSWORD], ols1clk will prompt you to provide this password during installation."
echoG " --dbname DATABASENAME " "To set the database name to be used by wordpress."
echoG " --dbuser DBUSERNAME " "To set the username of wordpress in database."
echoG " --dbpassword [PASSWORD] " "To set the password of the table used by wordpress in mysql instead of using a random one."
echoG " " "If you omit [PASSWORD], ols1clk will prompt you to provide this password during installation."
echoG " --listenport WORDPRESSPORT " "To set the wordpress listener port, default is 80."
echoG " --wpuser WORDPRESSUSER " "To set the wordpress user for admin login to the wordpress dashboard, default is wpuser."
echoG " --wppassword [PASSWORD] " "To set the wordpress password for admin login to the wordpress dashboard."
echoG " " "If you omit [PASSWORD], ols1clk will prompt you to provide this password during installation."
echoG " --wplang WORDPRESSLANGUAGE " "To set the wordpress language, default is en for English"
echoG " --sitetitle WORDPRESSSITETITLE " "To set the wordpress site title, default is MySite"
echoG " --uninstall " "To uninstall OpenLiteSpeed and remove installation directory."
echoG " --purgeall " "To uninstall OpenLiteSpeed, remove installation directory, and purge all data in mysql."
echoG " --quiet " "Set to --quiet mode, won't prompt to input anything."
echoG " --version(-v) " "To display version information."
echoG " --help(-h) " "To display usage."
echo
echoY "EXAMPLES "
echoG "./ols1clk.sh " "To install openlitespeed of the latest version with random webAdmin password."
echoG "./ols1clk.sh --lsphp 71 " "To install openlitespeed of the latest version with lsphp71."
echoG "./ols1clk.sh -a 123456 -e a@cc.com " "To install openlitespeed of the latest version with specified webAdmin password and email."
echoG "./ols1clk.sh -r 123456 -w " "To install openlitespeed with wordpress with specifies mysql root password."
echoG "./ols1clk.sh -a 123 -r 1234 --wordpressplus a.com" ""
echo " To install openlitespeed with wordpress with specifies mysql root password and finished all settings."
echoG "./ols1clk.sh -a 123 -r 1234 --wplang zh_CN --sitetitle mySite --wordpressplus a.com" ""
echo " To install openlitespeed with wordpress with specifies mysql root password and finished all settings."
echo
}
function uninstall_warn
{
if [ "x$FORCEYES" != "x1" ] ; then
echo
printf "\033[31mAre you sure you want to uninstall? Type 'Y' to continue, otherwise will quit.[y/N]\033[0m "
read answer