From 3465af26b1b4547de70386d5c1bee1c581e3d967 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 22 Aug 2021 14:28:41 +0200 Subject: [PATCH] Add purge datadir --- manifest.json | 2 +- scripts/backup | 4 ++-- scripts/change_url | 1 - scripts/install | 12 ++++++------ scripts/remove | 12 ++++++++++++ scripts/restore | 12 ++++++------ scripts/upgrade | 16 ++++++++-------- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/manifest.json b/manifest.json index 2bda36f..379526c 100644 --- a/manifest.json +++ b/manifest.json @@ -22,7 +22,7 @@ "email": "win10@tutanota.com, cyp@rouquin.me" }, "requirements": { - "yunohost": ">= 4.2.4" + "yunohost": ">= 4.2.8" }, "multi_instance": true, "services": [ diff --git a/scripts/backup b/scripts/backup index 514800d..6230e53 100644 --- a/scripts/backup +++ b/scripts/backup @@ -30,7 +30,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) -public_path=$(ynh_app_setting_get --app=$app --key=public_path) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -47,7 +47,7 @@ ynh_backup --src_path="$final_path" # BACKUP THE DATA DIR #================================================= -ynh_backup --src_path="$public_path" --is_big +ynh_backup --src_path="$datadir" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/change_url b/scripts/change_url index e78ed7f..17b4b74 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -35,7 +35,6 @@ is_public=$(ynh_app_setting_get --app=$app --key=is_public) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) db_user=$db_name -public_path=$(ynh_app_setting_get --app=$app --key=public_path) secret=$(ynh_app_setting_get --app=$app --key=secret) max_file_size=$(ynh_app_setting_get --app=$app --key=max_file_size) diff --git a/scripts/install b/scripts/install index b15901c..f3c8907 100644 --- a/scripts/install +++ b/scripts/install @@ -114,14 +114,14 @@ chown -R $app:www-data "$final_path" #================================================= ynh_script_progression --message="Creating a data directory..." -public_path=/home/yunohost.app/$app -ynh_app_setting_set --app=$app --key=public_path --value=$public_path +datadir=/home/yunohost.app/$app +ynh_app_setting_set --app=$app --key=datadir --value=$datadir -mkdir -p $public_path +mkdir -p $datadir -chmod 755 "$public_path" -chmod -R o-rwx "$public_path" -chown -R $app:www-data "$public_path" +chmod 755 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" #================================================= # NGINX CONFIGURATION diff --git a/scripts/remove b/scripts/remove index 0cca7d3..8d0d019 100644 --- a/scripts/remove +++ b/scripts/remove @@ -21,6 +21,7 @@ port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE @@ -67,6 +68,17 @@ ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" +#================================================= +# REMOVE DATA DIR +#================================================= + +# Remove the app data directory with the command `yunohost app remove --purge` +if [ "$YNH_APP_PURGE" == true ] +then + ynh_script_progression --message="Removing $app data directory..." --weight=2 + ynh_secure_remove --file="$datadir" +fi + #================================================= # REMOVE NGINX CONFIGURATION #================================================= diff --git a/scripts/restore b/scripts/restore index 16dd503..93315f1 100644 --- a/scripts/restore +++ b/scripts/restore @@ -30,7 +30,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -public_path=$(ynh_app_setting_get --app=$app --key=public_path) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) @@ -79,13 +79,13 @@ chown -R $app:www-data "$final_path" #================================================= ynh_script_progression --message="Restoring the data directory..." -ynh_restore_file --origin_path="$public_path" --not_mandatory +ynh_restore_file --origin_path="$datadir" --not_mandatory -mkdir -p $public_path +mkdir -p $datadir -chmod 750 "$public_path" -chmod -R o-rwx "$public_path" -chown -R $app:www-data "$public_path" +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" #================================================= # SPECIFIC RESTORATION diff --git a/scripts/upgrade b/scripts/upgrade index a059f3e..3800acc 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,7 +21,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) is_public=$(ynh_app_setting_get --app=$app --key=is_public) port=$(ynh_app_setting_get --app=$app --key=port) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -public_path=$(ynh_app_setting_get --app=$app --key=public_path) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) secret=$(ynh_app_setting_get --app=$app --key=secret) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name @@ -52,11 +52,11 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi -# If public_path doesn't exist, create it -if [ -z "$public_path" ]; then - public_path=/home/yunohost.app/$app - mkdir -p $public_path - ynh_app_setting_set --app=$app --key=public_path --value=$public_path +# If datadir doesn't exist, create it +if [ -z "$datadir" ]; then + datadir=/home/yunohost.app/$app + mkdir -p $datadir + ynh_app_setting_set --app=$app --key=datadir --value=$datadir fi if [ -z "$max_file_size" ]; then @@ -184,8 +184,8 @@ ynh_script_progression --message="Securing files and directories..." # Set permissions on app files chown -R $app:www-data $final_path chmod -R o-rwx "$final_path" -chown -R $app:www-data $public_path -chmod 755 $public_path +chown -R $app:www-data $datadir +chmod 755 $datadir #================================================= # SETUP SSOWAT