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,16 +140,24 @@ 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"
if [[ $? != "0" ]]; then
done="0"
echo "${red}============================================"
echo " [Error]: Database conection failed."
echo "============================================${blu}"
echo ""
continue 2;
fi
else else
sudo mysql --connect-timeout=10 -h "$dburl" -P "$dbport" -u"$dburoot" -p"$dbproot" -e "quit" 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}============================================" echo " [Error]: Database conection failed."
echo " [Error]: Database conection failed." echo "============================================${blu}"
echo "============================================${blu}" echo ""
echo "" continue 2;
continue 2; fi
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
@ -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,14 +229,14 @@ 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"
echo "${red}============================================" echo "${red}============================================"
echo " [Error]: Database creation failed." echo " [Error]: Database creation failed."
echo "============================================${end}" echo "============================================${end}"
echo "" echo ""
fi
fi fi
fi fi