From 17f4953ad6d9da553085663945935e7c34a858cb Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 20 Jun 2024 23:49:43 +0200 Subject: [PATCH 1/7] Helpers 2.1 --- .gitignore | 1 + conf/nginx.conf | 2 +- manifest.toml | 1 + scripts/_common.sh | 14 +-------- scripts/backup | 42 ++++++++++++------------- scripts/change_url | 14 ++++----- scripts/config | 7 ++--- scripts/install | 47 ++++++++++++++-------------- scripts/remove | 20 ++++++------ scripts/restore | 47 ++++++++++++++-------------- scripts/upgrade | 50 +++++++++++++----------------- sources/extra_files/app/.gitignore | 2 -- sources/patches/.gitignore | 2 -- 13 files changed, 113 insertions(+), 136 deletions(-) delete mode 100644 sources/extra_files/app/.gitignore delete mode 100644 sources/patches/.gitignore diff --git a/.gitignore b/.gitignore index 783a4ae..8f144f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.sw[op] +.DS_Store diff --git a/conf/nginx.conf b/conf/nginx.conf index 1e6eee0..97f02b5 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -13,7 +13,7 @@ location __PATH__/ { try_files $uri $uri/ index.php; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php__PHP_VERSION__-fpm-__APP__.sock; fastcgi_index index.php; include fastcgi_params; diff --git a/manifest.toml b/manifest.toml index e8754ce..74e675f 100644 --- a/manifest.toml +++ b/manifest.toml @@ -33,6 +33,7 @@ fund = "???" [integration] yunohost = ">= 11.2" +helpers_version = "2.1" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] architectures = "all" 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 87926d7..cfda8b7 100755 --- a/scripts/backup +++ b/scripts/backup @@ -8,10 +8,7 @@ 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..." ### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs ### to be backuped and not an actual copy of any file. The actual backup that @@ -22,59 +19,62 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # BACKUP THE DATA DIR #================================================= -### Only relevant if there is a "data_dir" resource for this app -ynh_backup --src_path="$data_dir" --is_big +# Only relevant if there is a "data_dir" resource for this app +# NB: $data_dir is not backuped during safety-backup-before-upgrades, +# because the data dir may be huge and we don't want to just yolo-create a 10+ GB archive just for upgrades. +# On the other hand, $data_dir is also *not* removed by default in the "app remove" step unless --purge is used +# This means that even if the upgrade fails and the backup is restored, the data are still there. +ynh_backup "$data_dir" #================================================= # SYSTEM CONFIGURATION #================================================= # Backup the PHP-FPM configuration -ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +ynh_backup "/etc/php/$php_version/fpm/pool.d/$app.conf" # 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" # Backup the systemd service unit -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" # Backup the logrotate configuration -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" # Backup the Fail2Ban config -ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" -ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" +ynh_backup "/etc/fail2ban/jail.d/$app.conf" +ynh_backup "/etc/fail2ban/filter.d/$app.conf" #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/cron.d/$app" +ynh_backup "/etc/cron.d/$app" -ynh_backup --src_path="/etc/$app/" +ynh_backup "/etc/$app/" -### For apps with huge logs, you might want to pass --is_big, -### and in restore script, mkdir and pass --not_mandatory to ynh_restore_file. -ynh_backup --src_path="/var/log/$app/" +# NB: /var/log is not backuped during safety-backup-before-upgrades, same as $data_dir +ynh_backup "/var/log/$app/" #================================================= # BACKUP THE MYSQL DATABASE #================================================= -ynh_print_info --message="Backing up the MySQL database..." +ynh_print_info "Backing up the MySQL database..." ### (However, things like MySQL dumps *do* take some time to run, though the ### copy of the generated dump to the archive still happens later) -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_mysql_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 f009a85..25e55b5 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -14,17 +14,17 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping $app's 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..." # this will most likely adjust NGINX config correctly -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # SPECIFIC MODIFICATIONS @@ -35,12 +35,12 @@ ynh_change_url_nginx_config #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app" --action="start" #================================================= # 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/config b/scripts/config index 48be2ff..9c4c1c1 100644 --- a/scripts/config +++ b/scripts/config @@ -20,7 +20,7 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS #================================================= -install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir) +install_dir=$(ynh_app_setting_get --key=install_dir) #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY @@ -59,7 +59,6 @@ get__prices() { fi } - #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= @@ -90,10 +89,8 @@ set__prices() { #--------------------------------------------- # IMPORTANT: to be able to upgrade properly, you have to save the value in settings too #--------------------------------------------- - ynh_app_setting_set --app="$app" --key=prices --value="$prices" + ynh_app_setting_set --key=prices --value="$prices" } -#================================================= -# GENERIC FINALIZATION #================================================= ynh_app_config_run "$1" diff --git a/scripts/install b/scripts/install index 5e20de5..48d5b80 100755 --- a/scripts/install +++ b/scripts/install @@ -33,12 +33,12 @@ source /usr/share/yunohost/helpers # If you need to, you can define custom settings # (or remove this section entirely if not relevant for you) foo="bar" -ynh_app_setting_set --app=$app --key=foo --value=$foo +ynh_app_setting_set --key=foo --value=$foo #================================================= # 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` is used to install an app from a zip or tar.gz file, ### downloaded from an upstream source, like a git repository. @@ -55,7 +55,7 @@ chown -R "$app:www-data" "$install_dir" #================================================= # APP INITIAL CONFIGURATION #================================================= -ynh_script_progression --message="Adding $app's configuration files..." --weight=1 +ynh_script_progression "Adding $app's configuration files..." ### You can add specific configuration files. ### @@ -63,13 +63,13 @@ ynh_script_progression --message="Adding $app's configuration files..." --weight ### The template may contain strings such as __FOO__ or __FOO_BAR__, ### which will automatically be replaced by the values of $foo and $foo_bar ### -### ynh_add_config will also keep track of the config file's checksum, +### ynh_config_add will also keep track of the config file's checksum, ### which later during upgrade may allow to automatically backup the config file ### if it's found that the file was manually modified ### -### Check the documentation of `ynh_add_config` for more info. +### Check the documentation of `ynh_config_add` for more info. -ynh_add_config --template="some_config_file" --destination="$install_dir/some_config_file" +ynh_config_add --template="some_config_file" --destination="$install_dir/some_config_file" # FIXME: this should be handled by the core in the future ### You may need to use chmod 600 instead of 400, @@ -78,20 +78,20 @@ chmod 400 "$install_dir/some_config_file" chown "$app:$app" "$install_dir/some_config_file" ### For more complex cases where you want to replace stuff using regexes, -### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) +### you shoud rely on ynh_replace (which is basically a wrapper for sed) ### When doing so, you also need to manually call ynh_store_file_checksum ### -### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" -### ynh_store_file_checksum --file="$install_dir/some_config_file" +### ynh_replace --match="match_string" --replace="replace_string" --file="$install_dir/some_config_file" +### ynh_store_file_checksum "$install_dir/some_config_file" #================================================= # 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_fpm_config` is used to set up a PHP config. +### `ynh_config_add_phpfpm` is used to set up a PHP config. ### You can remove it if your app doesn't use PHP. -### `ynh_add_fpm_config` will use the files conf/extra_php-fpm.conf +### `ynh_config_add_phpfpm` will use the files conf/extra_php-fpm.conf ### If you're not using these lines: ### - You can remove these files in conf/. ### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script @@ -101,10 +101,10 @@ ynh_script_progression --message="Adding system configurations related to $app.. ### - And the section "PHP-FPM CONFIGURATION" in the upgrade script # Create a PHP-FPM config (with conf/extra_php-fpm.conf being appended to it) -ynh_add_fpm_config +ynh_config_add_phpfpm # Create a dedicated NGINX config using the conf/nginx.conf template -ynh_add_nginx_config +ynh_config_add_nginx ### `ynh_systemd_config` is used to configure a systemd script for an app. ### It can be used for apps that use sysvinit (with adaptation) or systemd. @@ -118,7 +118,7 @@ ynh_add_nginx_config ### - And the section "SETUP SYSTEMD" in the upgrade script # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd ### `yunohost service add` integrates a service in YunoHost. It then gets ### displayed in the admin interface and through the others `yunohost service` commands. @@ -146,7 +146,7 @@ ynh_add_systemd_config ### service though so you should re-provide all relevant flags when doing so) yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" -### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. +### `ynh_config_add_logrotate` is used to configure a logrotate configuration for the logs of this app. ### Use this helper only if there is effectively a log file for this app. ### If you're not using this helper: ### - Remove the section "BACKUP LOGROTATE" in the backup script @@ -155,10 +155,10 @@ yunohost service add "$app" --description="A short description of the app" --log ### - And the section "SETUP LOGROTATE" in the upgrade script # Use logrotate to manage application logfile(s) -ynh_use_logrotate +ynh_config_add_logrotate # Create a dedicated Fail2Ban config -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" +ynh_config_add_fail2ban --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" #================================================= # SETUP APPLICATION WITH CURL @@ -170,15 +170,15 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failreg ### forms. # Installation with curl -ynh_script_progression --message="Finalizing installation..." --weight=1 +ynh_script_progression "Finalizing installation..." ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -### `ynh_systemd_action` is used to start a systemd service for an app. +### `ynh_systemctl` is used to start a systemd service for an app. ### Only needed if you have configure a systemd service ### If you're not using these lines: ### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script @@ -187,9 +187,10 @@ ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app" --action="start" #================================================= # 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 c636704..f2dc539 100755 --- a/scripts/remove +++ b/scripts/remove @@ -23,32 +23,32 @@ source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +ynh_script_progression "Removing system configurations related to $app..." ### This should be a symetric version of what happens in the install script -ynh_remove_fail2ban_config +ynh_config_remove_fail2ban -ynh_remove_logrotate +ynh_config_remove_logrotate # 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" >/dev/null; then +if ynh_hide_warnings yunohost service status "$app" >/dev/null; then yunohost service remove "$app" fi -ynh_remove_systemd_config +ynh_config_remove_systemd -ynh_remove_nginx_config +ynh_config_remove_nginx -ynh_remove_fpm_config +ynh_config_remove_phpfpm # Remove other various files specific to the app... such as : -ynh_secure_remove --file="/etc/cron.d/$app" +ynh_safe_rm "/etc/cron.d/$app" -ynh_secure_remove --file="/etc/$app" +ynh_safe_rm "/etc/$app" #================================================= # 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 c4c090a..f9cd974 100755 --- a/scripts/restore +++ b/scripts/restore @@ -11,9 +11,9 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" +ynh_restore "$install_dir" ### $install_dir will automatically be initialized with some decent ### permissions by default ... however, you may need to recursively reapply @@ -23,9 +23,9 @@ chown -R "$app:www-data" "$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Restoring the data directory..." --weight=1 +ynh_script_progression "Restoring the data directory..." -ynh_restore_file --origin_path="$data_dir" --not_mandatory +ynh_restore "$data_dir" ### (Same as for install dir) chown -R "$app:www-data" "$data_dir" @@ -33,61 +33,62 @@ chown -R "$app:www-data" "$data_dir" #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=1 +ynh_script_progression "Restoring the MySQL database..." -ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql +ynh_mysql_db_shell < ./db.sql #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." ### This should be a symetric version of what happens in the install script -ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +ynh_restore "/etc/php/$php_version/fpm/pool.d/$app.conf" -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 yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" -ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" -ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" -ynh_systemd_action --action=restart --service_name=fail2ban +ynh_restore "/etc/fail2ban/jail.d/$app.conf" +ynh_restore "/etc/fail2ban/filter.d/$app.conf" +ynh_systemctl --action=restart --service=fail2ban #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_restore_file --origin_path="/etc/cron.d/$app" -ynh_restore_file --origin_path="/etc/$app/" +ynh_restore "/etc/cron.d/$app" +ynh_restore "/etc/$app/" ### For apps with huge logs, you might want to not backup logs every time: ### The mkdir call is just here in case the log directory was not backed up. ### mkdir -p "/var/log/$app" ### chown $app:www-data "/var/log/$app" -### ynh_restore_file --src_path="/var/log/$app/" --not_mandatory +### ynh_restore "/var/log/$app/" || true ### ### For other apps, the simple way is better: -ynh_restore_file --origin_path="/var/log/$app/" +ynh_restore "/var/log/$app/" #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 +ynh_script_progression "Reloading NGINX web server and $app's service..." ### Typically you only have either $app or php-fpm but not both at the same time... -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" -ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload +ynh_systemctl --service="$app" --action="start" -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service="php$php_version-fpm" --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 fab8a9a..f6fa371 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,6 +1,5 @@ #!/bin/bash - #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -21,24 +20,17 @@ source /usr/share/yunohost/helpers ### - resources are automatically provisioned / updated / deleted (depending on existing resources) ### - a safety backup is automatically created by the core and will be restored if the upgrade fails -### This variable describes which upgrade type is occurring, allowing the script to handle different modes: -### - UPGRADE_PACKAGE if only the YunoHost package has changed -### - UPGRADE_APP if the upstream app version has changed -### If your package needs to handle other things, like same-version upgrades or downgrades, please -### check out the $YNH_APP_UPGRADE_TYPE variable that can contain DOWNGRADE and UPGRADE_SAME too. -# upgrade_type=$(ynh_check_app_version_changed) - #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping $app's 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" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -#ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +#ynh_script_progression "Ensuring downward compatibility..." ### N.B. : the following setting migration snippets are provided as *EXAMPLES* ### of what you may want to do in some cases (e.g. a setting was not defined on @@ -47,19 +39,19 @@ ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$a # 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 +# ynh_app_setting_set --key=db_name --value=$db_name # fi # If install_dir doesn't exist, create it # if [ -z "$install_dir" ]; then # install_dir=/var/www/$app -# ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir +# ynh_app_setting_set --key=install_dir --value=$install_dir # fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." --weight=1 +ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from manifest.toml ynh_setup_source --dest_dir="$install_dir" @@ -72,14 +64,14 @@ chown -R "$app:www-data" "$install_dir" #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating $app's configuration files..." --weight=1 +ynh_script_progression "Updating $app's configuration files..." ### Same as during install ### ### The file will automatically be backed-up if it's found to be manually modified (because -### ynh_add_config keeps track of the file's checksum) +### ynh_config_add keeps track of the file's checksum) -ynh_add_config --template="some_config_file" --destination="$install_dir/some_config_file" +ynh_config_add --template="some_config_file" --destination="$install_dir/some_config_file" # FIXME: this should be handled by the core in the future ### You may need to use chmod 600 instead of 400, @@ -88,40 +80,40 @@ chmod 400 "$install_dir/some_config_file" chown "$app:$app" "$install_dir/some_config_file" ### For more complex cases where you want to replace stuff using regexes, -### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) +### you shoud rely on ynh_replace (which is basically a wrapper for sed) ### When doing so, you also need to manually call ynh_store_file_checksum ### -### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" -### ynh_store_file_checksum --file="$install_dir/some_config_file" +### ynh_replace --match="match_string" --replace="replace_string" --file="$install_dir/some_config_file" +### ynh_store_file_checksum "$install_dir/some_config_file" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." ### This should be a literal copypaste of what happened in the install's "System configuration" section -ynh_add_fpm_config +ynh_config_add_phpfpm -ynh_add_nginx_config +ynh_config_add_nginx -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" -ynh_use_logrotate --non-append +ynh_config_add_logrotate -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" +ynh_config_add_fail2ban --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app" --action="start" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed" diff --git a/sources/extra_files/app/.gitignore b/sources/extra_files/app/.gitignore deleted file mode 100644 index 783a4ae..0000000 --- a/sources/extra_files/app/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -*.sw[op] diff --git a/sources/patches/.gitignore b/sources/patches/.gitignore deleted file mode 100644 index 783a4ae..0000000 --- a/sources/patches/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -*.sw[op] From cfe872b50e4d30ca2085ca38a0e146a271fc55df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 11 Jan 2024 00:17:14 +0100 Subject: [PATCH 2/7] On upgrade, pass --full_replace, --keep to ynh_setup_source, with the according doc. --- scripts/upgrade | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index f6fa371..b3b193d 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -53,8 +53,13 @@ ynh_systemctl --service="$app" --action="stop" #================================================= ynh_script_progression "Upgrading source files..." +### ynh_setup_source can wipe the destination dir if called with --full_replace. +### On upgrade, that is certainly what you want, to remove any old source file that +### does not exist in the new version of the software. +### You can list with --keep every file/directory to *not* wipe or overwrite, +### useful for configuration files, data directories, or plugins. # Download, check integrity, uncompress and patch the source from manifest.toml -ynh_setup_source --dest_dir="$install_dir" +ynh_setup_source --dest_dir="$install_dir" --full_replace --keep=".env data" ### $install_dir will automatically be initialized with some decent ### permissions by default ... however, you may need to recursively reapply From f7ea228df824eacefcbd3469f50404cf874b2291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:55:06 +0200 Subject: [PATCH 3/7] minor typos --- scripts/backup | 2 +- scripts/install | 4 ++-- scripts/remove | 4 ++-- scripts/restore | 4 ++-- scripts/upgrade | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/backup b/scripts/backup index cfda8b7..c288a49 100755 --- a/scripts/backup +++ b/scripts/backup @@ -39,7 +39,7 @@ ynh_backup "$data_dir" # Backup the PHP-FPM configuration ynh_backup "/etc/php/$php_version/fpm/pool.d/$app.conf" -# Backup the nginx configuration +# Backup the NGINX configuration ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" # Backup the systemd service unit diff --git a/scripts/install b/scripts/install index 48d5b80..e69da9e 100755 --- a/scripts/install +++ b/scripts/install @@ -24,7 +24,7 @@ source /usr/share/yunohost/helpers ### ... ### ### $app is the app id (i.e. 'example' for first install, -### or 'example__2', '__3', ... for multi-instance installs) +### or 'example__2', '__3'... for multi-instance installs) #================================================= # INITIALIZE AND STORE SETTINGS @@ -48,7 +48,7 @@ ynh_script_progression "Setting up source files..." ynh_setup_source --dest_dir="$install_dir" ### $install_dir will automatically be initialized with some decent -### permission by default ... however, you may need to recursively reapply +### permission by default... however, you may need to recursively reapply ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" diff --git a/scripts/remove b/scripts/remove index f2dc539..85ffd78 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,7 +16,7 @@ source /usr/share/yunohost/helpers ### - $port ### ... -### For remove operations : +### For remove operations: ### - the core will deprovision every resource defined in the manifest **after** this script is ran ### this includes removing the install directory, and data directory (if --purge was used) @@ -41,7 +41,7 @@ ynh_config_remove_nginx ynh_config_remove_phpfpm -# Remove other various files specific to the app... such as : +# Remove other various files specific to the app... such as: ynh_safe_rm "/etc/cron.d/$app" diff --git a/scripts/restore b/scripts/restore index f9cd974..e2f541a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -16,7 +16,7 @@ ynh_script_progression "Restoring the app main directory..." ynh_restore "$install_dir" ### $install_dir will automatically be initialized with some decent -### permissions by default ... however, you may need to recursively reapply +### permissions by default... however, you may need to recursively reapply ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" @@ -80,7 +80,7 @@ ynh_restore "/var/log/$app/" #================================================= ynh_script_progression "Reloading NGINX web server and $app's service..." -### Typically you only have either $app or php-fpm but not both at the same time... +### Typically you only have either $app or PHP-FPM but not both at the same time... ynh_systemctl --service="$app" --action="start" ynh_systemctl --service="php$php_version-fpm" --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index b3b193d..45d4ee7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -62,7 +62,7 @@ ynh_script_progression "Upgrading source files..." ynh_setup_source --dest_dir="$install_dir" --full_replace --keep=".env data" ### $install_dir will automatically be initialized with some decent -### permissions by default ... however, you may need to recursively reapply +### permissions by default... however, you may need to recursively reapply ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" From 2324dd95d259c53993b6a2c08da5aa572cfe475c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 3 Sep 2024 14:11:28 +0200 Subject: [PATCH 4/7] Use ynh_app_setting_set_default --- scripts/upgrade | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 45d4ee7..957e129 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -37,16 +37,10 @@ ynh_systemctl --service="$app" --action="stop" ### some legacy installs and you therefore want to initiaze stuff during upgrade) # 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 --key=db_name --value=$db_name -# fi +# ynh_app_setting_set_default --key=db_name --value="$(ynh_sanitize_dbid --db_name=$app)" # If install_dir doesn't exist, create it -# if [ -z "$install_dir" ]; then -# install_dir=/var/www/$app -# ynh_app_setting_set --key=install_dir --value=$install_dir -# fi +# ynh_app_setting_set_default --key=install_dir --value="/var/www/$app" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE From cb1248a7fd200413f1d57595015f56077da3746f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:15:46 +0200 Subject: [PATCH 5/7] Update manifest.toml --- manifest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index 74e675f..ac4bde3 100644 --- a/manifest.toml +++ b/manifest.toml @@ -32,7 +32,7 @@ cpe = "???" fund = "???" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.30" helpers_version = "2.1" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] architectures = "all" From 722cf4c54ec158715efbad7350d8ae32fa9db13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:19:18 +0200 Subject: [PATCH 6/7] fix helpers name --- scripts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index e69da9e..ebb82ea 100755 --- a/scripts/install +++ b/scripts/install @@ -106,10 +106,10 @@ ynh_config_add_phpfpm # Create a dedicated NGINX config using the conf/nginx.conf template ynh_config_add_nginx -### `ynh_systemd_config` is used to configure a systemd script for an app. +### `ynh_config_add_systemd` is used to configure a systemd script for an app. ### It can be used for apps that use sysvinit (with adaptation) or systemd. ### Have a look at the app to be sure this app needs a systemd script. -### `ynh_systemd_config` will use the file conf/systemd.service +### `ynh_config_add_systemd` will use the file conf/systemd.service ### If you're not using these lines: ### - You can remove those files in conf/. ### - Remove the section "BACKUP SYSTEMD" in the backup script From 910e85002d053965fc31a6ae56cac768087666df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:21:56 +0200 Subject: [PATCH 7/7] minor typo --- conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 97f02b5..1f14638 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -7,7 +7,7 @@ location __PATH__/ { ### Example PHP configuration (remove it if not used) index index.php; - # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file + # Common parameter to increase upload size limit in conjunction with dedicated PHP-FPM file # client_max_body_size 50M; try_files $uri $uri/ index.php;