From 98edecb0a694f4f8b3b56696a73d9338270a1a03 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 31 May 2022 03:20:11 +0200 Subject: [PATCH] Apply last example_ynh --- check_process | 6 ++++-- conf/.env.example | 2 +- conf/app.src | 5 +++-- conf/nginx.conf | 21 ++++++++++----------- manifest.json | 6 +++--- scripts/_common.sh | 2 +- scripts/backup | 4 ++++ scripts/change_url | 12 ++++++++++-- scripts/install | 9 ++++++++- scripts/restore | 20 ++++++++++++-------- scripts/upgrade | 25 ++++++++++--------------- 11 files changed, 66 insertions(+), 46 deletions(-) diff --git a/check_process b/check_process index e1b993a..570dda4 100644 --- a/check_process +++ b/check_process @@ -14,9 +14,11 @@ setup_public=1 upgrade=1 # 2.3.15~ynh1 - upgrade=1 from_commit=7497ea8b6915b725358db0d4a1210f999961cfee + upgrade=1 from_commit=7497ea8b6915b725358db0d4a1210f999961cfee # 2.4.0~ynh3 - upgrade=1 from_commit=1a0fd240d86ffaf5bcee61c176a22a7d075688a6 + upgrade=1 from_commit=1a0fd240d86ffaf5bcee61c176a22a7d075688a6 + # 2.4.0~ynh4 + upgrade=1 from_commit=6fcddf81286fb845735978ed832c9273c3b783ce backup_restore=1 multi_instance=1 port_already_use=0 diff --git a/conf/.env.example b/conf/.env.example index 6abf746..1ce10c4 100644 --- a/conf/.env.example +++ b/conf/.env.example @@ -23,7 +23,7 @@ CACHET_EMOJI=false CACHET_AUTO_TWITTER=true MAIL_DRIVER=sendmail -MAIL_HOST= +MAIL_HOST=localhost MAIL_PORT=25 MAIL_USERNAME=null MAIL_PASSWORD=null diff --git a/conf/app.src b/conf/app.src index f52595a..b0ef10a 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,6 +1,7 @@ -SOURCE_URL=https://github.com/CachetHQ/Cachet/archive/c7ad51e87645e5a717fb817616424276a8e5345b.tar.gz -SOURCE_SUM=7897744356bf81a2bcbc734f132eb5daafa889611c9c72fb2501afb3e9007cac +SOURCE_URL=https://github.com/CachetHQ/Cachet/archive/cf86f65f1dabf283d001d0f5d380f26dd5cfb64c.tar.gz +SOURCE_SUM=be48fdeacc093c9e688ecd9cef61e0304a856fcd6281066552bfecd8355fa35e SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/conf/nginx.conf b/conf/nginx.conf index 19a59ef..fc0a823 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -4,20 +4,19 @@ location __PATH__/ { # Path to source alias __FINALPATH__/public/ ; + index index.php; + more_set_headers "Strict-Transport-Security: max-age=15768000"; - index index.php; - location __PATH__ { - try_files $uri __PATH__/index.php; - } - + try_files $uri __PATH__/index.php; location ~ \.php$ { - include fastcgi_params; - fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; - fastcgi_param SCRIPT_FILENAME $request_filename; - fastcgi_index index.php; - fastcgi_keep_conn on; - more_set_headers "Strict-Transport-Security: max-age=15768000"; + fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; + + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_keep_conn on; + more_set_headers "Strict-Transport-Security: max-age=15768000"; } # Include SSOWAT user panel. diff --git a/manifest.json b/manifest.json index ab1c125..18db016 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Open source status page system", "fr": "Système de page de statut open source" }, - "version": "2.4.0~ynh4", + "version": "2.4.0~ynh5", "url": "https://cachethq.io", "upstream": { "license": "BSD-3-Clause", @@ -30,7 +30,7 @@ "mysql" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" @@ -49,7 +49,7 @@ }, "choices": ["fr", "en"], "default": "en" - }, + }, { "name": "admin", "type": "user" diff --git a/scripts/_common.sh b/scripts/_common.sh index 99d8830..ff8aedb 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,7 +6,7 @@ YNH_PHP_VERSION="7.3" -extra_php_dependencies="php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-sqlite3" +pkg_dependencies="php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-sqlite3" #================================================= # PERSONAL HELPERS diff --git a/scripts/backup b/scripts/backup index 50516c7..86cad22 100644 --- a/scripts/backup +++ b/scripts/backup @@ -14,6 +14,10 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + true +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= diff --git a/scripts/change_url b/scripts/change_url index 92cd70d..c2d713a 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -101,14 +101,22 @@ fi #================================================= # SPECIFIC MODIFICATIONS #================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +ynh_backup_if_checksum_is_different --file="$final_path/.env" +ynh_backup_if_checksum_is_different --file="$final_path/bootstrap/cachet/production.php" -ynh_script_progression --message="Updating Cachet configuration..." --weight=1 # Replace domain in Cachet configuration files ynh_replace_string --match_string="$old_domain" --replace_string="$new_domain" --target_file="$final_path/.env" ynh_replace_string --match_string="$old_domain" --replace_string="$new_domain" --target_file="$final_path/bootstrap/cachet/production.php" +ynh_store_file_checksum --file="$final_path/.env" +ynh_store_file_checksum --file="$final_path/bootstrap/cachet/production.php" + # Replace domain in Cachet database settings -ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_user" <<< "UPDATE settings SET value = 'https://$new_domain' WHERE name = 'app_domain'" +ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" <<< "UPDATE settings SET value = 'https://$new_domain' WHERE name = 'app_domain'" #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index 6627530..83f99d4 100644 --- a/scripts/install +++ b/scripts/install @@ -57,6 +57,13 @@ ynh_app_setting_set --app=$app --key=password --value=$password #================================================= # STANDARD MODIFICATIONS +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." + +ynh_install_app_dependencies $pkg_dependencies + #================================================= # CREATE DEDICATED USER #================================================= @@ -102,7 +109,7 @@ ynh_add_nginx_config ynh_script_progression --message="Configuring PHP-FPM..." --weight=8 # Create a dedicated PHP-FPM config -ynh_add_fpm_config --package="$extra_php_dependencies" +ynh_add_fpm_config #================================================= # SPECIFIC SETUP diff --git a/scripts/restore b/scripts/restore index 0ecbeab..a8ec796 100644 --- a/scripts/restore +++ b/scripts/restore @@ -71,19 +71,23 @@ chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" chown -R $app: "${final_path}/.env" "${final_path}/storage/" "${final_path}/bootstrap/" +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling dependencies..." + +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies + #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the PHP-FPM configuration..." --weight=6 +ynh_script_progression --message="Restoring the PHP-FPM configuration..." -# Restore the file first, so it can have a backup if different -ynh_restore_file --origin_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" -# Recreate a dedicated PHP-FPM config -ynh_add_fpm_config --package="$extra_php_dependencies" - -#================================================= -# SPECIFIC RESTORATION #================================================= # RESTORE THE MYSQL DATABASE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 1f9c995..335cdcd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -71,7 +71,7 @@ fi ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -80,21 +80,9 @@ ynh_system_user_create --username=$app if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=1 - # Backup essential configuration files - tmpdir=$(mktemp -d) - mv $final_path/.env $tmpdir - mv $final_path/bootstrap/cachet/production.php $tmpdir - - # Remove every old application files - ynh_secure_remove --file="$final_path" # /bootstrap/cache/* # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" - - # Restore configuration files - mv $tmpdir/.env $final_path - mv $tmpdir/production.php $final_path/bootstrap/cachet/ - ynh_secure_remove --file="$tmpdir" + ynh_setup_source --dest_dir="$final_path" --keep=".env bootstrap/cachet/production.php" fi chmod 750 "$final_path" @@ -110,13 +98,20 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated NGINX config ynh_add_nginx_config +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." + +ynh_install_app_dependencies $pkg_dependencies + #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 # Create a dedicated PHP-FPM config -ynh_add_fpm_config --package="$extra_php_dependencies" +ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE