mirror of
https://github.com/YunoHost-Apps/guacamole_ynh.git
synced 2024-09-03 19:16:03 +02:00
150 lines
5.8 KiB
Bash
Executable file
150 lines
5.8 KiB
Bash
Executable file
#!/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..."
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
#=================================================
|
|
# RECREATE THE DEDICATED USER
|
|
#=================================================
|
|
#REMOVEME? 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"
|
|
|
|
#=================================================
|
|
# RESTORE THE APP MAIN DIR
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
|
|
|
ynh_restore_file --origin_path="$install_dir"
|
|
|
|
#=================================================
|
|
# RESTORE FAIL2BAN CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1
|
|
|
|
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
|
|
#=================================================
|
|
# REINSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
|
|
|
|
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
|
|
|
|
# Define and install dependencies
|
|
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
if [ ! $tomcat_enabled ]; then
|
|
systemctl disable tomcat9 --quiet
|
|
fi
|
|
if [ ! $tomcat_active ]; then
|
|
systemctl stop tomcat9 --quiet
|
|
fi
|
|
|
|
#=================================================
|
|
# RESTORE USER RIGHTS
|
|
#=================================================
|
|
|
|
# Restore permissions on app files
|
|
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/"
|
|
|
|
#=================================================
|
|
# RESTORE THE MYSQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
|
|
|
|
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/"
|
|
|
|
#=================================================
|
|
# RESTORE SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICES IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating services in YunoHost..." --weight=1
|
|
|
|
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"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICES
|
|
#=================================================
|
|
ynh_script_progression --message="Starting systemd services..." --weight=1
|
|
|
|
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"
|
|
|
|
#=================================================
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the logrotate configuration..."
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|