From d9b1e8bad82c50e7cc93f2d345157418e28201bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 22 Nov 2020 23:03:06 +0100 Subject: [PATCH 1/8] Fix linter warnings --- manifest.json | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/manifest.json b/manifest.json index 1962914..293b7eb 100644 --- a/manifest.json +++ b/manifest.json @@ -1,25 +1,25 @@ { - "packaging_format": 1, - "id": "jappix", "name": "Jappix", + "id": "jappix", + "packaging_format": 1, "description": { "en": "A free social network", "fr": "Un réseau social libre" }, "url": "https://jappix.org/", - "license": "AGPL-3", - "version": "1.1.7", + "license": "AGPL-3.0-only", + "version": "1.1.7~ynh1", "maintainer": { "name": "titoko", "email": "titoko@titoko.fr" }, "multi_instance": false, "requirements": { - "yunohost": ">> 2.3.15" + "yunohost": ">> 3.8.1" }, "services": [ "nginx", - "php5-fpm", + "php7.0-fpm", "metronome" ], "arguments": { @@ -45,6 +45,7 @@ }, { "name": "name", + "type": "string", "ask": { "en": "Choose a name for Jappix", "fr": "Choisissez un nom pour Jappix" @@ -54,6 +55,7 @@ }, { "name": "language", + "type": "string", "ask": { "en": "Choose the default language of Jappix", "fr": "Choissisez la langue par défaut de Jappix" From 179845cc2d9c2a0f298ac23948d5837813e68160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 22 Nov 2020 23:05:45 +0100 Subject: [PATCH 2/8] Fix linter warnings --- scripts/remove | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/remove b/scripts/remove index da603b9..fccf315 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,8 +9,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) # Remove sources and configuration -sudo rm -rf "/var/www/${app}" -sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" +ynh_secure_remove --file="/var/www/${app}" +ynh_secure_remove --file="/etc/nginx/conf.d/${domain}.d/${app}.conf" # Reload services sudo service nginx reload From d3a98613965fcdcca3f15802edda2db5c0b06b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 22 Nov 2020 23:08:26 +0100 Subject: [PATCH 3/8] Fix linter warning --- scripts/upgrade | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 4e4e187..d0972c8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,9 +1,10 @@ #!/bin/bash -set -eu source .fonctions source /usr/share/yunohost/helpers +ynh_abort_if_errors + app=$YNH_APP_INSTANCE_NAME # Récupère les infos de l'application. From bf5482b195b21d311ea3b85e93c7ef7227b494e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 22 Nov 2020 23:10:08 +0100 Subject: [PATCH 4/8] Fix linter warning --- scripts/restore | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/restore b/scripts/restore index bffce4b..73a6d51 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,19 +1,21 @@ #!/bin/bash # causes the shell to exit if any subcommand or pipeline returns a non-zero status -set -eu + source /usr/share/yunohost/helpers +ynh_abort_if_errors + # Retrieve old app settings app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) # Restore sources & data -sudo cp -a ./sources "/var/www/${app}" +cp -a ./sources "/var/www/${app}" # Restore Nginx and YunoHost parameters -sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" +cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" # Reload services -sudo service nginx reload +ynh_systemd_action --service_name=nginx --action=reload From 463b065e4a1b7aa008506eef68da923cc77062a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 22 Nov 2020 23:23:32 +0100 Subject: [PATCH 5/8] Fix linter --- scripts/install | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/install b/scripts/install index a85cd5f..6f3c1cd 100644 --- a/scripts/install +++ b/scripts/install @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers # MANAGE FAILURE OF THE SCRIPT #================================================= -ynh_check_error # Active trap pour arrêter le script si une erreur est détectée. +ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST @@ -24,8 +24,8 @@ path=$YNH_APP_ARG_PATH name=$YNH_APP_ARG_NAME language=$YNH_APP_ARG_LANGUAGE - app=$YNH_APP_INSTANCE_NAME + #================================================= # Check domain/path availability #================================================= @@ -49,22 +49,22 @@ 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" +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" #================================================= # Validate language @@ -77,12 +77,13 @@ sudo 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 From b6428a51ef58fd516f52ad56425a9ac695c12270 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 22 Nov 2020 23:36:37 +0100 Subject: [PATCH 6/8] 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 From 9ec28d9bd6130256f3d38d32c3431652d1860ceb Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 22 Nov 2020 23:37:54 +0100 Subject: [PATCH 7/8] Update nginx.conf --- conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index d8528fd..956d94b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,4 @@ -location PATHTOCHANGE { +location PATHTOCHANGE/ { alias ALIASTOCHANGE ; if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; From 3f1bbff7f37aabef77ad4bff9f63dd03d15fbf77 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 22 Nov 2020 23:42:19 +0100 Subject: [PATCH 8/8] Update nginx.conf --- conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 956d94b..d8528fd 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,4 @@ -location PATHTOCHANGE/ { +location PATHTOCHANGE { alias ALIASTOCHANGE ; if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent;