Skip to content

Commit a39d57a

Browse files
committed
Update to support multiple time calling of the same command to install or uninstall which used to cause passwords become wrong and then would cause db connection error and access webAdmin error
1 parent 5eb9e63 commit a39d57a

File tree

1 file changed

+86
-45
lines changed

1 file changed

+86
-45
lines changed

ols1clk.sh

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function check_wget
9393
function display_license
9494
{
9595
echoYellow '/*********************************************************************************************'
96-
echoYellow '* Open LiteSpeed One click installation, Version 1.1 *'
96+
echoYellow '* Open LiteSpeed One click installation, Version 1.2 *'
9797
echoYellow '* Copyright (C) 2016 LiteSpeed Technologies, Inc. *'
9898
echoYellow '*********************************************************************************************/'
9999
}
@@ -267,7 +267,7 @@ function install_wordpress
267267

268268
cd "$WORDPRESSPATH"
269269
wget --no-check-certificate http://wordpress.org/latest.tar.gz
270-
tar -xzvf latest.tar.gz
270+
tar -xzvf latest.tar.gz > /dev/null 2>&1
271271
rm latest.tar.gz
272272

273273
wget -q -r -nH --cut-dirs=2 --no-parent https://plugins.svn.wordpress.org/litespeed-cache/trunk/ --reject html -P $WORDPRESSPATH/wordpress/wp-content/plugins/litespeed-cache/
@@ -298,27 +298,40 @@ function setup_wordpress
298298

299299
function test_mysql_password
300300
{
301-
#test it is the current password
302-
CURROOTPASSWORD=
301+
CURROOTPASSWORD=$ROOTPASSWORD
303302
TESTPASSWORDERROR=0
304-
printf '\033[31mPlease input the current root password:\033[0m'
305-
read answer
306-
mysqladmin -uroot -p$answer password $answer
307-
if [ $? = 0 ] ; then
308-
CURROOTPASSWORD=$answer
309-
else
310-
echoRed "root password is incorrect. 1 attempt remaining."
303+
304+
#test it is the current password
305+
mysqladmin -uroot -p$CURROOTPASSWORD password $CURROOTPASSWORD
306+
if [ $? != 0 ] ; then
311307
printf '\033[31mPlease input the current root password:\033[0m'
312308
read answer
313-
mysqladmin -u root -p$answer password $answer
309+
mysqladmin -uroot -p$answer password $answer
314310
if [ $? = 0 ] ; then
315311
CURROOTPASSWORD=$answer
316312
else
317-
echoRed "root password is incorrect. 0 attempts remaining."
318-
echo
319-
TESTPASSWORDERROR=1
313+
echoRed "root password is incorrect. 2 attempts remaining."
314+
printf '\033[31mPlease input the current root password:\033[0m'
315+
read answer
316+
mysqladmin -u root -p$answer password $answer
317+
if [ $? = 0 ] ; then
318+
CURROOTPASSWORD=$answer
319+
else
320+
echoRed "root password is incorrect. 1 attempt remaining."
321+
printf '\033[31mPlease input the current root password:\033[0m'
322+
read answer
323+
mysqladmin -u root -p$answer password $answer
324+
if [ $? = 0 ] ; then
325+
CURROOTPASSWORD=$answer
326+
else
327+
echoRed "root password is incorrect. 0 attempts remaining."
328+
echo
329+
TESTPASSWORDERROR=1
330+
fi
331+
fi
320332
fi
321333
fi
334+
322335
export CURROOTPASSWORD=$CURROOTPASSWORD
323336
export TESTPASSWORDERROR=$TESTPASSWORDERROR
324337
}
@@ -327,18 +340,28 @@ function install_mysql
327340
{
328341
if [ "x$ISCENTOS" = "x1" ] ; then
329342
yum -y install mysql-server
343+
if [ $? != 0 ] ; then
344+
echoRed "An error occured during installation of Mysql-server. Please fix this error and try again."
345+
echoRed "You may want to manually run the command 'yum -y install mysql-server' to check. Aborting installation!"
346+
exit 1
347+
fi
330348
service mysqld start
331349
else
332350
apt-get -y -f --force-yes install mysql-server
351+
if [ $? != 0 ] ; then
352+
echoRed "An error occured during installation of Mysql-server. Please fix this error and try again."
353+
echoRed "You may want to manually run the command 'apt-get -y -f --force-yes install mysql-server' to check. Aborting installation!"
354+
exit 1
355+
fi
333356
mysqld start
334357
fi
335-
#chkconfig mysqld on
358+
336359
if [ $? != 0 ] ; then
337-
echoRed "An error occured during installation of Mysql-server."
360+
echoRed "An error occured during starting service of Mysql-server. "
338361
echoRed "Please fix this error and try again. Aborting installation!"
339362
exit 1
340-
fi
341-
363+
fi
364+
342365
#mysql_secure_installation
343366
#mysql_install_db
344367
mysqladmin -u root password $ROOTPASSWORD
@@ -390,6 +413,9 @@ function install_mysql
390413
function setup_mysql
391414
{
392415
local ERROR=
416+
417+
#delete user if exists because I need to set the password
418+
mysql -uroot -p$ROOTPASSWORD -e "DELETE FROM mysql.user WHERE User = '$USERNAME@localhost';"
393419

394420
echo `mysql -uroot -p$ROOTPASSWORD -e "SELECT user FROM mysql.user"` | grep "$USERNAME" > /dev/nul
395421
if [ $? = 0 ] ; then
@@ -433,23 +459,20 @@ function purgedatabase
433459
echoYellow "Mysql-server not installed."
434460
else
435461
local ERROR=0
436-
mysqladmin -uroot -p$ROOTPASSWORD password $ROOTPASSWORD
437-
if [ $? != 0 ] ; then
438-
test_mysql_password
439-
440-
if [ "x$TESTPASSWORDERROR" = "x1" ] ; then
441-
echoRed "Failed to purge database."
442-
echo
443-
ERROR=1
444-
ALLERRORS=1
445-
else
446-
ROOTPASSWORD=$CURROOTPASSWORD
447-
fi
462+
test_mysql_password
463+
464+
if [ "x$TESTPASSWORDERROR" = "x1" ] ; then
465+
echoRed "Failed to purge database."
466+
echo
467+
ERROR=1
468+
ALLERRORS=1
469+
else
470+
ROOTPASSWORD=$CURROOTPASSWORD
448471
fi
449-
472+
450473
if [ "x$ERROR" = "x0" ] ; then
451-
mysql -uroot -p$ROOTPASSWORD -e "DROP USER $USERNAME@localhost;"
452-
mysql -uroot -p$ROOTPASSWORD -e "DROP DATABASE $DATABASENAME;"
474+
mysql -uroot -p$ROOTPASSWORD -e "DELETE FROM mysql.user WHERE User = '$USERNAME@localhost';"
475+
mysql -uroot -p$ROOTPASSWORD -e "DROP DATABASE IF EXISTS $DATABASENAME;"
453476
echoYellow "Database purged."
454477
fi
455478
fi
@@ -551,14 +574,22 @@ END_rules
551574
}
552575
553576
END
554-
555577
chown -R lsadm:lsadm $WORDPRESSPATH/conf/
556-
578+
fi
579+
557580
#setup password
558-
ENCRYPT_PASS=`"$SERVER_ROOT/admin/fcgi-bin/admin_php" -q "$SERVER_ROOT/admin/misc/htpasswd.php" $ADMINPASSWORD`
581+
ENCRYPT_PASS=`"$SERVER_ROOT/admin/fcgi-bin/admin_php" -q "$SERVER_ROOT/admin/misc/htpasswd.php" $ADMINPASSWORD`
582+
if [ $? = 0 ] ; then
559583
echo "admin:$ENCRYPT_PASS" > "$SERVER_ROOT/admin/conf/htpasswd"
560-
echoYellow "Finished setting OpenLiteSpeed webAdmin password to $ADMINPASSWORD."
561-
echoYellow "Finished updating server configuration."
584+
if [ $? = 0 ] ; then
585+
echoYellow "Finished setting OpenLiteSpeed webAdmin password to $ADMINPASSWORD."
586+
echoYellow "Finished updating server configuration."
587+
588+
#write the password file for record and remove the previous file.
589+
echo "WebAdmin password is [$ADMINPASSWORD]." > $SERVER_ROOT/password
590+
else
591+
echoYellow "OpenLiteSpeed webAdmin password not changed."
592+
fi
562593
fi
563594
else
564595
echoRed "$SERVER_ROOT/conf/httpd_config.conf is missing, it seems that something went wrong during openlitespeed installation."
@@ -794,14 +825,22 @@ install_ols
794825
if [ "x$INSTALLWORDPRESS" = "x1" ] ; then
795826
if [ "x$MYSQLINSTALLED" != "x1" ] ; then
796827
install_mysql
828+
else
829+
test_mysql_password
797830
fi
798831

799832
if [ "x$WORDPRESSINSTALLED" != "x1" ] ; then
800833
install_wordpress
801834
setup_wordpress
835+
836+
if [ "x$TESTPASSWORDERROR" = "x1" ] ; then
837+
echoYellow "Mysql setup byppassed due to not know the root password."
838+
else
839+
ROOTPASSWORD=$CURROOTPASSWORD
840+
setup_mysql
841+
fi
802842
fi
803-
804-
setup_mysql
843+
805844
config_server
806845

807846
if [ "x$WPPORT" = "x80" ] ; then
@@ -811,17 +850,17 @@ if [ "x$INSTALLWORDPRESS" = "x1" ] ; then
811850
fi
812851
fi
813852

853+
$SERVER_ROOT/bin/lswsctrl stop
814854
$SERVER_ROOT/bin/lswsctrl start
815855

816-
echo "WebAdmin password is [$ADMINPASSWORD] and mysql root password is [$ROOTPASSWORD]." > $SERVER_ROOT/password
817-
echoRed "Please be aware that your password was written to file $SERVER_ROOT/password."
856+
echo "mysql root password is [$ROOTPASSWORD]." >> $SERVER_ROOT/password
857+
echoYellow "Please be aware that your password was written to file '$SERVER_ROOT/password'."
818858

819859
if [ "x$ALLERRORS" = "x0" ] ; then
820860
echoGreen "Congratulations! Installation finished."
821861
if [ "x$INSTALLWORDPRESS" = "x1" ] ; then
822862
echoGreen "Please access http://localhost:$WPPORT/ to finish setting up your WordPress site."
823863
echoGreen "And also you may want to activate Litespeed Cache plugin to get better performance."
824-
echoGreen "Enjoy!"
825864
fi
826865
else
827866
echoYellow "Installation finished. It seems some errors occured, please check this as you may need to manually fix them."
@@ -830,7 +869,9 @@ else
830869
echoGreen "And also you may want to activate Litespeed Cache plugin to get better performance."
831870
fi
832871
fi
872+
echo
833873
echoGreen "If you run into any problems, they can sometimes be fixed by purgeall and reinstalling."
834-
echoGreen 'Thanks for using "OpenLiteSpeed One click installation."'
874+
echoGreen 'Thanks for using "OpenLiteSpeed One click installation".'
875+
echoGreen "Enjoy!"
835876
echo
836877
echo

0 commit comments

Comments
 (0)