From a625ad79da67dcd74f43dc7fd6a74477c4ba8172 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Mon, 28 Aug 2017 23:55:51 +0200 Subject: [PATCH 1/5] [enh] Some corrections --- check_process | 2 +- conf/app.src | 2 +- conf/php-fpm.ini | 4 +- manifest.json | 3 +- scripts/_common.sh | 110 --------------------------------------------- scripts/backup | 16 +++---- scripts/install | 8 ++-- scripts/remove | 5 ++- scripts/restore | 2 +- scripts/upgrade | 24 ++++++++-- 10 files changed, 42 insertions(+), 134 deletions(-) diff --git a/check_process b/check_process index 030355f..704a61c 100644 --- a/check_process +++ b/check_process @@ -20,7 +20,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 diff --git a/conf/app.src b/conf/app.src index 20f3c51..e4dd89f 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,6 +1,6 @@ SOURCE_URL=url of app's source SOURCE_SUM=sha256 checksum -SOURCE_SUM_PRG=sha256 +SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true SOURCE_FILENAME= diff --git a/conf/php-fpm.ini b/conf/php-fpm.ini index 27a4207..5c27d59 100644 --- a/conf/php-fpm.ini +++ b/conf/php-fpm.ini @@ -1,9 +1,9 @@ -# Common values to change to increase file upload limit +; Common values to change to increase file upload limit ; upload_max_filesize = 50M ; post_max_size = 50M ; mail.add_x_header = Off -# Other common parameters +; Other common parameters ; max_execution_time = 600 ; max_input_time = 300 ; memory_limit = 256M diff --git a/manifest.json b/manifest.json index a1f7b55..0179154 100644 --- a/manifest.json +++ b/manifest.json @@ -6,6 +6,7 @@ "en": "Example package for YunoHost application.", "fr": "Exemple de package d’application pour YunoHost." }, + "version": "1.0", "url": "https://example.com", "license": "free", "maintainer": { @@ -14,7 +15,7 @@ "url": "http://example.com" }, "requirements": { - "yunohost": ">= 2.6.4" + "yunohost": ">= 2.7.2" }, "multi_instance": true, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index 0f53f77..05a7907 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,112 +1,2 @@ #!/bin/bash -# ============================================================================= -# YUNOHOST 2.7 FORTHCOMING HELPERS -# ============================================================================= - -# Create a dedicated nginx config -# -# usage: ynh_add_nginx_config -ynh_add_nginx_config () { - finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalnginxconf" - sudo cp ../conf/nginx.conf "$finalnginxconf" - - # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. - # Substitute in a nginx config file only if the variable is not empty - if test -n "${path_url:-}"; then - ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf" - fi - if test -n "${domain:-}"; then - ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf" - fi - if test -n "${port:-}"; then - ynh_replace_string "__PORT__" "$port" "$finalnginxconf" - fi - if test -n "${app:-}"; then - ynh_replace_string "__NAME__" "$app" "$finalnginxconf" - fi - if test -n "${final_path:-}"; then - ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf" - fi - ynh_store_file_checksum "$finalnginxconf" - - sudo systemctl reload nginx -} - -# Remove the dedicated nginx config -# -# usage: ynh_remove_nginx_config -ynh_remove_nginx_config () { - ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo systemctl reload nginx -} - -# Create a dedicated php-fpm config -# -# usage: ynh_add_fpm_config -ynh_add_fpm_config () { - finalphpconf="/etc/php5/fpm/pool.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalphpconf" - sudo cp ../conf/php-fpm.conf "$finalphpconf" - ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf" - ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf" - ynh_replace_string "__USER__" "$app" "$finalphpconf" - sudo chown root: "$finalphpconf" - ynh_store_file_checksum "$finalphpconf" - - if [ -e "../conf/php-fpm.ini" ] - then - finalphpini="/etc/php5/fpm/conf.d/20-$app.ini" - ynh_backup_if_checksum_is_different "$finalphpini" - sudo cp ../conf/php-fpm.ini "$finalphpini" - sudo chown root: "$finalphpini" - ynh_store_file_checksum "$finalphpini" - fi - - sudo systemctl reload php5-fpm -} - -# Remove the dedicated php-fpm config -# -# usage: ynh_remove_fpm_config -ynh_remove_fpm_config () { - ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf" - ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1 - sudo systemctl reload php5-fpm -} - -# Create a dedicated systemd config -# -# usage: ynh_add_systemd_config -ynh_add_systemd_config () { - finalsystemdconf="/etc/systemd/system/$app.service" - ynh_backup_if_checksum_is_different "$finalsystemdconf" - sudo cp ../conf/systemd.service "$finalsystemdconf" - - # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. - # Substitute in a nginx config file only if the variable is not empty - if test -n "${final_path:-}"; then - ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" - fi - if test -n "${app:-}"; then - ynh_replace_string "__APP__" "$app" "$finalsystemdconf" - fi - ynh_store_file_checksum "$finalsystemdconf" - - sudo chown root: "$finalsystemdconf" - sudo systemctl enable $app - sudo systemctl daemon-reload -} - -# Remove the dedicated systemd config -# -# usage: ynh_remove_systemd_config -ynh_remove_systemd_config () { - finalsystemdconf="/etc/systemd/system/$app.service" - if [ -e "$finalsystemdconf" ]; then - sudo systemctl stop $app - sudo systemctl disable $app - ynh_secure_remove "$finalsystemdconf" - fi -} diff --git a/scripts/backup b/scripts/backup index 7764d59..297ea1d 100755 --- a/scripts/backup +++ b/scripts/backup @@ -30,7 +30,6 @@ app=$YNH_APP_INSTANCE_NAME 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) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) #================================================= # STANDARD BACKUP STEPS @@ -38,27 +37,26 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd) # BACKUP THE APP MAIN DIR #================================================= -ynh_backup "$final_path" "${backup_dir}$final_path" +ynh_backup "$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "${backup_dir}/etc/php5/fpm/pool.d/$app.conf" -ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "${backup_dir}/etc/php5/fpm/conf.d/20-$app.ini" +ynh_backup "/etc/php5/fpm/pool.d/$app.conf" +ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" #================================================= # BACKUP THE MYSQL DATABASE #================================================= ynh_mysql_dump_db "$db_name" > db.sql -ynh_backup "db.sql" "${backup_dir}/db.sql" #================================================= # SPECIFIC BACKUP @@ -66,16 +64,16 @@ ynh_backup "db.sql" "${backup_dir}/db.sql" # BACKUP LOGROTATE #================================================= -ynh_backup "/etc/logrotate.d/$app" "${backup_dir}/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup "/etc/systemd/system/$app.service" "${backup_dir}/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP THE CRON FILE #================================================= -ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app" +ynh_backup "/etc/cron.d/$app" diff --git a/scripts/install b/scripts/install index 8bd3d26..99f09e7 100755 --- a/scripts/install +++ b/scripts/install @@ -42,6 +42,9 @@ app=$YNH_APP_INSTANCE_NAME # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +final_path=/var/www/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" + # Normalize the url path syntax path_url=$(ynh_normalize_url_path $path_url) @@ -50,9 +53,6 @@ ynh_webpath_available $domain $path_url # Register (book) web path ynh_webpath_register $app $domain $path_url -final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" - #================================================= # STORE SETTINGS FROM MANIFEST #================================================= @@ -118,7 +118,7 @@ ynh_system_user_create $app #================================================= # Create a dedicated php-fpm config -ynh_fpm_config +ynh_add_fpm_config #================================================= # SPECIFIC SETUP diff --git a/scripts/remove b/scripts/remove index fbd8064..4367e39 100755 --- a/scripts/remove +++ b/scripts/remove @@ -18,6 +18,7 @@ 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 @@ -57,7 +58,7 @@ ynh_mysql_remove_db $db_name $db_name #================================================= # Remove the app directory securely -ynh_secure_remove "/var/www/$app" +ynh_secure_remove "$final_path" #================================================= # REMOVE NGINX CONFIGURATION @@ -87,7 +88,7 @@ ynh_remove_logrotate if yunohost firewall list | grep -q "\- $port$" then echo "Close port $port" - QUIET yunohost firewall disallow TCP $port + yunohost firewall disallow TCP $port 2>&1 fi #================================================= diff --git a/scripts/restore b/scripts/restore index e29e9ed..6889fc7 100755 --- a/scripts/restore +++ b/scripts/restore @@ -36,7 +36,7 @@ db_name=$(ynh_app_setting_get $app db_name) # CHECK IF THE APP CAN BE RESTORED #================================================= -yunohost app checkurl "${domain}${path_url}" -a "$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 " diff --git a/scripts/upgrade b/scripts/upgrade index c0b3296..c8d2304 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,19 +27,37 @@ db_name=$(ynh_app_setting_get $app db_name) # ENSURE DOWNWARD COMPATIBILITY #================================================= +# Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value + 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 [ -z $db_name ]; then # If db_name doesn't exist, create it +# If db_name doesn't exist, create it +if [ -z $db_name ]; then db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name fi +# If final_path doesn't exist, create it +if [ -z $final_path ]; then + final_path=$(ynh_sanitize_dbid $app) + ynh_app_setting_set $app final_path $final_path +fi + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +ynh_backup_before_upgrade # Backup the current version of the app +ynh_clean_setup () { + ynh_restore_upgradebackup # restore it if the upgrade fails +} +ynh_abort_if_errors # Exit if an error occurs during the execution of the script + #================================================= # CHECK THE PATH #================================================= @@ -75,7 +93,7 @@ ynh_system_user_create $app #================================================= # Create a dedicated php-fpm config -ynh_fpm_config +ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE From 5ef1d077527fbfa627501487eb42535fbd2d206e Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 5 Sep 2017 17:47:31 +0200 Subject: [PATCH 2/5] Add a systemd default file --- conf/systemd.service | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 conf/systemd.service diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..76cdf64 --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,13 @@ +[Unit] +Description=Small description of the service +After=network.target + +[Service] +Type=simple +User=__APP__ +Group=__APP__ +WorkingDirectory=__FINALPATH__/ +ExecStart=__FINALPATH__/script >> /var/log/__APP__/__APP__.log 2>&1 + +[Install] +WantedBy=multi-user.target From 5039df052d74abbffadb713c55f11e8a51de75a0 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 5 Sep 2017 17:48:23 +0200 Subject: [PATCH 3/5] Small corrections --- check_process | 4 ++-- scripts/backup | 14 +++++++------- scripts/install | 8 +++++++- scripts/restore | 16 ++++++++-------- scripts/upgrade | 11 +++++++---- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/check_process b/check_process index 704a61c..29c0fd5 100644 --- a/check_process +++ b/check_process @@ -7,8 +7,8 @@ admin="john" (USER) language="fr" is_public=1 (PUBLIC|public=1|private=0) - password="pass" - port="666" (PORT) + password="pass" + port="666" (PORT) ; Checks pkg_linter=1 setup_sub_dir=1 diff --git a/scripts/backup b/scripts/backup index 297ea1d..7c88c04 100755 --- a/scripts/backup +++ b/scripts/backup @@ -2,13 +2,6 @@ #================================================= # GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat access to unset variables as an error -set -eu - #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -21,6 +14,13 @@ fi source _common.sh 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 #================================================= diff --git a/scripts/install b/scripts/install index 99f09e7..6a4bcfa 100755 --- a/scripts/install +++ b/scripts/install @@ -141,7 +141,7 @@ ynh_systemd_config chown -R $app: $final_path # Set the app as temporarily public for curl call -ynh_app_setting_set $app unprotected_uris "/" +ynh_app_setting_set $app skipped_uris "/" # Reload SSOwat config yunohost app ssowatconf @@ -151,6 +151,12 @@ systemctl reload nginx # Installation with curl ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" +#================================================= +# MODIFY A CONFIG FILE +#================================================= + +ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE" + #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #================================================= diff --git a/scripts/restore b/scripts/restore index 6889fc7..73ac8e3 100755 --- a/scripts/restore +++ b/scripts/restore @@ -2,13 +2,6 @@ #================================================= # GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat access to unset variables as an error -set -eu - #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -21,6 +14,13 @@ fi source _common.sh 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 #================================================= @@ -113,7 +113,7 @@ systemctl enable $app.service ynh_restore_file "/etc/cron.d/$app" #================================================= -# BACKUP THE LOGROTATE CONFIGURATION +# RESTORE THE LOGROTATE CONFIGURATION #================================================= ynh_restore_file "/etc/logrotate.d/$app" diff --git a/scripts/upgrade b/scripts/upgrade index c8d2304..415963e 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -44,7 +44,7 @@ fi # If final_path doesn't exist, create it if [ -z $final_path ]; then - final_path=$(ynh_sanitize_dbid $app) + final_path=/var/www/$app ynh_app_setting_set $app final_path $final_path fi @@ -52,11 +52,14 @@ fi # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_backup_before_upgrade # Backup the current version of the app +# Backup the current version of the app +ynh_backup_before_upgrade ynh_clean_setup () { - ynh_restore_upgradebackup # restore it if the upgrade fails + # restore it if the upgrade fails + ynh_restore_upgradebackup } -ynh_abort_if_errors # Exit if an error occurs during the execution of the script +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # CHECK THE PATH From 73999433b21aeab0a5dcf2ab2c081ea73440194b Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Wed, 13 Sep 2017 14:04:53 +0200 Subject: [PATCH 4/5] Update and rename check_process to check_process.default --- check_process => check_process.default | 3 +++ 1 file changed, 3 insertions(+) rename check_process => check_process.default (89%) diff --git a/check_process b/check_process.default similarity index 89% rename from check_process rename to check_process.default index 29c0fd5..d7e2812 100644 --- a/check_process +++ b/check_process.default @@ -1,5 +1,8 @@ # See here for more informations # https://github.com/YunoHost/package_check#syntax-check_process-file + +# Move this file from check_process.default to check_process when you have filled it. + ;; Test complet ; Manifest domain="domain.tld" (DOMAIN) From bc052a6ed411ce65d6b9293111526039d4103655 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Fri, 29 Sep 2017 13:32:52 +0200 Subject: [PATCH 5/5] [fix] Clean useless version --- manifest.json | 1 - 1 file changed, 1 deletion(-) diff --git a/manifest.json b/manifest.json index 60758e5..0179154 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,6 @@ "version": "1.0", "url": "https://example.com", "license": "free", - "version": "1.0", "maintainer": { "name": "John doe", "email": "john.doe@example.com",