diff options
Diffstat (limited to 'files/scripts/CentOS')
-rw-r--r-- | files/scripts/CentOS/setmysqlpass.sh | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/files/scripts/CentOS/setmysqlpass.sh b/files/scripts/CentOS/setmysqlpass.sh index b84aa7a..6876cb9 100644 --- a/files/scripts/CentOS/setmysqlpass.sh +++ b/files/scripts/CentOS/setmysqlpass.sh @@ -2,6 +2,26 @@ test -f /root/.my.cnf || exit 1 +must_have () +{ + # Here, using "which" would not be appropriate since it also depends on + # PATH being set correctly. The type builtin command is unaffected by the + # environment. + type $1 >/dev/null + if [ $? -ne 0 ]; then + echo "Command '$1' not found, did you correctly set PATH ? Its current value is: $PATH" >&2 + exit 1 + fi +} + +# Since this script is doing something rather unsafe with the database, we want +# to be really careful to have all the necessary tools before doing anything so +# that we don't end up in an inconsistent state. +must_have sleep +must_have mysql +must_have killall +must_have chown + rootpw=$(grep password /root/.my.cnf | sed -e 's/^[^=]*= *\(.*\) */\1/') /usr/bin/mysqladmin -uroot --password="${rootpw}" status > /dev/null && echo "Nothing to do as the password already works" && exit 0 |