From b6428a51ef58fd516f52ad56425a9ac695c12270 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 22 Nov 2020 23:36:37 +0100 Subject: [PATCH] Fix linter warnings --- scripts/{.fonctions => _common.sh} | 34 +-------------------- scripts/backup | 46 +++++++++++++++++++++++----- scripts/install | 2 +- scripts/remove | 36 ++++++++++++++++++---- scripts/restore | 40 ++++++++++++++++++++----- scripts/upgrade | 48 ++++++++++++++++++++++-------- 6 files changed, 139 insertions(+), 67 deletions(-) rename scripts/{.fonctions => _common.sh} (68%) diff --git a/scripts/.fonctions b/scripts/_common.sh similarity index 68% rename from scripts/.fonctions rename to scripts/_common.sh index 6872e5f..2da4782 100644 --- a/scripts/.fonctions +++ b/scripts/_common.sh @@ -42,7 +42,7 @@ SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_pa fi } -#================================================= + #================================================= # FUTUR YNH HELPERS #================================================= @@ -50,38 +50,6 @@ SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_pa # Ainsi, les officiels prendront le pas sur ceux-ci le cas échéant #================================================= -# Manage a fail of the script -# -# Print a warning to inform that the script was failed -# Execute the ynh_clean_setup function if used in the app script -# -# usage of ynh_clean_setup function -# This function provide a way to clean some residual of installation that not managed by remove script. -# To use it, simply add in your script: -# ynh_clean_setup () { -# instructions... -# } -# This function is optionnal. -# -# Usage: ynh_exit_properly is used only by the helper ynh_check_error. -# You must not use it directly. -ynh_exit_properly () { - exit_code=$? - if [ "$exit_code" -eq 0 ]; then - exit 0 # Exit without error if the script ended correctly - fi - - trap '' EXIT # Ignore new exit signals - set +eu # Do not exit anymore if a command fail or if a variable is empty - - echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2 - - if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script. - ynh_clean_setup # Call the function to do specific cleaning for the app. - fi - - ynh_die # Exit with error status -} # Exit if an error occurs during the execution of the script. # diff --git a/scripts/backup b/scripts/backup index f7d0cda..4d89f16 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,18 +1,48 @@ #!/bin/bash -# causes the shell to exit if any subcommand or pipeline returns a non-zero status -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source YNH helpers +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_print_info --message="Loading installation settings..." + app=$YNH_APP_INSTANCE_NAME -# Retrieve app settings domain=$(ynh_app_setting_get $app domain) -# Save sources & data -ynh_backup "/var/www/${app}" "sources" +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." -# Copy NGINX configuration -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup --src_path="/var/www/$app" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 6f3c1cd..0d6cea5 100644 --- a/scripts/install +++ b/scripts/install @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -source .fonctions +source _common.sh source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/remove b/scripts/remove index fccf315..0f6ac7d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,16 +1,42 @@ #!/bin/bash -set -u +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh source /usr/share/yunohost/helpers +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 + app=$YNH_APP_INSTANCE_NAME -# Retrieve arguments domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# REMOVE APP MAIN DIR +#================================================= + # Remove sources and configuration -ynh_secure_remove --file="/var/www/${app}" -ynh_secure_remove --file="/etc/nginx/conf.d/${domain}.d/${app}.conf" +ynh_secure_remove --file="/var/www/$app" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +ynh_secure_remove --file="/etc/nginx/conf.d/$domain.d/$app.conf" + # Reload services -sudo service nginx reload +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 73a6d51..b2d2c2f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,21 +1,47 @@ #!/bin/bash -# causes the shell to exit if any subcommand or pipeline returns a non-zero status +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + ynh_abort_if_errors -# Retrieve old app settings +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 + app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_restore_file --origin_path="/var/www/$app" -# Restore sources & data -cp -a ./sources "/var/www/${app}" +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= -# Restore Nginx and YunoHost parameters -cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= -# Reload services ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index d0972c8..5a7df1b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,10 +1,21 @@ #!/bin/bash -source .fonctions +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh source /usr/share/yunohost/helpers ynh_abort_if_errors +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 + app=$YNH_APP_INSTANCE_NAME # Récupère les infos de l'application. @@ -27,22 +38,33 @@ CHECK_PATH final_path="/var/www/${app}" ynh_app_setting_set $app final_path $final_path SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path -sudo mkdir -p "${final_path}/store/conf" -sudo cp ../conf/*.xml "${final_path}/store/conf/" +mkdir -p "${final_path}/store/conf" +cp ../conf/*.xml "${final_path}/store/conf/" -# Set permissions to jappix directory -sudo chown -R www-data: "$final_path" +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +chown -R www-data: "$final_path" # Set and copy NGINX configuraion -sudo sed -i "s@PATHTOCHANGE@${path}@g" ../conf/nginx.conf -sudo sed -i "s@ALIASTOCHANGE@${final_path}/@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" +sed -i "s@PATHTOCHANGE@${path}@g" ../conf/nginx.conf +sed -i "s@ALIASTOCHANGE@${final_path}/@g" ../conf/nginx.conf +cp ../conf/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" # Set Jappix configuration -sudo sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/hosts.xml" -sudo sed -i "s@CHANGELANG@${language}@g" "${final_path}/store/conf/main.xml" -sudo sed -i "s@CHANGENAME@${name}@g" "${final_path}/store/conf/main.xml" -sudo sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/hosts.xml" +sed -i "s@PATHTOCHANGE@${path}@g" "${final_path}/store/conf/hosts.xml" +sed -i "s@CHANGELANG@${language}@g" "${final_path}/store/conf/main.xml" +sed -i "s@CHANGENAME@${name}@g" "${final_path}/store/conf/main.xml" +sed -i "s@DOMAINTOCHANGE@${domain}@g" "${final_path}/store/conf/hosts.xml" # Reload services -sudo service nginx reload +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --last