From 4d81bf63e8c414ceb0fa5d47da52db282a43dafd Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sat, 31 Aug 2024 01:12:42 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- conf/systemd.service | 4 +-- manifest.toml | 3 +- scripts/_common.sh | 14 +-------- scripts/backup | 23 +++++---------- scripts/change_url | 24 +++++----------- scripts/install | 58 ++++++++++++++++--------------------- scripts/remove | 22 ++++++-------- scripts/restore | 37 ++++++++++-------------- scripts/upgrade | 68 ++++++++++++++++++-------------------------- 9 files changed, 95 insertions(+), 158 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 83db3c9..82f1adc 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,8 +7,8 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__INSTALL_DIR__/ -Environment="__YNH_NODE_LOAD_PATH__" -ExecStart=__YNH_NPM__ run serve +Environment="PATH=__PATH_WITH_NODEJS__" +ExecStart=__NODEJS_DIR__/npm run serve StandardOutput=append:/var/log/__APP__/__APP__.log StandardError=syslog Restart=always diff --git a/manifest.toml b/manifest.toml index 94f6bce..19e9447 100644 --- a/manifest.toml +++ b/manifest.toml @@ -17,7 +17,8 @@ admindoc = "https://manual.os-js.org/" code = "https://github.com/os-js/OS.js" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = false diff --git a/scripts/_common.sh b/scripts/_common.sh index d5160da..7417f0c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,19 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= nodejs_version=10 - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index d1816f1..228a774 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,44 +1,35 @@ #!/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" #================================================= # SYSTEM 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/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/var/log/$app/" +ynh_backup "/var/log/$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 7bfa55f..34ecde2 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,42 +1,32 @@ #!/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..." +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..." +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server listening on" +ynh_systemctl --service="$app" --action="start" --wait_until="Server listening on" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 1737890..ffe1fc3 100644 --- a/scripts/install +++ b/scripts/install @@ -1,44 +1,37 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # INSTALL NODEJS #================================================= -ynh_script_progression --message="Installing NodeJS..." +ynh_script_progression "Installing NodeJS..." -ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." ynh_setup_source --dest_dir="$install_dir" -chmod -R o-rwx "$install_dir" -chown -R "$app:$app" "$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:$app" "$install_dir" #================================================= # SPECIFIC SETUP #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." +ynh_script_progression "Adding $app's configuration..." -ynh_add_config --template="client.config.js" --destination="$install_dir/src/client/config.js" +ynh_config_add --template="client.config.js" --destination="$install_dir/src/client/config.js" -chmod 400 "$install_dir/src/client/config.js" -chown "$app:$app" "$install_dir/src/client/config.js" +#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 400 "$install_dir/src/client/config.js" +#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 "$app:$app" "$install_dir/src/client/config.js" -ynh_add_config --template="server.index.js" --destination="$install_dir/src/server/index.js" +ynh_config_add --template="server.index.js" --destination="$install_dir/src/server/index.js" chmod 400 "$install_dir/src/server/index.js" chown "$app:$app" "$install_dir/src/server/index.js" @@ -46,43 +39,42 @@ chown "$app:$app" "$install_dir/src/server/index.js" #================================================= # BUILD APP #================================================= -ynh_script_progression --message="Building $app..." +ynh_script_progression "Building $app..." pushd "$install_dir" - ynh_use_nodejs - ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" install - ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" run package:discover - ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" run build - ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" install --save --production @osjs/pam-auth + + ynh_hide_warnings ynh_exec_as_app node_load_PATH" npm install + ynh_hide_warnings ynh_exec_as_app node_load_PATH" npm run package:discover + ynh_hide_warnings ynh_exec_as_app node_load_PATH" npm run build + ynh_hide_warnings ynh_exec_as_app node_load_PATH" npm install --save --production @osjs/pam-auth popd -ynh_replace_string --match_string="8000" --replace_string="$port" --target_file="$install_dir/src/server/config.js" - -chown -R "$app:$app" "$install_dir" +ynh_replace --match="8000" --replace="$port" --file="$install_dir/src/server/config.js" +#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:$app" "$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..." -ynh_add_nginx_config +ynh_config_add_nginx -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --description="Desktop you have accesss through your browser" --log="/var/log/$app/$app.log" # Use logrotate to manage application logfile(s) -ynh_use_logrotate +ynh_config_add_logrotate #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server listening on" +ynh_systemctl --service="$app" --action="start" --wait_until="Server listening on" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index c3607b8..3319949 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,36 +1,30 @@ #!/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..." # 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_logrotate +ynh_config_remove_logrotate -ynh_remove_nginx_config +ynh_config_remove_nginx -ynh_remove_nodejs +ynh_nodejs_remove -ynh_secure_remove --file="/var/log/$app" +#REMOVEME? (Apps should not remove their log dir during remove ... this should only happen if --purge is used, and be handled by the core...) ynh_safe_rm "/var/log/$app" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 12b21ac..75a0f3a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,61 +1,54 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # REINSTALL NODEJS #================================================= -ynh_script_progression --message="Reinstalling NodeJS..." +ynh_script_progression "Reinstalling NodeJS..." -ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod -R o-rwx "$install_dir" -chown -R "$app:$app" "$install_dir" +ynh_restore "$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:$app" "$install_dir" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -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 yunohost service add "$app" --description="Desktop you have accesss through your browser" --log="/var/log/$app/$app.log" -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_restore_file --origin_path="/var/log/$app/" +ynh_restore "/var/log/$app/" #================================================= # START SYSTEMD 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="$app" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server listening on" +ynh_systemctl --service="$app" --action="start" --wait_until="Server listening on" -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" +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index a1130af..19f6894 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,53 +1,42 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +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" #================================================= # INSTALL NODEJS #================================================= -ynh_script_progression --message="Updating NodeJS..." +ynh_script_progression "Updating NodeJS..." -ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." +ynh_script_progression "Upgrading source files..." -ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="src/client/config.js src/server/index.js" +ynh_setup_source --dest_dir="$install_dir" --full_replace --keep="src/client/config.js src/server/index.js" -chmod -R o-rwx "$install_dir" -chown -R "$app:$app" "$install_dir" - -#================================================= -# SPECIFIC UPGRADE +#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:$app" "$install_dir" #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." +ynh_script_progression "Updating configuration..." -ynh_add_config --template="client.config.js" --destination="$install_dir/src/client/config.js" +ynh_config_add --template="client.config.js" --destination="$install_dir/src/client/config.js" -chmod 400 "$install_dir/src/client/config.js" -chown "$app:$app" "$install_dir/src/client/config.js" +#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 400 "$install_dir/src/client/config.js" +#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 "$app:$app" "$install_dir/src/client/config.js" -ynh_add_config --template="server.index.js" --destination="$install_dir/src/server/index.js" +ynh_config_add --template="server.index.js" --destination="$install_dir/src/server/index.js" chmod 400 "$install_dir/src/server/index.js" chown "$app:$app" "$install_dir/src/server/index.js" @@ -55,42 +44,41 @@ chown "$app:$app" "$install_dir/src/server/index.js" #================================================= # BUILD APP #================================================= -ynh_script_progression --message="Building app..." +ynh_script_progression "Building app..." pushd "$install_dir" - ynh_use_nodejs - ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" install - ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" run package:discover - ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" run build - ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" install --save --production @osjs/pam-auth + + ynh_hide_warnings ynh_exec_as_app node_load_PATH" npm install + ynh_hide_warnings ynh_exec_as_app node_load_PATH" npm run package:discover + ynh_hide_warnings ynh_exec_as_app node_load_PATH" npm run build + ynh_hide_warnings ynh_exec_as_app node_load_PATH" npm install --save --production @osjs/pam-auth popd -ynh_replace_string --match_string="8000" --replace_string="$port" --target_file="$install_dir/src/server/config.js" - -chown -R "$app:$app" "$install_dir" +ynh_replace --match="8000" --replace="$port" --file="$install_dir/src/server/config.js" +#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:$app" "$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 -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --description="Desktop you have accesss through your browser" --log="/var/log/$app/$app.log" -ynh_use_logrotate --non-append +ynh_config_add_logrotate #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server listening on" +ynh_systemctl --service="$app" --action="start" --wait_until="Server listening on" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression "Upgrade of $app completed"