From 61055e4da652166ce27ed67c5bd47b0a0f257627 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 23 Sep 2022 22:20:55 +0200 Subject: [PATCH] Fix #5 --- scripts/backup | 7 +++++++ scripts/install | 3 +++ scripts/remove | 20 ++++++++++++++++++++ scripts/restore | 14 ++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/scripts/backup b/scripts/backup index 622ac8d..143d201 100755 --- a/scripts/backup +++ b/scripts/backup @@ -29,6 +29,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) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -41,6 +42,12 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$final_path" +#================================================= +# BACKUP THE DATA DIR +#================================================= + +ynh_backup --src_path="$datadir" --is_big + #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= diff --git a/scripts/install b/scripts/install index 682b35b..8ebd4c9 100755 --- a/scripts/install +++ b/scripts/install @@ -38,6 +38,8 @@ ynh_script_progression --message="Validating installation parameters..." --weigh final_path=/opt/couchdb test ! -e "$final_path" || ynh_die --message="This path already contains a folder" +datadir=/var/lib/$app + # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -50,6 +52,7 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=password --value=$password ynh_app_setting_set --app=$app --key=final_path --value=$final_path +ynh_app_setting_set --app=$app --key=datadir --value=$datadir #================================================= # STANDARD MODIFICATIONS diff --git a/scripts/remove b/scripts/remove index f4d1f82..a8ba343 100755 --- a/scripts/remove +++ b/scripts/remove @@ -19,6 +19,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE @@ -41,6 +42,25 @@ ynh_script_progression --message="Removing logrotate configuration..." --weight= # Remove the app-specific logrotate config ynh_remove_logrotate +#================================================= +# REMOVE APP MAIN DIR +#================================================= +ynh_script_progression --message="Removing app main directory..." --weight=1 + +# Remove the app directory securely +ynh_secure_remove --file="$final_path" + +#================================================= +# REMOVE DATA DIR +#================================================= + +# Remove the data directory if --purge option is used +if [ "${YNH_APP_PURGE:-0}" -eq 1 ] +then + ynh_script_progression --message="Removing app data directory..." --weight=1 + ynh_secure_remove --file="$datadir" +fi + #================================================= # REMOVE NGINX CONFIGURATION #================================================= diff --git a/scripts/restore b/scripts/restore index e27040f..8556d62 100755 --- a/scripts/restore +++ b/scripts/restore @@ -32,6 +32,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) password=$(ynh_app_setting_get --app=$app --key=password) port=$(ynh_app_setting_get --app=$app --key=port) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -50,6 +51,15 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$final_path" +#================================================= +# RESTORE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Restoring the data directory..." --weight=1 + +ynh_restore_file --origin_path="$datadir" --not_mandatory + +mkdir -p $datadir + #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= @@ -99,6 +109,10 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #=================================================