1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/n8n_ynh.git synced 2024-09-03 19:55:52 +02:00

Merge pull request #48 from YunoHost-Apps/version-2

Version 2
This commit is contained in:
eric_G 2023-10-15 14:41:19 +02:00 committed by GitHub
commit c6d0a95f84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 172 additions and 582 deletions

View file

@ -16,7 +16,8 @@ Si vous navez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po
## Vue densemble
n8n is an extendable workflow automation tool. With a fair-code distribution model, n8n will always have visible source code, be available to self-host, and allow you to add your own custom functions, logic and apps. n8n's node-based approach makes it highly versatile, enabling you to connect anything to everything.
n8n est un outil d'automatisation de flux de travail extensible. Avec un modèle de distribution de code équitable, n8n aura toujours un code source visible, sera disponible pour s'auto-héberger et vous permettra d'ajouter vos propres fonctions, logiques et applications personnalisées. L'approche basée sur les nœuds de n8n le rend très polyvalent, vous permettant de connecter n'importe quoi à tout.
**Version incluse :** 1.9.3~ynh1

View file

@ -1,24 +0,0 @@
;; Test complet
; Manifest
domain="domain.tld"
path="/path"
is_public=1
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=0d34c8a15f95a3dc3b9e1d233bc03410d182628a
backup_restore=1
multi_instance=0
change_url=1
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=0d34c8a15f95a3dc3b9e1d233bc03410d182628a
name=#29
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&port=9001&

View file

@ -1,5 +1,5 @@
# Folder where data should be saved
N8N_USER_FOLDER=__DATADIR__
N8N_USER_FOLDER=__DATA_DIR__
# Disable Basic Auth in favour of User Management
N8N_BASIC_AUTH_ACTIVE=false
@ -13,22 +13,23 @@ WEBHOOK_URL=https://__DOMAIN____PATH__
# Optional timezone to set which gets used by Cron-Node by default
# If not set New York time will be used
GENERIC_TIMEZONE=__TIMEZONE__
TZ=__TIMEZONE__
N8N_DEFAULT_LOCALE=__LANGUAGE__
# Use http (we're behind a reverse-proxy)
N8N_PROTOCOL=http
N8N_LISTEN_ADDRESS=127.0.0.1
N8N_PORT=__PORT__
# Use filesystem for binary data and keep it for 2 hours
N8N_DEFAULT_BINARY_DATA_MODE=filesystem
N8N_PERSISTED_BINARY_DATA_TTL=120
DB_TYPE=mysqldb
DB_MYSQLDB_DATABASE=__DB_NAME__
DB_MYSQLDB_HOST="localhost"
DB_MYSQLDB_PORT=3306
DB_MYSQLDB_USER=__DB_USER__
DB_MYSQLDB_PASSWORD=__DB_PWD__
DB_TYPE=postgresdb
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_HOST="localhost"
DB_POSTGRESDB_USER=__DB_USER__
DB_POSTGRESDB_PASSWORD=__DB_PWD__
DB_POSTGRESDB_DATABASE=__DB_NAME__
EXECUTIONS_DATA_SAVE_ON_ERROR=all
EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
@ -41,6 +42,6 @@ EXECUTIONS_DATA_PRUNE_MAX_COUNT=2000
N8N_EMAIL_MODE=smtp
N8N_SMTP_HOST=localhost
N8N_SMTP_PORT=25
N8N_SMTP_USER=__ADMIN__
N8N_SMTP_PASS=
N8N_SMTP_USER=__APP__
N8N_SMTP_PASS=__MAIL_PWD__
N8N_SMTP_SENDER=__EMAIL__

View file

@ -6,10 +6,10 @@ After=syslog.target network.target
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
WorkingDirectory=__INSTALL_DIR__/
Environment=PATH=__ENV_PATH__
Environment=NODE_ENV=production
ExecStart=__FINALPATH__/node_modules/n8n/bin/n8n
ExecStart=__INSTALL_DIR__/node_modules/n8n/bin/n8n
Restart=always
# Sandboxing options to harden security

1
doc/DESCRIPTION_fr.md Normal file
View file

@ -0,0 +1 @@
n8n est un outil d'automatisation de flux de travail extensible. Avec un modèle de distribution de code équitable, n8n aura toujours un code source visible, sera disponible pour s'auto-héberger et vous permettra d'ajouter vos propres fonctions, logiques et applications personnalisées. L'approche basée sur les nœuds de n8n le rend très polyvalent, vous permettant de connecter n'importe quoi à tout.

2
doc/PRE_UPGRADE.md Normal file
View file

@ -0,0 +1,2 @@
n8n deprecated MySQL and MariaDB as backend databases in version 0.227.0. n8n recommends using PostgreSQL.
This upgrade does not convert the database MySQL to PostgreSQL.

View file

@ -1,59 +0,0 @@
{
"name": "n8n",
"id": "n8n",
"packaging_format": 1,
"description": {
"en": "Workflow Automation Tool. Easily automate tasks across different services",
"fr": "Outil d'automatisation du flux de travail. Automatisez facilement les tâches sur différents services"
},
"version": "1.9.3~ynh1",
"url": "https://n8n.io/",
"upstream": {
"license": "Apache-2.0",
"website": "https://n8n.io/",
"admindoc": "https://docs.n8n.io/",
"code": "https://github.com/n8n-io/n8n"
},
"license": "Apache-2.0",
"maintainer": {
"name": ""
},
"requirements": {
"yunohost": ">= 11.2"
},
"multi_instance": false,
"services": [
"nginx"
],
"arguments": {
"install" : [
{
"name": "domain",
"type": "domain"
},
{
"name": "path",
"type": "path",
"example": "/n8n",
"default": "/n8n"
},
{
"name": "admin",
"type": "user",
"help": {
"en": "Users email address to use for notifications",
"fr": "Adresse e-mail des utilisateurs à utiliser pour les notifications"
}
},
{
"name": "is_public",
"type": "boolean",
"help": {
"en": "If enabled, n8n will be accessible by people who do not have an account. This can be changed later via the webadmin.",
"fr": "Si cette case est cochée, n8n sera accessible aux personnes nayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin."
},
"default": true
}
]
}
}

70
manifest.toml Normal file
View file

@ -0,0 +1,70 @@
packaging_format = 2
id = "n8n"
name = "n8n"
description.en = "Workflow Automation Tool. Easily automate tasks across different services"
description.fr = "Outil d'automatisation du flux de travail. Automatisez facilement les tâches sur différents services"
version = "1.9.3~ynh1"
maintainers = []
[upstream]
license = "Apache-2.0"
website = "https://n8n.io/"
admindoc = "https://docs.n8n.io/"
code = "https://github.com/n8n-io/n8n"
[integration]
yunohost = ">= 11.2"
architectures = "all"
multi_instance = false
ldap = false
sso = false
disk = "50M"
ram.build = "1500M"
ram.runtime = "50M"
[install]
[install.domain]
type = "domain"
[install.path]
type = "path"
default = "/n8n"
[install.admin]
help.en = "Users email address to use for notifications"
help.fr = "Adresse e-mail des utilisateurs à utiliser pour les notifications"
type = "user"
[install.init_main_permission]
type = "group"
default = "visitors"
[install.language]
ask.en = "Choose the application language"
ask.fr = "Choisissez la langue de l'application"
type = "select"
choices = ["fr", "en"]
default = "fr"
[resources]
[resources.ports]
[resources.system_user]
allow_email = true
[resources.install_dir]
[resources.data_dir]
[resources.permissions]
main.url = "/"
[resources.apt]
packages = "postgresql"
[resources.database]
type = "postgresql"

View file

@ -8,6 +8,8 @@ nodejs_version=20
n8n_version=1.9.3
timezone="$(cat /etc/timezone)"
#=================================================
# PERSONAL HELPERS
#=================================================

View file

@ -9,24 +9,6 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
@ -36,13 +18,13 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
ynh_backup --src_path="$install_dir"
#=================================================
# BACKUP THE DATA DIR
#=================================================
ynh_backup --src_path="$datadir" --is_big
ynh_backup --src_path="$data_dir" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION
@ -57,11 +39,11 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# BACKUP THE MYSQL DATABASE
# BACKUP THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
ynh_psql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT

View file

@ -9,66 +9,7 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
admin=$(ynh_app_setting_get --app=$app --key=admin)
timezone="$(cat /etc/timezone)"
email=$(ynh_app_setting_get --app=$app --key=email)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up $app before changing its URL (may take a while)..." --weight=2
# Backup the current version of n8n
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
email=$(ynh_user_get_info --username=$admin --key=mail)
#=================================================
# STANDARD MODIFICATIONS
@ -84,29 +25,7 @@ ynh_systemd_action --service_name=$app --action=stop --log_path=systemd
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
ynh_change_url_nginx_config
#=================================================
# ADD A CONFIGURATION
@ -115,17 +34,10 @@ ynh_script_progression --message="Adding a configuration file..." --weight=1
domain=$new_domain
path=$new_path
ynh_add_config --template="../conf/.env" --destination="$final_path/.env"
ynh_add_config --template="../conf/.env" --destination="$install_dir/.env"
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
ynh_systemd_action --service_name=nginx --action=reload
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
#=================================================
# START SYSTEMD SERVICE

View file

@ -9,107 +9,24 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
admin=$YNH_APP_ARG_ADMIN
timezone="$(cat /etc/timezone)"
email=$(ynh_user_get_info --username=$admin --key=mail)
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=2
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=2
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=email --value=$email
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port
port=$(ynh_find_port --port=5678)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=6
ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=4
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=1
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
mkdir -p $final_path
mkdir -p $install_dir
#=================================================
# INSTALL n8n
#=================================================
ynh_script_progression --message="Installing $app..." --weight=2
pushd $final_path
ynh_use_nodejs
ynh_exec_warn_less env $ynh_node_load_PATH npm install n8n@${n8n_version}
popd
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# NGINX CONFIGURATION
@ -119,45 +36,34 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=4
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..." --weight=1
env_path="$PATH"
# Create a dedicated systemd config
ynh_add_systemd_config
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
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_add_config --template="../conf/.env" --destination="$final_path/.env"
ynh_add_config --template="../conf/.env" --destination="$install_dir/.env"
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
#=================================================
# SETUP SYSTEMD
# INSTALL n8n
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=4
ynh_script_progression --message="Installing $app..." --weight=2
env_path="$PATH"
# Create a dedicated systemd config
ynh_add_systemd_config
pushd $install_dir
ynh_use_nodejs
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH $ynh_npm install n8n@${n8n_version}
popd
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3
yunohost service add $app --description="Workflow Automation Tool" --log="/var/log/$app/$app.log"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# START SYSTEMD SERVICE
@ -167,24 +73,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=6
# Start a systemd service
ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Editor is now accessible via:"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]
then
ynh_permission_update --permission="main" --add="visitors"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -10,24 +10,11 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
# REMOVE SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# 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
@ -36,67 +23,15 @@ then
yunohost service remove $app
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the MySQL database..." --weight=1
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
ynh_remove_nodejs
#=================================================
# REMOVE ETHERPAD MAIN DIR
#=================================================
ynh_script_progression --message="Removing $app main directory..." --weight=3
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DATA DIR
#=================================================
# Remove the data directory if --purge option is used
if [ "${YNH_APP_PURGE:-0}" -eq 1 ]
then
ynh_script_progression --message="Removing app data directory..." --weight=1
ynh_secure_remove --file="$datadir"
fi
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -9,108 +9,49 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
# CHECK IF ETHERPAD CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=2
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=2
ynh_restore_file --origin_path="$final_path"
ynh_restore_file --origin_path="$install_dir"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1
ynh_restore_file --origin_path="$datadir" --not_mandatory
ynh_restore_file --origin_path="$data_dir" --not_mandatory
mkdir -p $datadir
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
chown -R $app:www-data "$data_dir"
#=================================================
# REINSTALL DEPENDENCIES
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=7
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3
yunohost service add $app --description="Workflow Automation Tool" --log="/var/log/$app/$app.log"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=8
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
yunohost service add $app --description="Workflow Automation Tool" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
@ -118,13 +59,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=8
ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Editor is now accessible via:"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
ynh_systemd_action --service_name=nginx --action=reload
#=================================================

View file

@ -9,24 +9,7 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
admin=$(ynh_app_setting_get --app=$app --key=admin)
timezone="$(cat /etc/timezone)"
email=$(ynh_app_setting_get --app=$app --key=email)
email=$(ynh_user_get_info --username=$admin --key=mail)
#=================================================
# CHECK VERSION
@ -34,20 +17,6 @@ email=$(ynh_app_setting_get --app=$app --key=email)
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
@ -57,50 +26,28 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=42
ynh_systemd_action --service_name=$app --action=stop --log_path="systemd"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if ynh_compare_current_package_version --comparison le --version 0.169.0~ynh1
if ynh_compare_current_package_version --comparison le --version 0.218.0~ynh1
then
ynh_die --message="Upgrade from version 0.169.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 --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"
fi
# If email doesn't exist, create it
if [ -z "$email" ]; then
if [ -z "${email:-}" ]; then
email=$(ynh_user_get_info --username=$admin --key=mail)
ynh_app_setting_set --app=$app --key=email --value=$email
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
pushd $final_path
ynh_use_nodejs
ynh_exec_warn_less env $ynh_node_load_PATH npm install n8n@${n8n_version}
popd
# If language doesn't exist, create it
if [ -z "${language:-}" ]; then
language="en"
ynh_app_setting_set --app=$app --key=language --value=$language
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -109,38 +56,34 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." -
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=12
ynh_install_nodejs --nodejs_version=$nodejs_version
env_path="$PATH"
# Create a dedicated systemd config
ynh_add_systemd_config
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_add_config --template="../conf/.env" --destination="$final_path/.env"
ynh_add_config --template="../conf/.env" --destination="$install_dir/.env"
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
#=================================================
# SETUP SYSTEMD
# INSTALL n8n
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
ynh_script_progression --message="Installing $app..." --weight=2
env_path="$PATH"
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
yunohost service add $app --description="Workflow Automation Tool" --log="/var/log/$app/$app.log"
# 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@${n8n_version}
popd
#=================================================
# START SYSTEMD SERVICE
@ -149,13 +92,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=6
ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Editor is now accessible via:"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================

9
tests.toml Normal file
View file

@ -0,0 +1,9 @@
test_format = 1.0
[default]
# -------------------------------
# Commits to test upgrade from
# -------------------------------
test_upgrade_from.0d34c8a1.name = "Upgrade from #29"