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

135 lines
5.1 KiB
Text
Raw Normal View History

2021-09-18 14:27:12 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
2023-03-31 20:51:42 +02:00
#REMOVEME? ynh_abort_if_errors
2021-09-18 14:27:12 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2023-03-31 20:51:42 +02:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
2021-09-18 14:27:12 +02:00
2023-03-31 20:51:42 +02:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2021-09-18 14:27:12 +02:00
2023-03-31 20:51:42 +02:00
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
2021-09-18 14:27:12 +02:00
#=================================================
# CHECK IF ETHERPAD CAN BE RESTORED
#=================================================
2023-03-31 20:51:42 +02:00
#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=2
2021-09-18 14:27:12 +02:00
2023-03-31 20:51:42 +02:00
#REMOVEME? test ! -d $install_dir \
|| ynh_die --message="There is already a directory: $install_dir "
2021-09-18 14:27:12 +02:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2023-03-31 20:51:42 +02:00
#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
2021-09-18 14:27:12 +02:00
# Create the dedicated user (if not existing)
2023-03-31 20:51:42 +02:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2021-09-18 14:27:12 +02:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=2
2023-03-31 20:51:42 +02:00
ynh_restore_file --origin_path="$install_dir"
2021-09-18 14:27:12 +02:00
2023-03-31 20:51:42 +02:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2021-09-18 14:27:12 +02:00
2021-09-18 14:36:33 +02:00
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1
2023-03-31 20:51:42 +02:00
ynh_restore_file --origin_path="$data_dir" --not_mandatory
2021-09-18 14:36:33 +02:00
2023-03-31 20:51:42 +02:00
mkdir -p $data_dir
2021-09-18 14:36:33 +02:00
2023-03-31 20:51:42 +02:00
chmod 750 "$data_dir"
chmod -R o-rwx "$data_dir"
chown -R $app:www-data "$data_dir"
2021-09-18 14:36:33 +02:00
2021-09-18 14:27:12 +02:00
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2023-03-31 20:51:42 +02:00
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=7
2021-09-18 14:27:12 +02:00
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2022-08-18 11:24:30 +02:00
#=================================================
# 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"
2021-09-18 14:36:33 +02:00
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
2023-03-31 20:51:42 +02:00
#REMOVEME? ynh_script_progression --message="Restoring the MySQL database..." --weight=1
2021-09-18 14:36:33 +02:00
2023-03-31 20:51:42 +02:00
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#REMOVEME? ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
2021-09-18 14:36:33 +02:00
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
2021-09-18 14:27:12 +02:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3
2021-09-18 22:24:48 +02:00
yunohost service add $app --description="Workflow Automation Tool" --log="/var/log/$app/$app.log"
2021-09-18 14:27:12 +02:00
#=================================================
# 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
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=8
2021-09-18 19:44:48 +02:00
ynh_systemd_action --service_name=$app --action=restart --log_path=systemd --line_match="Editor is now accessible via:"
2021-09-18 14:27:12 +02:00
#=================================================
# 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
#=================================================
# END OF SCRIPT
#=================================================
2021-09-18 15:01:21 +02:00
ynh_script_progression --message="Restoration completed for $app" --last