From 5d684d99ac5ad9edc445319097c0031f0fa00d32 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 15 Feb 2021 20:13:48 +0100 Subject: [PATCH] Apply last example_ynh --- conf/app.src | 2 ++ scripts/backup | 3 +-- scripts/install | 6 +++--- scripts/restore | 31 ++++++++++++++------------- scripts/upgrade | 56 ++++++++++++++++--------------------------------- 5 files changed, 40 insertions(+), 58 deletions(-) diff --git a/conf/app.src b/conf/app.src index e2ffb638..ff7ce9c6 100644 --- a/conf/app.src +++ b/conf/app.src @@ -3,3 +3,5 @@ SOURCE_SUM=d843796473858de2f0f3cda11db2f711b8303a058660d62c6696d4cb828a8a45 OURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/scripts/backup b/scripts/backup index 0e486ebf..d447d2a4 100644 --- a/scripts/backup +++ b/scripts/backup @@ -8,7 +8,6 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_supervisor source /usr/share/yunohost/helpers #================================================= @@ -65,7 +64,7 @@ ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= -# BACKUP SUPERVISOR +# BACKUP SUPERVISOR CONFIGURATION #================================================= ynh_backup --src_path="/etc/supervisor/conf.d/${app}-horizon.conf" diff --git a/scripts/install b/scripts/install index c5f091f2..b4a4ad03 100644 --- a/scripts/install +++ b/scripts/install @@ -51,7 +51,6 @@ ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url -ynh_app_setting_set --app=$app --key=is_public --value=$is_public ynh_app_setting_set --app=$app --key=app_key --value=$app_key #================================================= @@ -233,8 +232,9 @@ ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi #================================================= diff --git a/scripts/restore b/scripts/restore index b660b1ac..87eedb38 100644 --- a/scripts/restore +++ b/scripts/restore @@ -86,6 +86,7 @@ ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" # Recreate a dedicated php-fpm config ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies" +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC RESTORATION @@ -107,6 +108,13 @@ ynh_psql_test_if_first_run ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" +#================================================= +# RESTORE THE CRON FILE +#================================================= +ynh_script_progression --message="Restoring the cron file..." + +ynh_restore_file --origin_path="/etc/cron.d/$app" + #================================================= # CREATE LOG FILE #================================================= @@ -117,7 +125,14 @@ touch "/var/log/$app/${app}-horizon.log" chown -R root: "/var/log/$app/" #================================================= -# RESTORE SUPERVISOR +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + +#================================================= +# RESTORE SUPERVISOR CONFIGURATION #================================================= ynh_script_progression --message="Restoring the supervisor configuration..." @@ -138,20 +153,6 @@ ynh_script_progression --message="Starting a supervisor service..." ynh_supervisor_action --service_name="${app}-horizon" --action="reload" --log_path="systemd" --line_match="success: ${app}-horizon" -#================================================= -# RESTORE THE CRON FILE -#================================================= -ynh_script_progression --message="Restoring the cron file..." - -ynh_restore_file --origin_path="/etc/cron.d/$app" - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 97d7921e..15f13bb7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -41,25 +41,11 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=0 - is_public=0 -fi +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all -# If db_name doesn't exist, create it -if [ -z "$db_name" ]; then - db_name=$(ynh_sanitize_dbid --db_name="$app") - ynh_app_setting_set --app=$app --key=db_name --value=$db_name -fi - -# If final_path doesn't exist, create it -if [ -z "$final_path" ]; then - final_path=/var/www/$app - ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" + ynh_app_setting_delete --app=$app --key=is_public fi #================================================= @@ -110,7 +96,6 @@ if dpkg --compare-versions "0.10.9~ynh2" gt "$(ynh_read_manifest --manifest="/et touch "/var/log/$app/${app}-horizon.log" chown -R root: "/var/log/$app/" - ynh_script_progression --message="Configuring a supervisor service..." phpversion=$YNH_PHP_VERSION ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf --others_var="phpversion" @@ -166,7 +151,7 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_install_app_dependencies "$pkg_dependencies" +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER @@ -188,9 +173,9 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC UPGRADE #================================================= -# UPDATE PHP DEPENDENCIES +# UPDATE COMPOSER DEPENDENCIES #================================================= -ynh_script_progression --message="Updating php dependencies..." +ynh_script_progression --message="Updating composer dependencies..." chown -R "$app": "$final_path" @@ -254,14 +239,6 @@ cp ../conf/cron "/etc/cron.d/$app" ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="/etc/cron.d/$app" -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append - #================================================= # SETUP SUPERVISOR #================================================= @@ -281,16 +258,19 @@ ynh_script_progression --message="Securing files and directories..." chown -R $app: $final_path #================================================= -# SETUP SSOWAT +# SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." +ynh_script_progression --message="Upgrading logrotate configuration..." -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" -fi +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add "supervisor" --description "Supervisor daemon for $app" --log "/var/log/$app/${app}-horizon.log" #================================================= # START SUPERVISOR SERVICE