From 4065c7d68284cf14b61664369a47221f68ca83e2 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 16 Oct 2022 12:21:24 +0200 Subject: [PATCH] Reorder script --- scripts/install | 18 ++++++++--------- scripts/restore | 30 ++++++++++++---------------- scripts/upgrade | 53 ++++++++++++++++++++++++------------------------- 3 files changed, 48 insertions(+), 53 deletions(-) diff --git a/scripts/install b/scripts/install index db3dbb8..aadca27 100755 --- a/scripts/install +++ b/scripts/install @@ -56,6 +56,14 @@ ynh_script_progression --message="Finding an available port..." --weight=2 port=$(ynh_find_port --port=7777) ynh_app_setting_set --app=$app --key=port --value=$port +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=3 + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -73,14 +81,6 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=3 - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path - #================================================= # SPECIFIC SETUP #================================================= @@ -115,7 +115,7 @@ popd ynh_script_progression --message="Creating the data directory..." --weight=1 # Define app's data directory -data_path="/home/yunohost.app/${app}" +data_path=/home/yunohost.app/$app ynh_app_setting_set --app=$app --key=data_path --value=$data_path # Create app folders diff --git a/scripts/restore b/scripts/restore index 3ff4e61..866e600 100755 --- a/scripts/restore +++ b/scripts/restore @@ -33,17 +33,11 @@ data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=2 -test ! -d $final_path || ynh_die "There is already a directory: $final_path " +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -51,6 +45,10 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$final_path" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -59,6 +57,13 @@ ynh_script_progression --message="Recreating the dedicated system user..." --wei # Create the dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir=$final_path +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # SPECIFIC RESTORE #================================================= @@ -88,15 +93,6 @@ chown -R $app:www-data "$data_path" ynh_script_progression --message="Restoring various files..." --weight=1 ynh_restore_file --origin_path="/usr/bin/$app" - -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chown -R $app: "$data_path" chmod +x /usr/bin/$app #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index cb8eb0a..86f523a 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,6 +27,27 @@ data_path=$(ynh_app_setting_get --app=$app --key=data_path) upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the 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 + +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -52,28 +73,15 @@ 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 the 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 #================================================= -# STOP SYSTEMD SERVICE +# CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -95,14 +103,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - #================================================= # SPECIFIC UPGRADE #================================================= @@ -135,8 +135,7 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 -ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service" - +env_path="$PATH" ynh_add_systemd_config #=================================================