From 2e7cced587a7cc8390e68e232cd4f6bfff2d33e8 Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 30 Dec 2021 07:31:27 +0100 Subject: [PATCH 1/7] Use ynh_install_app_dependencies for cleaner installation / removal Also don't output warning about package not being found on removal it is a normal case: running ynh_remove_app_dependencies produces it --- scripts/install | 3 ++- scripts/remove | 7 +++++-- scripts/upgrade | 9 ++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index 29a76b9..8fa2f6d 100644 --- a/scripts/install +++ b/scripts/install @@ -76,7 +76,8 @@ ynh_add_nginx_config ynh_script_progression --message="Configuring PHP-FPM..." --weight=5 # Create a dedicated PHP-FPM config -ynh_add_fpm_config --package="$extra_php_dependencies" +ynh_install_app_dependencies "$extra_php_dependencies" +ynh_add_fpm_config #================================================= # ADD A CONFIGURATION diff --git a/scripts/remove b/scripts/remove index 222ce56..8c4ebd5 100644 --- a/scripts/remove +++ b/scripts/remove @@ -41,10 +41,13 @@ ynh_remove_nginx_config ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=2 # Remove the app dependencies installed along with php-fpm -# ynh_remove_app_dependencies +ynh_remove_app_dependencies # Remove the dedicated PHP-FPM config -ynh_remove_fpm_config --package="$extra_php_dependencies" +# NB: If there is a warning because it cannot locate the garradin-ynh-deps package, ignore +# It's just it has been removed before. +# https://github.com/YunoHost/yunohost/blob/509ba1e8a28e0be598aa0617eda06669b7b0f1d8/data/helpers.d/php#L284-L287 +ynh_remove_fpm_config 2> >(grep -v 'WARNING E: Unable to locate package') #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 98e376a..d2ec51c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -97,7 +97,8 @@ then # Set permissions on app files ynh_system_user_create --username=$app ynh_add_nginx_config - ynh_add_fpm_config --package="$extra_php_dependencies" + ynh_install_app_dependencies "$extra_php_dependencies" + ynh_add_fpm_config phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) ynh_script_progression --message="restore data..." --weight=10 @@ -144,7 +145,8 @@ then # Set permissions on app files ynh_system_user_create --username=$app ynh_add_nginx_config - ynh_add_fpm_config --package="$extra_php_dependencies" + ynh_install_app_dependencies "$extra_php_dependencies" + ynh_add_fpm_config phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) ynh_script_progression --message="restore data..." --weight=10 @@ -213,7 +215,8 @@ ynh_add_nginx_config ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2 # Create a dedicated PHP-FPM config -ynh_add_fpm_config --package="$extra_php_dependencies" +ynh_install_app_dependencies "$extra_php_dependencies" +ynh_add_fpm_config #======================================================= # backup bdd, squelettes directory and config.local.php From 92b105e43db05dc912e5a9877096abeb785577a7 Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 30 Dec 2021 14:12:37 +0100 Subject: [PATCH 2/7] Split config into several files --- conf/config.local.php | 9 ++++++ conf/config.local.release.php | 51 ------------------------------ conf/config.local.user.php | 13 ++++++++ conf/config.local.yunohost.php | 58 ++++++++++++++++++++++++++++++++++ scripts/_common.sh | 2 +- scripts/install | 23 ++++++-------- scripts/upgrade | 19 +++++------ 7 files changed, 101 insertions(+), 74 deletions(-) create mode 100644 conf/config.local.php delete mode 100644 conf/config.local.release.php create mode 100644 conf/config.local.user.php create mode 100644 conf/config.local.yunohost.php diff --git a/conf/config.local.php b/conf/config.local.php new file mode 100644 index 0000000..82b5400 --- /dev/null +++ b/conf/config.local.php @@ -0,0 +1,9 @@ +> $final_path/config.local.php +ynh_add_config --template="config.local.php" --destination="$final_path/config.local.php" +ynh_add_config --template="config.local.yunohost.php" --destination="$final_path/config.local.yunohost.php" +# NOTE: Don't overwrite config.local.user.php # Permissions on files and directories chmod -R o-rwx "$final_path" @@ -269,8 +270,9 @@ find "$final_path" -type d -exec chmod 550 {} + find "$final_path" -type f -exec chmod 440 {} + find "$final_path/data" -type d -exec chmod 770 {} + find "$final_path/data" -type f -exec chmod 660 {} + -chmod 660 "$final_path/config.local.php" -chmod 660 "$final_path/config.local.release.php" +chmod 440 "$final_path/config.local.php" +chmod 440 "$final_path/config.local.yunohost.php" +chmod 660 "$final_path/config.local.user.php" #================================================= # RELOAD NGINX @@ -285,7 +287,6 @@ ynh_systemd_action --service_name=nginx --action=reload ynh_script_progression --message="Finalise upgrade" --weight=1 ynh_local_curl "/admin/index.php" -chmod 440 "$final_path/config.local.php" #================================================= # END OF SCRIPT From 441755d9fbab98975f69d68ef74a87063dd13ed9 Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 30 Dec 2021 16:00:13 +0100 Subject: [PATCH 3/7] Fix change_url and add test cases for upgrade --- check_process | 10 +++++++++- scripts/change_url | 11 ++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/check_process b/check_process index 6d24bc6..87a0cef 100644 --- a/check_process +++ b/check_process @@ -12,6 +12,8 @@ setup_public=1 upgrade=1 upgrade=1 from_commit=7205455e0a806a49c48c6d2f005d80d1b74a3355 + upgrade=1 from_commit=fc55308f7521310d5c339139339896bb59bd73cd + upgrade=1 from_commit=e5dd30afa6a618344c9e7b927839d4e9ac8bfc56 backup_restore=1 multi_instance=1 change_url=1 @@ -20,5 +22,11 @@ Email= Notification=none ;;; Upgrade options ; commit=7205455e0a806a49c48c6d2f005d80d1b74a3355 - name=Merge pull request #55 from yunohost-bot/issue-and-pr-template + name=Previous version + manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& + ; commit=fc55308f7521310d5c339139339896bb59bd73cd + name=Version 0.9.5 + manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& + ; commit=e5dd30afa6a618344c9e7b927839d4e9ac8bfc56 + name=Version 1.0.3~ynh2 manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& diff --git a/scripts/change_url b/scripts/change_url index 594268b..0035ee1 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -20,6 +20,7 @@ new_domain=$YNH_APP_NEW_DOMAIN new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME +secret_key=$(ynh_string_random --length=50) #================================================= # LOAD SETTINGS @@ -81,15 +82,7 @@ then path_url="$new_path" # Create a dedicated NGINX config ynh_add_nginx_config -fi - -# change the config.local.conf -if [ $change_path -eq 1 ] && [ "$new_path" == "/" ]; then - ynh_replace_string --match_string="const WWW_URI = '$old_path/';" --replace_string="const WWW_URI = '$new_path';" --target_file="$final_path/config.local.php" -elif [ $change_path -eq 1 ] && [ "$old_path" == "/" ]; then - ynh_replace_string --match_string="const WWW_URI = '$old_path';" --replace_string="const WWW_URI = '$new_path/';" --target_file="$final_path/config.local.php" -elif [ $change_path -eq 1 ]; then - ynh_replace_string --match_string="const WWW_URI = '$old_path/';" --replace_string="const WWW_URI = '$new_path/';" --target_file="$final_path/config.local.php" + ynh_add_config --template="config.local.yunohost.php" --destination="$final_path/config.local.yunohost.php" fi # Change the domain for NGINX From 8366a5fa240d9bf1f5d973cdf1a249b0c09a1c8d Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 30 Dec 2021 20:14:13 +0100 Subject: [PATCH 4/7] Pre-upgrade script for chown + fixes --- check_process | 14 +++++++------- scripts/restore | 4 +++- scripts/upgrade | 4 ++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/check_process b/check_process index 87a0cef..89a9335 100644 --- a/check_process +++ b/check_process @@ -1,4 +1,8 @@ ; Test complet + ; pre-upgrade + if [ "$FROM_COMMIT" == "04e1730ff642a2e48dfb533b2136fe90f9eaf133" ]; then + chmod -R o-rwx /var/www/garradin + fi ; Manifest domain="domain.tld" path="/path" @@ -12,8 +16,7 @@ setup_public=1 upgrade=1 upgrade=1 from_commit=7205455e0a806a49c48c6d2f005d80d1b74a3355 - upgrade=1 from_commit=fc55308f7521310d5c339139339896bb59bd73cd - upgrade=1 from_commit=e5dd30afa6a618344c9e7b927839d4e9ac8bfc56 + upgrade=1 from_commit=04e1730ff642a2e48dfb533b2136fe90f9eaf133 backup_restore=1 multi_instance=1 change_url=1 @@ -24,9 +27,6 @@ Notification=none ; commit=7205455e0a806a49c48c6d2f005d80d1b74a3355 name=Previous version manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& - ; commit=fc55308f7521310d5c339139339896bb59bd73cd - name=Version 0.9.5 - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& - ; commit=e5dd30afa6a618344c9e7b927839d4e9ac8bfc56 - name=Version 1.0.3~ynh2 + ; commit=04e1730ff642a2e48dfb533b2136fe90f9eaf133 + name=Version 1.0.6~ynh1 manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& diff --git a/scripts/restore b/scripts/restore index d702b05..a4dfe8a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -71,7 +71,9 @@ find "$final_path" -type d -exec chmod 550 {} + find "$final_path" -type f -exec chmod 440 {} + find "$final_path/data" -type d -exec chmod 770 {} + find "$final_path/data" -type f -exec chmod 660 {} + -chmod 660 "$final_path/config.local.php" +chmod 440 "$final_path/config.local.php" +chmod 440 "$final_path/config.local.yunohost.php" +chmod 660 "$final_path/config.local.user.php" #================================================= # RESTORE THE PHP-FPM CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index 5e9f4b2..dedde73 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -259,6 +259,10 @@ fi #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=5 +if ynh_compare_current_package_version --comparison lt --version 1.1.15~ynh1; then + ynh_add_config --template="config.local.user.php" --destination="$final_path/config.local.user.php" +fi + ynh_add_config --template="config.local.php" --destination="$final_path/config.local.php" ynh_add_config --template="config.local.yunohost.php" --destination="$final_path/config.local.yunohost.php" # NOTE: Don't overwrite config.local.user.php From 866b07346053be4b378553ae9ba8045ddf0633e8 Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 30 Dec 2021 22:22:08 +0100 Subject: [PATCH 5/7] Update comments --- conf/config.local.php | 4 ++-- conf/config.local.yunohost.php | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/conf/config.local.php b/conf/config.local.php index 82b5400..e9b8a71 100644 --- a/conf/config.local.php +++ b/conf/config.local.php @@ -1,9 +1,9 @@ Date: Sun, 2 Jan 2022 12:54:08 +0100 Subject: [PATCH 6/7] Don't use legacy signature for ynh_die --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index ca0d5a1..9964cf1 100644 --- a/scripts/install +++ b/scripts/install @@ -32,7 +32,7 @@ app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Validating installation parameters..." --weight=1 final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url diff --git a/scripts/restore b/scripts/restore index a4dfe8a..f63a66d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -35,7 +35,7 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) ynh_script_progression --message="Validating restoration parameters..." --weight=4 test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS diff --git a/scripts/upgrade b/scripts/upgrade index dedde73..accbb30 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,7 +18,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) || ynh_die "This path already contains a folder" +final_path=$(ynh_app_setting_get --app=$app --key=final_path) || ynh_die --message="This path already contains a folder" phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) secret_key=$(ynh_string_random --length=50) From 535464fcdd6fd22a88b8a1d348079459b54336a2 Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 2 Jan 2022 13:01:17 +0100 Subject: [PATCH 7/7] Update restoration script with the use of ynh_install_app_dependencies --- scripts/restore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index f63a66d..d712603 100644 --- a/scripts/restore +++ b/scripts/restore @@ -82,7 +82,8 @@ ynh_script_progression --message="Reconfiguring PHP-FPM..." --weight=6 ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" -ynh_add_fpm_config --package="$extra_php_dependencies" +ynh_install_app_dependencies "$extra_php_dependencies" +ynh_add_fpm_config #================================================= # GENERIC FINALIZATION