2021-03-19 04:09:26 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
|
|
source ../settings/scripts/_common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2024-02-25 21:19:54 +01:00
|
|
|
# STOP TOMCAT
|
2021-03-19 04:09:26 +01:00
|
|
|
#=================================================
|
2024-02-25 21:19:54 +01:00
|
|
|
ynh_script_progression --message="Stopping system tomcat..." --weight=1
|
2021-03-21 05:17:45 +01:00
|
|
|
|
|
|
|
tomcat_enabled=""
|
|
|
|
tomcat_active=""
|
|
|
|
if [ "$(systemctl cat tomcat9 --quiet)" ]; then
|
|
|
|
if (systemctl is-enabled tomcat9 --quiet); then
|
|
|
|
tomcat_enabled=1
|
|
|
|
fi
|
|
|
|
if (systemctl is-active tomcat9 --quiet); then
|
|
|
|
tomcat_active=1
|
|
|
|
fi
|
|
|
|
fi
|
2021-03-19 04:09:26 +01:00
|
|
|
|
2021-03-21 05:17:45 +01:00
|
|
|
if [ ! $tomcat_enabled ]; then
|
|
|
|
systemctl disable tomcat9 --quiet
|
|
|
|
fi
|
|
|
|
if [ ! $tomcat_active ]; then
|
|
|
|
systemctl stop tomcat9 --quiet
|
|
|
|
fi
|
|
|
|
|
2024-02-25 21:19:54 +01:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$install_dir"
|
|
|
|
chown -R "$app:www-data" "$install_dir"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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-guacd"
|
|
|
|
ynh_system_user_create --username="$app-tomcat"
|
|
|
|
|
2021-03-19 04:09:26 +01:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE MYSQL DATABASE
|
|
|
|
#=================================================
|
2023-05-29 17:23:44 +02:00
|
|
|
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
|
2021-03-19 04:09:26 +01:00
|
|
|
|
|
|
|
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
|
|
|
|
2021-08-07 13:59:24 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE VARIOUS FILES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring various files..."
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/var/log/$app"
|
2024-02-25 21:12:49 +01:00
|
|
|
|
|
|
|
_set_permissions
|
2021-08-07 13:59:24 +02:00
|
|
|
|
2021-03-19 04:09:26 +01:00
|
|
|
#=================================================
|
2024-02-25 21:19:54 +01:00
|
|
|
# RESTORE SYSTEM CONFIGURATIONS
|
2021-03-19 04:09:26 +01:00
|
|
|
#=================================================
|
2024-02-25 21:19:54 +01:00
|
|
|
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
|
2021-03-19 04:09:26 +01:00
|
|
|
|
2024-02-25 21:19:54 +01:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2021-03-19 04:09:26 +01:00
|
|
|
|
2024-02-25 21:19:54 +01:00
|
|
|
ynh_restore_file "/etc/fail2ban/jail.d/$app.conf"
|
|
|
|
ynh_restore_file "/etc/fail2ban/filter.d/$app.conf"
|
|
|
|
ynh_systemd_action --action=restart --service_name=fail2ban
|
2021-03-19 04:09:26 +01:00
|
|
|
|
2024-02-25 21:19:54 +01:00
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app-guacd.service"
|
|
|
|
systemctl enable "$app-guacd.service" --quiet
|
2021-03-21 05:17:45 +01:00
|
|
|
yunohost service add "$app-guacd" --description="Guacamole server" --log="/var/log/$app/guacd.log"
|
2024-02-25 21:19:54 +01:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app-tomcat.service"
|
|
|
|
systemctl enable "$app-tomcat.service" --quiet
|
2021-03-21 05:17:45 +01:00
|
|
|
yunohost service add "$app-tomcat" --description="Guacamole client" --log="/var/log/$app/tomcat.log"
|
2021-03-19 04:09:26 +01:00
|
|
|
|
2024-02-25 21:19:54 +01:00
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
|
2021-03-19 04:09:26 +01:00
|
|
|
#=================================================
|
2021-03-21 05:17:45 +01:00
|
|
|
# START SYSTEMD SERVICES
|
2021-03-19 04:09:26 +01:00
|
|
|
#=================================================
|
2024-02-25 21:19:54 +01:00
|
|
|
ynh_script_progression --message="Starting NGINX and $app's systemd services..." --weight=1
|
2021-03-19 04:09:26 +01:00
|
|
|
|
2021-03-21 05:17:45 +01:00
|
|
|
ynh_systemd_action --service_name="$app-guacd" --action="start" --log_path="/var/log/$app/guacd.log"
|
|
|
|
ynh_systemd_action --service_name="$app-tomcat" --action="start" --log_path="/var/log/$app/tomcat.log"
|
2021-03-19 04:09:26 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-03-21 05:17:45 +01:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|