mysql command error exit code

Fixed error detection after mysql command execution.
This commit is contained in:
Cristhian Martínez Ochoa 2018-02-27 16:29:24 -07:00
parent aa5313bf80
commit ecb20e4254

View file

@ -140,9 +140,6 @@ wpinstall() {
if [[ $dbhost == "localhost" ]]; then if [[ $dbhost == "localhost" ]]; then
local ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt ) local ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "quit" sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "quit"
else
sudo mysql --connect-timeout=10 -h "$dburl" -P "$dbport" -u"$dburoot" -p"$dbproot" -e "quit"
fi
if [[ $? != "0" ]]; then if [[ $? != "0" ]]; then
done="0" done="0"
echo "${red}============================================" echo "${red}============================================"
@ -151,6 +148,17 @@ wpinstall() {
echo "" echo ""
continue 2; continue 2;
fi fi
else
sudo mysql --connect-timeout=10 -h "$dburl" -P "$dbport" -u"$dburoot" -p"$dbproot" -e "quit"
if [[ $? != "0" ]]; then
done="0"
echo "${red}============================================"
echo " [Error]: Database conection failed."
echo "============================================${blu}"
echo ""
continue 2;
fi
fi
if [[ $dbhost == "localhost" ]]; then if [[ $dbhost == "localhost" ]]; then
# https://stackoverflow.com/questions/7364709/bash-script-check-if-mysql-database-exists-perform-action-based-on-result # https://stackoverflow.com/questions/7364709/bash-script-check-if-mysql-database-exists-perform-action-based-on-result
local newdbname=$(sudo mysqlshow --user=root -p$ROOT_PASS | grep -ow $dbname) local newdbname=$(sudo mysqlshow --user=root -p$ROOT_PASS | grep -ow $dbname)
@ -207,6 +215,13 @@ wpinstall() {
if [[ $dbhost == "localhost" ]]; then if [[ $dbhost == "localhost" ]]; then
local dbsetup="CREATE DATABASE $dbname;GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@$dbhost IDENTIFIED BY '$dbpass';FLUSH PRIVILEGES;" local dbsetup="CREATE DATABASE $dbname;GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@$dbhost IDENTIFIED BY '$dbpass';FLUSH PRIVILEGES;"
sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "$dbsetup" sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "$dbsetup"
if [ $? != "0" ]; then
done="0"
echo "${red}============================================"
echo " [Error]: Database creation failed."
echo "============================================${end}"
echo ""
fi
else else
sudo mysql --connect-timeout=10 -h "$dburl" -P "$dbport" -u"$dburoot" -p"$dbproot" <<_EOF_ sudo mysql --connect-timeout=10 -h "$dburl" -P "$dbport" -u"$dburoot" -p"$dbproot" <<_EOF_
CREATE DATABASE ${dbname}; CREATE DATABASE ${dbname};
@ -214,7 +229,6 @@ grant usage on ${dbname}.* to ${dbuser}@\`%\` identified by '${dbpass}';
grant all privileges on ${dbname}.* to ${dbuser}@\`%\`; grant all privileges on ${dbname}.* to ${dbuser}@\`%\`;
FLUSH PRIVILEGES; FLUSH PRIVILEGES;
_EOF_ _EOF_
fi
if [ $? != "0" ]; then if [ $? != "0" ]; then
done="0" done="0"
@ -224,6 +238,7 @@ _EOF_
echo "" echo ""
fi fi
fi fi
fi
if [[ $done != "1" ]]; then if [[ $done != "1" ]]; then
echo "${red} Some error ocurred during Database Configuration." echo "${red} Some error ocurred during Database Configuration."