From 7a9660f02cefdfeeef2f73a985e3eb6482e1bc3a Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Mon, 19 Aug 2024 09:15:13 +0200 Subject: [PATCH] helpers_2.1 --- .gitignore | 3 +++ manifest.toml | 3 ++- scripts/_common.sh | 14 +------------- scripts/backup | 25 ++++++++----------------- scripts/change_url | 28 +++++++++------------------- scripts/install | 36 +++++++++++++++--------------------- scripts/remove | 25 ++++++++++--------------- scripts/restore | 35 ++++++++++++++--------------------- scripts/upgrade | 41 ++++++++++++++--------------------------- 9 files changed, 76 insertions(+), 134 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f144f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index c12d5f5..5040886 100644 --- a/manifest.toml +++ b/manifest.toml @@ -16,7 +16,8 @@ admindoc = "https://miniflux.app/docs/index.html" code = "https://github.com/miniflux/v2" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = ["amd64", "armhf", "arm64"] multi_instance = true diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..3d7f008 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,17 +1,5 @@ #!/bin/bash #================================================= -# COMMON VARIABLES -#================================================= - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index ab4f52c..e431ca5 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,44 +1,35 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the PostgreSQL database..." +ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 1328083..39a5d1c 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,53 +1,43 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action=stop #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression "Adding $app's configuration..." domain="$new_domain" path="$new_path" -ynh_add_config --template="../conf/miniflux.conf" --destination="$install_dir/$app.conf" +ynh_config_add --template="miniflux.conf" --destination="$install_dir/$app.conf" chmod 600 "$install_dir/$app.conf" -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action=start --log_path=systemd +ynh_systemctl --service=$app --action=start --log_path=systemd #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 60df0a9..9cf3709 100644 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -14,32 +8,32 @@ source /usr/share/yunohost/helpers #================================================= password=$YNH_APP_ARG_PASSWORD -ynh_app_setting_set --app=$app --key=password --value=$password +ynh_app_setting_set --key=password --value=$password #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 +ynh_script_progression "Creating a PostgreSQL database..." -ynh_psql_execute_as_root --sql="CREATE EXTENSION hstore;" --database=$db_name +ynh_psql_db_shell <<< "CREATE EXTENSION hstore;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=1 +ynh_script_progression "Setting up source files..." ynh_setup_source --dest_dir="$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" chmod +x "$install_dir/miniflux" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression "Adding $app's configuration..." -ynh_add_config --template="miniflux.conf" --destination="$install_dir/$app.conf" +ynh_config_add --template="miniflux.conf" --destination="$install_dir/$app.conf" chmod 600 "$install_dir/$app.conf" chown $app "$install_dir/$app.conf" @@ -47,25 +41,25 @@ chown $app "$install_dir/$app.conf" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +ynh_script_progression "Adding system configurations related to $app..." -ynh_add_nginx_config +ynh_config_add_nginx -ynh_add_systemd_config +ynh_config_add_systemd -ynh_use_logrotate +ynh_config_add_logrotate yunohost service add $app --description="Minimalist feed reader" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=2 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action=start --log_path=systemd +ynh_systemctl --service=$app --action=start --log_path=systemd #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index a959a08..4dc46a3 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,35 +1,30 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= -# REMOVE SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +# REMOVE SYSTEMD SERVICE -if ynh_exec_warn_less yunohost service status $app >/dev/null +#================================================= +ynh_script_progression "Removing system configurations related to $app..." + +if ynh_hide_warnings yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --weight=1 + ynh_script_progression "Removing $app service..." yunohost service remove $app fi -ynh_remove_systemd_config +ynh_config_remove_systemd -ynh_remove_nginx_config +ynh_config_remove_nginx -ynh_remove_logrotate +ynh_config_remove_logrotate #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 67f302a..bdc5f65 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,59 +1,52 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring $app main directory..." --weight=4 +ynh_script_progression "Restoring $app main directory..." -ynh_restore_file --origin_path="$install_dir" +ynh_restore "$install_dir" -chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" chmod +x "$install_dir/miniflux" -chown -R $app:www-data "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +ynh_psql_db_shell < "./db.sql"" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" yunohost service add $app --description="Minimalist feed reader" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action=start --log_path=systemd +ynh_systemctl --service=$app --action=start --log_path=systemd -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index fc4d97e..fe27a5b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,66 +1,53 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action=stop --log_path=systemd +ynh_systemctl --service=$app --action=stop --log_path=systemd #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] +# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed +if ynh_app_upstream_version_changed then - ynh_script_progression --message="Upgrading source files..." --weight=5 + ynh_script_progression "Upgrading source files..." ynh_setup_source --dest_dir=$install_dir --keep="$app.conf" fi -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" chmod +x "$install_dir/miniflux" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." -ynh_add_nginx_config +ynh_config_add_nginx -ynh_add_systemd_config +ynh_config_add_systemd -ynh_use_logrotate --non-append +ynh_config_add_logrotate yunohost service add $app --description="Minimalist feed reader" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action=start --log_path=systemd +ynh_systemctl --service=$app --action=start --log_path=systemd #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"