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

151 lines
5.8 KiB
Text
Raw Normal View History

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
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
2021-03-19 04:09:26 +01:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2023-05-29 17:10:43 +02:00
#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
2021-03-19 04:09:26 +01:00
# Create the dedicated user (if not existing)
2023-05-29 17:23:44 +02:00
ynh_system_user_create --username="$app-guacd"
ynh_system_user_create --username="$app-tomcat"
2021-03-19 04:09:26 +01:00
#=================================================
# RESTORE THE APP MAIN DIR
2021-03-19 04:09:26 +01:00
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
2021-03-19 04:09:26 +01:00
2023-05-29 17:10:43 +02:00
ynh_restore_file --origin_path="$install_dir"
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1
2021-03-19 04:09:26 +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
#=================================================
# SPECIFIC RESTORATION
2021-03-19 04:09:26 +01:00
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2023-05-29 17:23:44 +02:00
ynh_script_progression --message="Reinstalling dependencies..." --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
# Define and install dependencies
2023-05-29 17:10:43 +02:00
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
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
2021-03-22 21:39:41 +01:00
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
2023-05-29 17:10:43 +02:00
chown -R nobody $install_dir
chmod -R o-rwx $install_dir
setfacl -n -R -m user:$app-guacd:rx -m default:user:$app-guacd:rx $install_dir
setfacl -n -R -m user:$app-tomcat:rx -m default:user:$app-tomcat:rx $install_dir
chown -R nobody:$app-tomcat "$install_dir/etc/tomcat9/" "$install_dir/etc/guacamole/"
chown -R "$app-tomcat":"$app-tomcat" "$install_dir/var/lib/tomcat9/webapps"
setfacl -n -R -m user:$app-guacd:- -m default:user:$app-guacd:- "$install_dir/var/lib/tomcat9/" "$install_dir/etc/guacamole/" "$install_dir/etc/tomcat9/"
2021-03-22 21:39:41 +01:00
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
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_restore_file --origin_path="/var/log/$app"
chown -R $app-guacd:$app-guacd "/var/log/$app/guacd/"
chown -R $app-tomcat:$app-tomcat "/var/log/$app/tomcat/"
2021-03-19 04:09:26 +01:00
#=================================================
# RESTORE SYSTEMD
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
2021-03-19 04:09:26 +01:00
2021-03-21 05:17:45 +01:00
ynh_restore_file --origin_path="/etc/systemd/system/$app-guacd.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-tomcat.service"
systemctl enable "$app-guacd.service" --quiet
systemctl enable "$app-tomcat.service" --quiet
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# INTEGRATE SERVICES IN YUNOHOST
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Integrating services in YunoHost..." --weight=1
2021-03-19 04:09:26 +01:00
2021-03-21 05:17:45 +01:00
yunohost service add "$app-guacd" --description="Guacamole server" --log="/var/log/$app/guacd.log"
yunohost service add "$app-tomcat" --description="Guacamole client" --log="/var/log/$app/tomcat.log"
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
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Starting 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
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
2021-03-19 04:09:26 +01:00
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
2021-03-21 05:17:45 +01:00
# RELOAD NGINX
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
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