2019-05-29 00:20:58 +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
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-08-29 15:07:15 +02:00
|
|
|
ynh_script_progression --message="Loading settings..." --weight=1
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2020-08-29 15:07:15 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2020-08-29 15:07:15 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
|
|
|
|
|
|
|
#=================================================
|
2021-07-21 09:11:11 +02:00
|
|
|
# RESTORE THE APP MAIN DIR
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
2021-09-18 17:20:18 +02:00
|
|
|
ynh_script_progression --message="Restoring Node-RED main directory..." --weight=5
|
2021-07-21 09:11:11 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2021-06-07 23:13:39 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
2021-07-24 13:51:38 +02:00
|
|
|
chown -R $app: "$final_path"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2021-05-25 11:37:52 +02:00
|
|
|
# Create log directory and apply permissions
|
|
|
|
mkdir -p /var/log/$app
|
|
|
|
chown -R $app: /var/log/$app
|
|
|
|
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
2019-10-13 18:52:07 +02:00
|
|
|
# INSTALL NODEJS
|
|
|
|
#=================================================
|
|
|
|
|
2021-05-25 11:37:52 +02:00
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
2020-08-29 15:07:15 +02:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
2020-12-07 09:50:58 +01:00
|
|
|
systemctl enable $app.service --quiet
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2021-12-26 18:03:31 +01:00
|
|
|
yunohost service add $app --description="Low-code programming for event-driven applications" --log_type="systemd"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2021-09-18 17:20:18 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
2019-05-29 00:20:58 +02:00
|
|
|
|
2021-05-24 15:26:59 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start"
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2020-08-29 14:45:14 +02:00
|
|
|
# RELOAD NGINX
|
2019-05-29 00:20:58 +02:00
|
|
|
#=================================================
|
2020-10-16 10:50:34 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2019-05-29 00:20:58 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-10-16 10:50:34 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for Node-RED" --last
|