diff --git a/scripts/backup b/scripts/backup index e88426f..bc978f0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,8 +1,10 @@ #!/bin/bash -# Retrieve arguments -backup_dir=$1 -app=$2 +# Exit on command errors and treat unset variables as an error +set -eu + +# Retrieve app id +app=$YNH_APP_INSTANCE_NAME # Set app specific variables dbname=$app diff --git a/scripts/install b/scripts/install index a91bbd6..74c1aeb 100644 --- a/scripts/install +++ b/scripts/install @@ -1,15 +1,18 @@ #!/bin/bash -set -e +# Exit on command errors and treat unset variables as an error +set -eu + +# Retrieve app id +app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$1 path=${2%/} password=$3 -app=${!#} # Load common variables and helpers -source ./_common.sh +. ./_common.sh # Set app specific variables dbname=$app diff --git a/scripts/remove b/scripts/remove index 0b0af86..ae74e55 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,21 +1,21 @@ #!/bin/bash -# Retrieve arguments -app=${!#} +# Retrieve app id +app=$YNH_APP_INSTANCE_NAME # Load common variables and helpers -source ./_common.sh +. ./_common.sh # Set app specific variables dbname=$app dbuser=$app # Drop MySQL database and user -ynh_mysql_drop_db $dbname || true -ynh_mysql_drop_user $dbuser || true +ynh_mysql_drop_db "$dbname" 2>/dev/null || true +ynh_mysql_drop_user "$dbuser" 2>/dev/null || true # Retrieve domain from app settings -domain=$(ynh_app_setting_get $app domain) +domain=$(ynh_app_setting_get "$app" domain) # Delete app directory and configurations sudo rm -rf "/var/www/${app}" diff --git a/scripts/restore b/scripts/restore index bb43be9..e394c7f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,12 +1,10 @@ #!/bin/bash -# Retrieve arguments -backup_dir=$1 -app=$2 +# Exit on command errors and treat unset variables as an error +set -eu -# Set app specific variables -dbname=$app -dbuser=$app +# Retrieve app id +app=$YNH_APP_INSTANCE_NAME # Source app helpers . /usr/share/yunohost/helpers @@ -16,6 +14,10 @@ domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) dbpass=$(ynh_app_setting_get "$app" mysqlpwd) +# Set app specific variables +dbname=$app +dbuser=$app + # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ || exit 1 diff --git a/scripts/upgrade b/scripts/upgrade index 2897a13..35491a1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,20 +1,23 @@ #!/bin/bash -set -u +# Exit on command errors and treat unset variables as an error +set -eu + +# Retrieve app id +app=$YNH_APP_INSTANCE_NAME # Load common variables and helpers . ./_common.sh -# Set app specific variables -app=${!#} -dbname=$app -dbuser=$app - -# Retrieve arguments +# Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) path=${path%/} +# Set app specific variables +dbname=$app +dbuser=$app + # Check destination directory DESTDIR="/var/www/$app" [[ ! -d $DESTDIR ]] && ynh_die \