From 321d6cb2d9b88c7145212b0afdf5febc5ce6bf2e Mon Sep 17 00:00:00 2001 From: Jocelyn Delalande Date: Sun, 25 Nov 2018 18:38:33 +0100 Subject: [PATCH] Use ynh helpers for error handling Instead of doing it by hand. Also we now rely on the fact ynh automatically runs uninstall script if the install fails. So no more need for manual cleanup. --- scripts/backup | 3 ++- scripts/install | 21 +++------------------ scripts/remove | 1 - scripts/restore | 2 +- scripts/upgrade | 8 ++------ 5 files changed, 8 insertions(+), 27 deletions(-) diff --git a/scripts/backup b/scripts/backup index f9cbb36..9749d13 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,9 +1,10 @@ #!/bin/bash -set -eu # Source YunoHost helpers source /usr/share/yunohost/helpers +ynh_abort_if_errors + # Get multi-instances specific variables app=$YNH_APP_INSTANCE_NAME diff --git a/scripts/install b/scripts/install index 8cdbe5c..da3eb9e 100755 --- a/scripts/install +++ b/scripts/install @@ -1,5 +1,4 @@ #!/bin/bash -set -eu # Source YunoHost helpers source /usr/share/yunohost/helpers @@ -25,29 +24,15 @@ db_user=ihatemoney secret_key=`openssl rand -base64 32` mails_sender="no-reply@${domain}" + +ynh_abort_if_errors + ynh_webpath_register $app $domain $path # Configure database ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd" ynh_app_setting_set $app mysqlpwd $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 - ynh_mysql_drop_db $db_name - ynh_mysql_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 - ynh_die "Install script failed, aborted and rolled back the installation" -} -trap exit_properly ERR - # Save app settings ynh_app_setting_set $app domain $domain ynh_app_setting_set $app is_public "$is_public" diff --git a/scripts/remove b/scripts/remove index 414b9b5..be63595 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,5 +1,4 @@ #!/bin/bash -set -u # Source YunoHost helpers source /usr/share/yunohost/helpers diff --git a/scripts/restore b/scripts/restore index 8317037..3c2dfee 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,5 +1,4 @@ #!/bin/bash -set -eu # Source app helpers source /usr/share/yunohost/helpers @@ -26,6 +25,7 @@ fi source _common.sh +ynh_abort_if_errors ynh_webpath_register $app $domain $path diff --git a/scripts/upgrade b/scripts/upgrade index 000036b..acbb0f7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,5 +1,4 @@ #!/bin/bash -set -eu app=$YNH_APP_INSTANCE_NAME @@ -23,17 +22,14 @@ VENV_PY_VERSION=$(echo ${INSTALL_DIR}/venv/bin/python*.*|sed 's/.*python//') # Source local utils source _common.sh -function exit_properly () { - set +e - # Revert to the old venv +ynh_clean_setup () { if [ -e /opt/yunohost/ihatemoney/venv-old ] then sudo mv /opt/yunohost/ihatemoney/venv{-old,} fi - ynh_die "Upgrade script failed, aborted and rolled back the installation" } -trap exit_properly ERR +ynh_abort_if_errors #----------------------------PRE-UPGRADE MIGRATIONS-----------------------