From a2f37b8e277ba173b53f73320514f1fc7f3aa3ac Mon Sep 17 00:00:00 2001 From: YliesC Date: Fri, 20 Oct 2017 19:06:13 +0200 Subject: [PATCH] [fix] patch bugs --- check_process | 9 +++--- manifest.json | 9 +++--- scripts/backup | 56 ++++++++++++++++++++++++++------ scripts/install | 24 +++++++++++--- scripts/remove | 72 +++++++++++++++++++++++++++++++++++++---- scripts/restore | 86 +++++++++++++++++++++++++++++++++---------------- scripts/upgrade | 67 ++++++++++++++++++++++++++++++-------- 7 files changed, 253 insertions(+), 70 deletions(-) diff --git a/check_process b/check_process index 674bd30..f20b174 100644 --- a/check_process +++ b/check_process @@ -7,8 +7,9 @@ admin="john" (USER) language="fr" is_public=1 (PUBLIC|public=1|private=0) - password="pass" - port="666" (PORT) + author="john" + password="pass" + port="666" (PORT) ; Checks pkg_linter=1 setup_sub_dir=1 @@ -20,7 +21,7 @@ backup_restore=1 multi_instance=1 incorrect_path=1 - port_already_use=1 + port_already_use=0 change_url=0 ;;; Levels Level 1=auto @@ -37,4 +38,4 @@ Level 10=0 ;;; Options Email= -Notification=none \ No newline at end of file +Notification=none diff --git a/manifest.json b/manifest.json index f8997a4..8c4a0f3 100644 --- a/manifest.json +++ b/manifest.json @@ -6,16 +6,16 @@ "en": "Pelican Static Site Generator", "fr": "Pelican, un générateur de blog statique" }, - "version": "3.7.1", + "version": "1.0", "url": "https://thegoldenkoala.com", - "license": "GPLv3", + "license": "free", "maintainer": { "name": "Ylies Chahi", "email": "ylieschahi@gmail.com", "url": "http://thegoldenkoala.com" }, "requirements": { - "yunohost": ">= 2.4" + "yunohost": ">= 2.7.2" }, "multi_instance": true, "services": [ @@ -49,7 +49,8 @@ "en": "Choose an author", "fr": "Choisissez l'auteur" }, - "example": "johndoe" + "example": "johndoe", + "default": "John Doe" }, { "name": "title", diff --git a/scripts/backup b/scripts/backup index 797bf4c..78c79c8 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,20 +1,56 @@ #!/bin/bash -# Exit on command errors and treat access to unset variables as an error -set -eu + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors # Source YNH helpers -. /usr/share/yunohost/helpers +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= app=$YNH_APP_INSTANCE_NAME -# Retrieve arguments -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) -is_public=$(ynh_app_setting_get "$app" is_public) +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app db_name) -# Copy the app source files -ynh_backup "/var/www/$app" "www" +--------- +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup "$final_path" # Copy the conf files -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" diff --git a/scripts/install b/scripts/install index d0224df..2ca29df 100644 --- a/scripts/install +++ b/scripts/install @@ -1,19 +1,33 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source app helpers and functions +source _common.sh source /usr/share/yunohost/helpers -# Retrieve arguments -app=$YNH_APP_INSTANCE_NAME +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC author=$YNH_APP_ARG_AUTHOR title=$YNH_APP_ARG_TITLE +app=$YNH_APP_INSTANCE_NAME + #force location to be / or /foo location=${path:-/} diff --git a/scripts/remove b/scripts/remove index 33c094a..2ddad7d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,17 +1,77 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -u +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source app helpers source /usr/share/yunohost/helpers +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME + domain=$(ynh_app_setting_get $app domain) +port=$(ynh_app_setting_get $app port) +db_name=$(ynh_app_setting_get $app db_name) +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# STANDARD REMOVE +#================================================= +# STOP AND REMOVE SERVICE +#================================================= + +# Remove the dedicated systemd config +ynh_remove_systemd_config + +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +if yunohost service status | grep -q $app +then + echo "Remove $app service" + yunohost service remove $app +fi + +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + +#================================================= +# REMOVE APP MAIN DIR +#================================================= + +# Remove the app directory securely +ynh_secure_remove "$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# CLOSE A PORT +#================================================= + +if yunohost firewall list | grep -q "\- $port$" +then + echo "Close port $port" + yunohost firewall disallow TCP $port 2>&1 +fi # Delete app directory and configurations -sudo rm -rf "/var/www/"${app:-preventunsetvariable} -[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" +#sudo rm -rf "/var/www/"${app:-preventunsetvariable} +#[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" # Reload services -sudo service nginx reload || true +#sudo service nginx reload || true diff --git a/scripts/restore b/scripts/restore index 5969a0b..1cd1676 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,45 +1,72 @@ #!/bin/bash -# Exit on command errors and treat access to unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source app helpers and functions source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME -# Retrieve arguments -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) -is_public=$(ynh_app_setting_get "$app" is_public) +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +final_path=$(ynh_app_setting_get $app final_path) -# is_public is now a boolean field +# is_public is now a boolean field if [ "$is_public" = "Yes" ]; then is_public=1 fi -# Check domain/path availability -sudo yunohost app checkurl $domain$path -a $app \ - || ynh_die "The path ${domain}${path} is not available for app installation." +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= -# Check destination directory -DESTDIR="/var/www/$app" -[[ -d $DESTDIR ]] && ynh_die \ -"The destination directory '$DESTDIR' already exists.\ - You should safely delete it before restoring this app." +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " -# Check configuration files -NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf" -[[ -f $NGINX_CONF ]] && ynh_die \ -"The NGINX configuration already exists at '${NGINX_CONF}'. - You should safely delete it before restoring this app." +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= -# Restore the app files -sudo cp -a ./www "$DESTDIR" +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + +ynh_restore_file "$final_path" + +#================================================= +# RESTORE USER RIGHTS +#================================================= + +# Restore permissions on app files +chown -R root: $final_path + +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add $app --log "/var/log/$app/APP.log" -# Restore configuration files -sudo cp -a ./conf/nginx.conf "$NGINX_CONF" # Make app public if necessary [[ $is_public -eq 1 ]] \ @@ -47,5 +74,10 @@ sudo cp -a ./conf/nginx.conf "$NGINX_CONF" fi -# Reload Nginx and regenerate SSOwat conf -sudo service nginx reload +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= + +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index 973d740..aff8dcd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,25 +1,64 @@ #!/bin/bash -# Source app helpers and functions +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + source /usr/share/yunohost/helpers -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# LOAD SETTINGS +#================================================= -# Retrieve arguments app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) -is_public=$(ynh_app_setting_get "$app" is_public) -author=$(ynh_app_setting_get "$app" author) -title=$(ynh_app_setting_get "$app" title) -# is_public is now a boolean field -if [ "$is_public" = "Yes" ]; -then - is_public=1 +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +admin=$(ynh_app_setting_get $app admin) +is_public=$(ynh_app_setting_get $app is_public) +final_path=$(ynh_app_setting_get $app final_path) +port=$(ynh_app_setting_get $app port) +author=$(ynh_app_setting_get $app author) +title=$(ynh_app_setting_get $app title) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set $app is_public 0 + is_public=0 fi +# If final_path doesn't exist, create it +if [ -z $final_path ]; then + final_path=/var/www/$app + ynh_app_setting_set $app final_path $final_path +fi + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# 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 +#================================================= + #force location to be / or /foo location=${path:-/} @@ -51,6 +90,6 @@ sudo chown -hR www-data:www-data $document_root # Make app public if necessary [[ $is_public -eq 1 ]] \ && ynh_app_setting_set "$app" unprotected_uris "/" - + # Reload Nginx and regenerate SSOwat conf sudo service nginx reload