From f285a5edce793731e19b98479622299a9c2f7b13 Mon Sep 17 00:00:00 2001 From: kload Date: Thu, 1 Oct 2015 18:32:33 -0400 Subject: [PATCH] [fix] Set a MySQL password at moulinette installation --- data/hooks/conf_regen/34-mysql | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/data/hooks/conf_regen/34-mysql b/data/hooks/conf_regen/34-mysql index 62d9d2b27..021e4537a 100644 --- a/data/hooks/conf_regen/34-mysql +++ b/data/hooks/conf_regen/34-mysql @@ -13,8 +13,24 @@ function safe_copy () { fi } +function randpass () { + [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" + cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-32} + echo +} + cd /usr/share/yunohost/templates/mysql if [[ "$(safe_copy my.cnf /etc/mysql/my.cnf)" == "True" ]]; then sudo service mysql restart fi + +if [ ! -f /etc/yunohost/mysql ]; then + [[ $(/bin/ps aux | grep mysqld | grep -vc "grep") == "0" ]] \ + && sudo service mysql start + + mysql_password=$(randpass 10 0) + sudo mysqladmin -u root -pyunohost password $mysql_password + echo $mysql_password | sudo tee /etc/yunohost/mysql + sudo chmod 400 /etc/yunohost/mysql +fi