From 6e66a37271a08e8771abd44644a6110fd4fa6898 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 23 Feb 2020 18:18:57 +0100 Subject: [PATCH] Apply example_ynh --- README.md | 3 +-- scripts/_common.sh | 2 +- scripts/backup | 4 ++++ scripts/change_url | 22 ++++++++++++++++++++++ scripts/install | 15 ++++++++++++++- scripts/remove | 7 ++++--- scripts/restore | 12 ++++++++++-- scripts/upgrade | 11 +++++------ 8 files changed, 61 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 832c9098..bdb2cc02 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,10 @@ Those commands can be found in the official documentation. * x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/pixelfed%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/pixelfed/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/pixelfed%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pixelfed/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/pixelfed%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/pixelfed/) ## Links - * Report a bug about this package: https://github.com/YunoHost-Apps/pixelfed_ynh + * Report a bug: https://github.com/YunoHost-Apps/pixelfed_ynh * Pixelfed website: https://pixelfed.org * Upstream app repository: https://github.com/pixelfed/pixelfed * YunoHost website: https://yunohost.org diff --git a/scripts/_common.sh b/scripts/_common.sh index fbb68168..062da75e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -106,7 +106,7 @@ ynh_install_php () { ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" 200 --name=extra_php_version ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" 600 --name=extra_php_version --append - # Advertise service in admin panel + # INTEGRATE SERVICE IN YUNOHOST yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log" } diff --git a/scripts/backup b/scripts/backup index e821eed8..8c6b7521 100644 --- a/scripts/backup +++ b/scripts/backup @@ -13,7 +13,11 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing 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 fe65f305..e541478d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS #================================================= +ynh_print_info --message="Retrieve arguments from the manifest" old_domain=$YNH_APP_OLD_DOMAIN old_path="/" @@ -31,8 +32,26 @@ final_path=$(ynh_app_setting_get --app="$app" --key=final_path) # Add settings here as needed by your application #db_name=$(ynh_app_setting_get --app="$app" --key=db_name) +#db_user=$db_name #db_pwd=$(ynh_app_setting_get --app="$app" --key=db_pwd) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_print_info --message="Backing up the app before changing its url (may take a while)..." + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= @@ -67,6 +86,7 @@ fi #================================================= # UPDATE CONFIG FILE #================================================= +ynh_print_info --message="Updating config file..." config="$final_path/.env" ynh_replace_string --match_string="APP_URL=.*" --replace_string="APP_URL=https://$new_domain" --target_file="$config" @@ -77,6 +97,7 @@ ynh_replace_string --match_string="MAIL_FROM_ADDRESS=.*" --replace_string="MAIL_ #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= +ynh_print_info --message="Storing the config file checksum..." ynh_backup_if_checksum_is_different --file="$config" @@ -86,6 +107,7 @@ ynh_store_file_checksum --file="$config" #================================================= # APPLY CHANGES #================================================= +ynh_print_info --message="Applying changes..." pushd "$final_path" php7.3 artisan config:clear diff --git a/scripts/install b/scripts/install index d6ee0c18..31f84af6 100644 --- a/scripts/install +++ b/scripts/install @@ -12,13 +12,18 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing script failure..." +ynh_clean_setup () { + true +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= +ynh_print_info --message="Retrieving arguments from the manifest..." domain=$YNH_APP_ARG_DOMAIN path_url="/" @@ -42,6 +47,7 @@ ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info --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" @@ -83,6 +89,7 @@ ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info --message="Setting up source files..." ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" # Download, check integrity, uncompress and patch the source from app.src @@ -115,6 +122,7 @@ ynh_add_fpm_config --phpversion="7.3" #================================================= # INSTALL PHP DEPENDENCIES #================================================= +ynh_print_info --message="Installing php dependencies..." chown -R "$app": "$final_path" @@ -138,6 +146,7 @@ ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_print_info --message="Modifying a config file..." config="$final_path/.env" cp ../conf/.env "$config" @@ -153,6 +162,7 @@ ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --t #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #================================================= +ynh_print_info --message="Storing the config file checksum..." # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config" @@ -160,6 +170,7 @@ ynh_store_file_checksum --file="$config" #================================================= # DEPLOYMENT #================================================= +ynh_print_info --message="Deploying..." pushd "$final_path" php7.3 artisan -n key:generate --force @@ -180,14 +191,16 @@ popd #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_print_info --message="Securing files and directories..." # Set permissions to app files chown -R root: "$final_path" chown -R "$app": "$final_path/storage/" #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_print_info --message="Integrating service in YunoHost..." yunohost service add "${app}-horizon" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log" diff --git a/scripts/remove b/scripts/remove index c2d055b8..7d0d102e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -24,10 +24,11 @@ final_path=$(ynh_app_setting_get --app="$app" --key=final_path) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= +ynh_print_info --message="Removing service integration in YunoHost..." -# Remove a service from the admin panel, added by `yunohost service add` +# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status ${app}-horizon >/dev/null then ynh_print_info --message="Removing ${app}-horizon service..." @@ -89,7 +90,7 @@ ynh_remove_fpm_config ynh_print_info --message="Start php7.0-fpm..." #Sometimes with package_check php7.0-fpm fail to reload and stop. So starting the service, just in case. -ynh_systemd_action --service_name=php7.0-fpm --action=start +ynh_systemd_action --service_name=php7.0-fpm --action="start" #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index abfa92a4..967755ef 100644 --- a/scripts/restore +++ b/scripts/restore @@ -13,7 +13,11 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing script failure..." +ynh_clean_setup () { + true +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -29,7 +33,6 @@ path_url=$(ynh_app_setting_get --app="$app" --key=path) final_path=$(ynh_app_setting_get --app="$app" --key=final_path) db_name=$(ynh_app_setting_get --app="$app" --key=db_name) db_user=$db_name -db_pwd=$(ynh_app_setting_get --app="$app" --key=db_pwd) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -46,6 +49,7 @@ test ! -d "$final_path" \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_print_info --message="Restoring the nginx configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -67,6 +71,7 @@ ynh_system_user_create --username="$app" #================================================= # RESTORE USER RIGHTS #================================================= +ynh_print_info --message="Restoring user rights..." # Restore permissions on app files chown -R "$app": "$final_path" @@ -81,6 +86,7 @@ ynh_install_php --phpversion="7.3" --package="$extra_pkg_dependencies" #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= +ynh_print_info --message="Restoring PHP-FPM configuration..." ynh_restore_file --origin_path="/etc/php/7.3/fpm/pool.d/$app.conf" @@ -99,6 +105,7 @@ ynh_install_app_dependencies "$pkg_dependencies" #================================================= ynh_print_info --message="Restoring the PostgreSQL database..." +db_pwd=$(ynh_app_setting_get --app="$app" --key=db_pwd) 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" @@ -112,8 +119,9 @@ ynh_restore_file --origin_path="/etc/systemd/system/${app}-horizon.service" systemctl enable ${app}-horizon.service #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_print_info --message="Integrating service in YunoHost..." yunohost service add "${app}-horizon" --log "/var/log/$app/${app}-horizon.log" diff --git a/scripts/upgrade b/scripts/upgrade index 0d292096..e6f6137d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -30,6 +30,7 @@ app_key=$(ynh_app_setting_get --app="$app" --key=app_key) #================================================= # CHECK VERSION #================================================= +ynh_print_info --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -148,6 +149,7 @@ ynh_add_fpm_config --phpversion="7.3" #================================================= # UPDATE PHP DEPENDENCIES #================================================= +ynh_print_info --message="Updating php dependencies..." chown -R "$app": "$final_path" @@ -161,6 +163,7 @@ ynh_composer_exec --phpversion="7.3" --workdir="$final_path" --commands="update" #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_print_info --message="Modifying a config file..." config="$final_path/.env" ynh_backup_if_checksum_is_different --file="$config" @@ -180,6 +183,7 @@ ynh_store_file_checksum --file="$config" #================================================= # DEPLOYMENT #================================================= +ynh_print_info --message="Deploying..." pushd "$final_path" php7.3 artisan horizon:install @@ -204,17 +208,12 @@ ynh_print_info --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config --service="${app}-horizon" --template=horizon.service -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -yunohost service add "${app}-horizon" --description "${app}-horizon daemon for $app" --log "/var/log/$app/${app}-horizon.log" - #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_print_info --message="Securing files and directories..." # Set permissions on app files chown -R "$app": "$final_path"