diff --git a/manifest.toml b/manifest.toml index ecd935b..8a26c0c 100644 --- a/manifest.toml +++ b/manifest.toml @@ -16,7 +16,8 @@ admindoc = "https://docs.n8n.io/" code = "https://github.com/n8n-io/n8n" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = true ldap = false diff --git a/scripts/_common.sh b/scripts/_common.sh index c09932f..9ff791e 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,22 +1,10 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= nodejs_version=20 timezone="$(cat /etc/timezone)" main_domain=$(cat /etc/yunohost/current_host) - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 1687db8..0f1edcf 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,52 +1,43 @@ #!/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 DATA DIR #================================================= -ynh_backup --src_path="$data_dir" --is_big +ynh_backup "$data_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" #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # 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 3459199..723eb4c 100755 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,54 +1,46 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers email=$(ynh_user_get_info --username=$admin --key=mail) -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=2 +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 #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2 +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/.env" --destination="$install_dir/.env" +ynh_config_add --template=".env" --destination="$install_dir/.env" -chmod 400 "$install_dir/.env" -chown $app:$app "$install_dir/.env" +#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/.env" +#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/.env" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=6 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Editor is now accessible via:" +ynh_systemctl --service=$app --action=restart --log_path=systemd --wait_until="Editor is now accessible via:" #================================================= # 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 6d403b9..3731e3d 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 @@ -15,69 +9,67 @@ email=$(ynh_user_get_info --username=$admin --key=mail) # INSTALL DEPENDENCIES #================================================= -ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install #================================================= # 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 mkdir -p $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" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=4 +ynh_script_progression "Configuring NGINX web server..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx env_path="$PATH" # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add $app --description="Workflow Automation Tool" --log="/var/log/$app/$app.log" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression "Adding $app's configuration..." -ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" +ynh_config_add --template=".env" --destination="$install_dir/.env" -chmod 400 "$install_dir/.env" -chown $app:$app "$install_dir/.env" +#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/.env" +#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/.env" #================================================= # INSTALL n8n #================================================= -ynh_script_progression --message="Installing $app..." --weight=2 +ynh_script_progression "Installing $app..." pushd $install_dir - ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH $ynh_npm install n8n@$(ynh_app_upstream_version) - ynh_replace_string --match_string="secure: config_1.default.getEnv('userManagement.emails.smtp.secure'),$" \ - --replace_string="secure: config_1.default.getEnv('userManagement.emails.smtp.secure'), tls: {servername:'${main_domain}'}," \ - --target_file="node_modules/n8n/dist/UserManagement/email/NodeMailer.js" + + ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install n8n@$(ynh_app_upstream_version) + ynh_replace --match="secure: config_1.default.getEnv('userManagement.emails.smtp.secure'),$" \ + --replace="secure: config_1.default.getEnv('userManagement.emails.smtp.secure'), tls: {servername:'${main_domain}'}," \ + --file="node_modules/n8n/dist/UserManagement/email/NodeMailer.js" popd -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" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=6 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Editor is now accessible via:" +ynh_systemctl --service=$app --action=restart --log_path=systemd --wait_until="Editor is now accessible via:" #================================================= # 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 6539ee4..bc22ecc 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,39 +1,34 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= -# REMOVE SYSTEMD SERVICE +# REMOVE SYSTEMD SERVICE + #================================================= -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 +if ynh_hide_warnings yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service integration..." --weight=2 + ynh_script_progression "Removing $app service integration..." yunohost service remove $app fi # Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_config_remove_systemd # Remove metapackage and its dependencies -ynh_remove_nodejs +ynh_nodejs_remove # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx #================================================= # 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 d3c91dd..307d232 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,53 +1,46 @@ #!/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 the app main directory..." --weight=2 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +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: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" chown -R $app:www-data "$data_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +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..." # Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install -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="Workflow Automation Tool" --log="/var/log/$app/$app.log" @@ -55,14 +48,14 @@ yunohost service add $app --description="Workflow Automation Tool" --log="/var/l #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=8 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Editor is now accessible via:" +ynh_systemctl --service=$app --action=restart --log_path=systemd --wait_until="Editor is now accessible via:" -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 eeeadbe..5984e3d 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,102 +1,90 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers email=$(ynh_user_get_info --username=$admin --key=mail) -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=42 +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" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression "Ensuring downward compatibility..." -if ynh_compare_current_package_version --comparison le --version 0.218.0~ynh1 +if ynh_app_upgrading_from_version_before_or_equal_to 0.218.0~ynh1 then - ynh_die --message="Upgrade from version 0.218.0~ynh1 is not possible is not possible yet because data migration is not supported. Please let us know you encounter this message in this issue: https://github.com/YunoHost-Apps/n8n_ynh/issues/18" + ynh_die "Upgrade from version 0.218.0~ynh1 is not possible is not possible yet because data migration is not supported. Please let us know you encounter this message in this issue: https://github.com/YunoHost-Apps/n8n_ynh/issues/18" fi # If email doesn't exist, create it +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=email --value=$(ynh_user_get_info --username=$admin --key=mail) if [ -z "${email:-}" ]; then email=$(ynh_user_get_info --username=$admin --key=mail) - ynh_app_setting_set --app=$app --key=email --value=$email + ynh_app_setting_set --key=email --value=$email fi # If language doesn't exist, create it +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=language --value="en" if [ -z "${language:-}" ]; then language="en" - ynh_app_setting_set --app=$app --key=language --value=$language + ynh_app_setting_set --key=language --value=$language fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 +ynh_script_progression "Upgrading NGINX web server configuration..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx -ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_nodejs_install env_path="$PATH" # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add $app --description="Workflow Automation Tool" --log="/var/log/$app/$app.log" #================================================= # UPGRADE A CONFIGURATION FILE #================================================= -ynh_script_progression --message="Upgrade a configuration file..." --weight=1 +ynh_script_progression "Upgrade a configuration file..." -ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" +ynh_config_add --template=".env" --destination="$install_dir/.env" -chmod 400 "$install_dir/.env" -chown $app:$app "$install_dir/.env" +#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/.env" +#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/.env" #================================================= # INSTALL n8n #================================================= -ynh_script_progression --message="Installing $app..." --weight=2 +ynh_script_progression "Installing $app..." # Download, check integrity, uncompress and patch the source from app.src pushd $install_dir - ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH $ynh_npm install n8n@$(ynh_app_upstream_version) - ynh_replace_string --match_string="secure: config_1.default.getEnv('userManagement.emails.smtp.secure'),$" \ - --replace_string="secure: config_1.default.getEnv('userManagement.emails.smtp.secure'), tls: {servername:'${main_domain}'}," \ - --target_file="node_modules/n8n/dist/UserManagement/email/NodeMailer.js" + + ynh_hide_warnings ynh_exec_as_app node_load_PATH npm install n8n@$(ynh_app_upstream_version) + ynh_replace --match="secure: config_1.default.getEnv('userManagement.emails.smtp.secure'),$" \ + --replace="secure: config_1.default.getEnv('userManagement.emails.smtp.secure'), tls: {servername:'${main_domain}'}," \ + --file="node_modules/n8n/dist/UserManagement/email/NodeMailer.js" popd #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=6 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Editor is now accessible via:" +ynh_systemctl --service=$app --action=restart --log_path=systemd --wait_until="Editor is now accessible via:" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"