From 309e46013fdf6909f741dc78845ae6115d1f2071 Mon Sep 17 00:00:00 2001 From: Jocelyn Delande Date: Sun, 26 Jul 2015 18:23:54 +0200 Subject: [PATCH] Cleans after itself in case the install fails. Refs #1 and #4 (and hopefuly fixes them) --- scripts/install | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index 259c55d..9e85c60 100755 --- a/scripts/install +++ b/scripts/install @@ -21,6 +21,27 @@ fi # Remove trailing "/" for next commands path=${path%/} +# Configure database +db_pwd=`sudo yunohost app initdb $db_user` +sudo yunohost app setting $app mysqlpwd -v $db_pwd + +# Delete db, user dirs and conf if exit with an error +# inspired from https://github.com/Kloadut/owncloud_ynh/blob/master/scripts/install#L37 + +function exit_properly +{ + set +e + root_pwd=$(sudo cat /etc/yunohost/mysql) + mysql -u root -p$root_pwd -e "DROP DATABASE ihatemoney ; DROP USER $db_user ;" + sudo userdel ihatemoney + sudo rm -Rf /opt/yunohost/ihatemoney + sudo rm -Rf /etc/ihatemoney + sudo rm /etc/nginx/conf.d/$domain.d/ihatemoney.conf + sudo rm /etc/supervisor/conf.d/ihatemoney.conf + exit 1 +} +trap exit_properly ERR + # Save app settings sudo yunohost app setting $app domain -v $domain sudo yunohost app setting $app is_public -v "$is_public" @@ -55,10 +76,6 @@ sudo install -o root -g root -m 644 \ ../conf/supervisord.conf /etc/supervisor/conf.d/ihatemoney.conf sudo yunohost service add supervisor -# Configure database -db_pwd=`sudo yunohost app initdb $db_user` -sudo yunohost app setting $app mysqlpwd -v $db_pwd - # Configure ihatemoney sed -i "s@MY_SECRET_KEY@$secret_key@" ../conf/settings.py sed -i "s/MY_EMAIL/$mails_sender/" ../conf/settings.py