diff --git a/scripts/backup b/scripts/backup index 00bf0d9..a4ec5ef 100644 --- a/scripts/backup +++ b/scripts/backup @@ -25,6 +25,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,7 +42,7 @@ ynh_backup --src_path="$final_path" # BACKUP DATA #================================================= -ynh_backup --src_path="/home/yunohost.app/$app" --is_big +ynh_backup --src_path="$datadir" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index de93230..12beb0c 100644 --- a/scripts/install +++ b/scripts/install @@ -107,13 +107,19 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=3 ynh_add_nginx_config #================================================= -# CREATE DIRECTORIES +# CREATE DATA DIRECTORY #================================================= +ynh_script_progression --message="Creating a data directory..." --weight=1 + +datadir=/home/yunohost.app/$app +ynh_app_setting_set --app=$app --key=datadir --value=$datadir + +mkdir -p $datadir/{torrents,downloads} -mkdir -p /home/yunohost.app/$app/{torrents,downloads} # Set permissions to app files -chown -R $app:www-data /home/yunohost.app/$app -chmod 755 /home/yunohost.app/$app/{torrents,downloads} +chmod 755 $datadir/{torrents,downloads} +chmod -R o-rwx $datadir +chown -R $app:www-data $datadir #================================================= # MODIFY A CONFIG FILE diff --git a/scripts/remove b/scripts/remove index 1e7b474..04be542 100644 --- a/scripts/remove +++ b/scripts/remove @@ -20,6 +20,7 @@ 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) peer_port=$(ynh_app_setting_get --app=$app --key=peer_port) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE @@ -50,6 +51,17 @@ ynh_script_progression --message="Removing $app main directory..." --weight=6 # 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 01820b9..18fbbdd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -27,6 +27,7 @@ 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) peer_port=$(ynh_app_setting_get --app=$app --key=peer_port) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -52,7 +53,6 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Configuring firewall..." --weight=3 -#ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port ynh_exec_warn_less yunohost firewall allow Both $peer_port #================================================= @@ -80,10 +80,13 @@ chmod +x $final_path/$app #================================================= ynh_script_progression --message="Restoring $app data..." --weight=10 -ynh_restore_file --origin_path="/home/yunohost.app/$app" --not_mandatory +ynh_restore_file --origin_path="$datadir" --not_mandatory -chown -R $app:www-data /home/yunohost.app/$app -chmod 755 /home/yunohost.app/$app/{torrents,downloads} +mkdir -p $datadir/{torrents,downloads} + +chmod 755 $datadir/{torrents,downloads} +chmod -R o-rwx $datadir +chown -R $app:www-data $datadir #================================================= # RESTORE SYSTEMD diff --git a/scripts/upgrade b/scripts/upgrade index d19bb5f..af6a90b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,10 +26,23 @@ architecture=$(ynh_detect_arch) #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=4 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -48,20 +61,6 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=4 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -119,15 +118,6 @@ ynh_script_progression --message="Modifying a config file..." --weight=1 ynh_add_config --template="../conf/config.default.yml" --destination="$final_path/config.yml" -#================================================= -# CREATE DIRECTORIES -#================================================= - -mkdir -p /home/yunohost.app/$app/{torrents,downloads} - -chown -R $app:www-data /home/yunohost.app/$app -chmod 755 /home/yunohost.app/$app/{torrents,downloads} - #================================================= # SETUP SYSTEMD #=================================================