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

120 lines
4.1 KiB
Text
Raw Normal View History

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
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
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-07-21 09:11:11 +02:00
ynh_script_progression --message="Restoring Node-RED main directory..." --weight=10
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-21 09:11:11 +02:00
chown -R $app:www-data "$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
#=================================================
# 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-01-08 23:12:27 +01:00
yunohost service add $app --description="Low-code programming for event-driven applications" --log="/var/log/$app/$app.log"
2019-05-29 00:20:58 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2020-08-29 15:07:15 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2019-05-29 00:20:58 +02:00
ynh_systemd_action --service_name=$app --action="start"
2019-05-29 00:20:58 +02:00
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
2020-08-29 14:45:14 +02:00
# RELOAD NGINX
2019-05-29 00:20:58 +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
#=================================================
ynh_script_progression --message="Restoration completed for Node-RED" --last