From c7a8f3f1626b848ff7cf3f50abae41709918f870 Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Fri, 30 Aug 2024 22:43:21 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- manifest.toml | 4 ++- scripts/_common.sh | 34 +++++++++---------------- scripts/backup | 19 ++++---------- scripts/change_url | 6 ++--- scripts/config | 37 +++++++++++---------------- scripts/install | 40 +++++++++++++----------------- scripts/remove | 14 +++-------- scripts/restore | 24 ++++++------------ scripts/upgrade | 26 +++++++------------ sources/extra_files/app/.gitignore | 2 -- sources/patches/.gitignore | 2 -- 11 files changed, 76 insertions(+), 132 deletions(-) delete mode 100644 sources/extra_files/app/.gitignore delete mode 100644 sources/patches/.gitignore diff --git a/manifest.toml b/manifest.toml index 4b26f37..7272adb 100644 --- a/manifest.toml +++ b/manifest.toml @@ -16,7 +16,8 @@ admindoc = "https://framagit.org/chatons/chatonsinfos/-/blob/master/README.md" code = "https://framagit.org/chatons/chatonsinfos" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = false @@ -53,6 +54,7 @@ ram.runtime = "50M" # This will provision/deprovision a unix system user [resources.install_dir] + group = "www-data:r-x" # This will create/remove the install dir as /var/www/$app # and store the corresponding setting $install_dir diff --git a/scripts/_common.sh b/scripts/_common.sh index 69649b3..f5bb767 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,15 +1,12 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= -#================================================= -# PERSONAL HELPERS -#================================================= generate_config_panel() { export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g" | grep -v chatonsinfos | tr '\n' ',' | sed "s/,$//") - ynh_render_template /etc/yunohost/apps/chatonsinfos/conf/config_panel.toml.j2 /etc/yunohost/apps/chatonsinfos/config_panel.toml + ynh_config_add --jinja /etc/yunohost/apps/chatonsinfos/conf/config_panel.toml.j2 /etc/yunohost/apps/chatonsinfos/config_panel.toml create_service_properties } @@ -31,7 +28,7 @@ create_service_properties() { cp "$source_path" "$service_path" # Prefill the properties - ynh_print_info --message="Filling '$service_path'" + ynh_print_info "Filling '$service_path'" local app_info="$(yunohost app info $_app_id --full --json)" get_info() { echo $app_info | jq -r ".$1" @@ -74,15 +71,15 @@ create_service_properties() { for config_key in host.name host.description host.server.distribution host.server.type host.provider.type host.provider.hypervisor host.country.name host.country.code do settings=${config_key//\./_} - local value=$(ynh_app_setting_get --app=$app --key=$settings) + local value=$(ynh_app_setting_get --key=$settings) ynh_write_var_in_file --file="$service_path" --key="$config_key" --value="$value" done fi done - chown $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 $app:www-data "$install_dir" chown -R $app:www-data "$install_dir/public" chown -R $app:www-data "$install_dir/public" - 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 a-x "$install_dir/{public,sources}/*" } update_subs() { @@ -90,14 +87,15 @@ update_subs() { local app=chatonsinfos export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g" | grep -v chatonsinfos) local orga_path="$install_dir/public/organization.properties" - - # Remove all subs + + # Remove all subs + sed -i "/^subs\..* =/d" "$orga_path" - + # Add a subs for each published apps for subs_app_id in $apps do - local app_published=$(ynh_app_setting_get --app=$app --key=${subs_app_id}_published) + local app_published=$(ynh_app_setting_get --key=${subs_app_id}_published) if [ "$app_published" == "" ] then sed -i "/\[Subs\]/a \ @@ -106,7 +104,7 @@ subs.${subs_app_id} = 'https://$domain$path/${subs_app_id}.properties'" "$orga_p done # Add external subs - local external_subs=$(ynh_app_setting_get --app=$app --key=external_subs | sed "s/,/ /g") + local external_subs=$(ynh_app_setting_get --key=external_subs | sed "s/,/ /g") for external_sub in $external_subs do local subs_app_id=${external_sub%*:} @@ -118,11 +116,3 @@ subs.${subs_app_id} = '${subs_url}'" "$orga_path" ynh_write_var_in_file --file="$orga_path" --key="file.datetime" --value="$(date '+%Y-%m-%dT%H:%M:%S')" } - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 1927e79..37d4f81 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,31 +1,22 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts 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" #================================================= # SPECIFIC BACKUP @@ -33,10 +24,10 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/cron.daily/$app" +ynh_backup "/etc/cron.daily/$app" #================================================= # 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 6492778..39d37fc 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -6,12 +6,12 @@ source /usr/share/yunohost/helpers #================================================= # 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 #================================================= # 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 b319a9e..9753eff 100644 --- a/scripts/config +++ b/scripts/config @@ -1,23 +1,18 @@ #!/bin/bash -# In simple cases, you don't need a config script. +# In simple cases, you don't need a config script. + +# With a simple config_panel.toml, you can write in the app settings, in the -# With a simple config_panel.toml, you can write in the app settings, in the # upstream config file or replace complete files (logo ...) and restart services. -# The config scripts allows you to go further, to handle specific cases +# The config scripts allows you to go further, to handle specific cases + # (validation of several interdependent fields, specific getter/setter for a value, # display dynamic informations or choices, pre-loading of config type .cube... ). -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source /usr/share/yunohost/helpers -ynh_abort_if_errors - +#REMOVEME? ynh_abort_if_errors #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY @@ -33,7 +28,7 @@ get__host_properties() { # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= get__multi_file() { - ynh_app_setting_get --app=$app --key=$1 + ynh_app_setting_get --key=$1 } set__multi_file() { local short_setting="${1//_/.}" @@ -41,26 +36,26 @@ set__multi_file() { local bind_files="$(echo $3 | sed 's/multi_file(//' | sed 's/)//')" local value="${!1}" local bind_file - ynh_app_setting_set --app=$app --key=$1 --value="$value" - ynh_print_info --message="Configuration key '$short_setting' edited in app settings" + ynh_app_setting_set --key=$1 --value="$value" + ynh_print_info "Configuration key '$short_setting' edited in app settings" if [ "$bind_files" != "" ] then for bind_file in ${bind_files//,/ } do ynh_read_var_in_file --file="${bind_file}" --key="${short_settings}" - ynh_print_info --message="Configuration key '$short_setting' edited in '${bind_file}'" + ynh_print_info "Configuration key '$short_setting' edited in '${bind_file}'" done fi } get__manage_subs() { - ynh_app_setting_get --app=$app --key=$1 + ynh_app_setting_get --key=$1 } set__manage_subs() { - ynh_print_info --message="Configuration key '$1' edited in app settings" - ynh_app_setting_set --app=$app --key=$1 --value="${!1}" - - ynh_print_info --message="Subs added in organization.properties" + ynh_print_info "Configuration key '$1' edited in app settings" + ynh_app_setting_set --key=$1 --value="${!1}" + + ynh_print_info "Subs added in organization.properties" update_subs } @@ -82,6 +77,4 @@ ynh_app_config_apply() { } #================================================= -# GENERIC FINALIZATION -#================================================= ynh_app_config_run $1 diff --git a/scripts/install b/scripts/install index 0a75d0c..7d6c160 100755 --- 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 @@ -13,14 +7,14 @@ source /usr/share/yunohost/helpers # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set --app=$app --key=host_server_distribution --value="YunoHost" +ynh_app_setting_set --key=host_server_distribution --value="YunoHost" #================================================= # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=1 +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/sources" @@ -28,29 +22,29 @@ mkdir $install_dir/public # Empty html page to fix the CI echo "ChatonsInfos" > $install_dir/public/index.html -# $install_dir will automatically be initialized with some decent +# $install_dir will automatically be initialized with some decent + # permission by default ... however, you may need to recursively reapply # ownership to all files such as after the ynh_setup_source step -chown -R root:root "$install_dir" -chown $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 root:root "$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 $app:www-data "$install_dir" chown -R $app:www-data "$install_dir/public" -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" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +ynh_script_progression "Adding system configurations related to $app..." # Create a dedicated NGINX config using the conf/nginx.conf template -ynh_add_nginx_config +ynh_config_add_nginx #================================================= # APP INITIAL CONFIGURATION #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 - +ynh_script_progression "Adding $app's configuration..." + cp "$install_dir/sources/MODELES/organization.properties" "$install_dir/public/" orga_path="$install_dir/public/organization.properties" @@ -62,22 +56,22 @@ chown -R $app:www-data "$install_dir/public" #================================================= # GENERATE CONFIG PANEL #================================================= -ynh_script_progression --message="Generating configuration panel..." --weight=1 +ynh_script_progression "Generating configuration panel..." generate_config_panel #================================================= # ADD A CRON JOB #================================================= -ynh_script_progression --message="Adding cron job to generate metrics..." --weight=1 +ynh_script_progression "Adding cron job to generate metrics..." cron_path="/etc/cron.daily/$app" -ynh_add_config --template="cron" --destination="$cron_path" -chown root: "$cron_path" -chmod 644 "$cron_path" +ynh_config_add --template="cron" --destination="$cron_path" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root: "$cron_path" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 644 "$cron_path" #================================================= # 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 901e482..9b6b457 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,25 +1,19 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh 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..." -ynh_remove_nginx_config +ynh_config_remove_nginx -ynh_secure_remove --file="/etc/cron.daily/$app" +ynh_safe_rm "/etc/cron.daily/$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 cea07a9..9bf4593 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,9 +7,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" chown -R root:root "$install_dir/sources" chown -R $app:www-data "$install_dir/public" @@ -25,22 +19,20 @@ chown -R $app:www-data "$install_dir/public" #================================================= # 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_file --origin_path="/etc/cron.daily/$app" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/cron.daily/$app" -#================================================= -# GENERIC FINALIZATION #================================================= # 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..." -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 e80ded4..b52313e 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,54 +1,46 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -upgrade_type=$(ynh_check_app_version_changed) - #================================================= # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) #================================================= # 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=1 + ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/sources" fi -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" #================================================= # 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 #================================================= # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #================================================= # GENERATE CONFIG PANEL #================================================= -ynh_script_progression --message="Generating configuration panel..." --weight=1 +ynh_script_progression "Generating configuration panel..." generate_config_panel chmod 400 "$install_dir/public/organization.properties" chown $app:www-data "$install_dir/public/organization.properties" -ynh_store_file_checksum --file="$install_dir/public/organization.properties" +ynh_store_file_checksum "$install_dir/public/organization.properties" #================================================= # 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]