From 33427a79c41d3d1267614a2eb7422f559b95c2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 10 Jul 2024 18:18:45 +0200 Subject: [PATCH] Cleanup, coding style --- manifest.toml | 15 ++++++++---- scripts/backup | 14 +---------- scripts/change_url | 19 ++++----------- scripts/install | 58 ++++++++++++++++++---------------------------- scripts/remove | 11 ++------- scripts/restore | 22 ++++++------------ scripts/upgrade | 55 ++++++++++++++----------------------------- tests.toml | 2 ++ 8 files changed, 66 insertions(+), 130 deletions(-) diff --git a/manifest.toml b/manifest.toml index c10821d..d670e06 100644 --- a/manifest.toml +++ b/manifest.toml @@ -1,3 +1,5 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + packaging_format = 2 id = "firefly-iii-di" @@ -41,10 +43,10 @@ ram.runtime = "50M" type = "user" [resources] - [resources.sources.main] - url = "https://github.com/firefly-iii/data-importer/archive/refs/tags/v1.5.2.tar.gz" - sha256 = "ee1debfe137c04e4152bf7ebb6bb50cbd6c4ab2d7dd64bee05b93f7e6c25f7d7" - autoupdate.strategy = "latest_github_tag" + [resources.sources.main] + url = "https://github.com/firefly-iii/data-importer/archive/refs/tags/v1.5.2.tar.gz" + sha256 = "ee1debfe137c04e4152bf7ebb6bb50cbd6c4ab2d7dd64bee05b93f7e6c25f7d7" + autoupdate.strategy = "latest_github_tag" [resources.system_user] @@ -54,4 +56,7 @@ ram.runtime = "50M" main.url = "/" [resources.apt] - packages = "php8.3-xml php8.3-bcmath" + packages = [ + "php8.3-xml", + "php8.3-bcmath", + ] diff --git a/scripts/backup b/scripts/backup index db124c0..ed0aadc 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -22,23 +20,13 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# BACKUP THE SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# BACKUP THE PHP-FPM CONFIGURATION -#================================================= - ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" -#================================================= -# BACKUP VARIOUS FILES -#================================================= - -# ynh_backup --src_path="/etc/cron.d/$app" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 1fbf84a..c89b2cb 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,15 +7,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= - -email=$(ynh_user_get_info --username=$admin --key=mail) -timezone="$(cat /etc/timezone)" - -#================================================= -# STANDARD MODIFICATIONS #================================================= # MODIFY URL IN NGINX CONF #================================================= @@ -30,12 +19,12 @@ ynh_change_url_nginx_config #================================================= ynh_script_progression --message="Modifying a config file..." -domain="$new_domain" -path="$new_path" +email=$(ynh_user_get_info --username="$admin" --key="mail") +timezone="$(cat /etc/timezone)" -ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" +ynh_add_config --template=".env" --destination="$install_dir/.env" chmod 400 "$install_dir/.env" -chown $app "$install_dir/.env" +chown "$app" "$install_dir/.env" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 0444f81..893c5cd 100755 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,25 +8,21 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST +# INITIALIZE AND STORE SETTINGS #================================================= random_key=$(ynh_string_random --length=32) -email=$(ynh_user_get_info --username=$admin --key=mail) +ynh_app_setting_set --app="$app" --key="random_key" --value="$random_key" + +email=$(ynh_user_get_info --username="$admin" --key="mail") timezone="$(cat /etc/timezone)" fpm_footprint="low" fpm_free_footprint=0 fpm_usage="low" - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= - -ynh_app_setting_set --app=$app --key=random_key --value=$random_key -ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint -ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint -ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage +ynh_app_setting_set --app="$app" --key="fpm_footprint" --value="$fpm_footprint" +ynh_app_setting_set --app="$app" --key="fpm_free_footprint" --value="$fpm_free_footprint" +ynh_app_setting_set --app="$app" --key="fpm_usage" --value="$fpm_usage" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -39,27 +33,9 @@ ynh_script_progression --message="Setting up source files..." ynh_setup_source --dest_dir=$install_dir chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" -chmod -R 775 $install_dir/storage +chown -R "$app:www-data" "$install_dir" +chmod -R 775 "$install_dir/storage" -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring PHP-FPM..." - -# Create a dedicated PHP-FPM config -ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC SETUP #================================================= # INSTALL COMPOSER DEPENDENCIES #================================================= @@ -72,10 +48,20 @@ ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$i #================================================= ynh_script_progression --message="Adding a configuration file..." -ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" - +ynh_add_config --template=".env" --destination="$install_dir/.env" chmod 400 "$install_dir/.env" -chown $app "$install_dir/.env" +chown "$app" "$install_dir/.env" + +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +# Create a dedicated PHP-FPM config +ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint + +# Create a dedicated NGINX config +ynh_add_nginx_config #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index c9f5356..52b7893 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,18 +8,13 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# REMOVE NGINX CONFIGURATION +# REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Removing PHP-FPM configuration..." - # Remove the dedicated PHP-FPM config ynh_remove_fpm_config diff --git a/scripts/restore b/scripts/restore index afa45cb..43e5e34 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -18,30 +16,24 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" #================================================= -# RESTORE THE PHP-FPM CONFIGURATION +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring the PHP-FPM configuration..." +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." - ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# GENERIC FINALIZATION +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -# RELOAD NGINX AND PHP-FPM -#================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 + +ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload -ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 0e0721e..ac2cdcd 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -16,12 +14,6 @@ source /usr/share/yunohost/helpers email=$(ynh_user_get_info --username=$admin --key=mail) timezone="$(cat /etc/timezone)" -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -48,43 +40,32 @@ fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" --keep=".env storage/upload storage/export" -fi +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" --keep=".env storage/upload storage/export" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" -chmod -R 775 $install_dir/storage +chown -R "$app:www-data" "$install_dir" +chmod -R 775 "$install_dir/storage" -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." - -# Create a dedicated PHP-FPM config -ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC UPGRADE #================================================= # UPDATE PHP DEPENDENCIES #================================================= -ynh_script_progression --message="Updating PHP dependencies..." +ynh_script_progression --message="Installing composer dependencies..." -ynh_exec_warn_less ynh_install_composer +ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$install_dir" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated PHP-FPM config +ynh_add_fpm_config --phpversion="$phpversion" --usage="$fpm_usage" --footprint="$fpm_footprint" + +# Create a dedicated NGINX config +ynh_add_nginx_config #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml index 65c744c..e5f98b5 100644 --- a/tests.toml +++ b/tests.toml @@ -1,3 +1,5 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + test_format = 1.0 [default]