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

183 lines
6.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
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Loading installation settings..." --weight=1
2021-03-19 04:09:26 +01: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)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Validating restoration parameters..." --weight=1
2021-03-19 04:09:26 +01: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"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Restoring the app main directory..." --weight=1
2021-03-19 04:09:26 +01:00
ynh_restore_file --origin_path="$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2021-03-21 05:17:45 +01:00
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)
2021-03-21 05:17:45 +01:00
ynh_system_user_create --username="$app-guacd"
ynh_system_user_create --username="$app-tomcat"
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
# RESTORE VARIOUS FILES
2021-03-19 04:09:26 +01:00
#=================================================
2021-03-21 05:17:45 +01:00
ynh_restore_file --origin_path="/var/log/$app"
2021-03-19 04:09:26 +01:00
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2021-03-21 05:17:45 +01:00
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
2021-03-19 04:09:26 +01:00
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
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
chown -R root:root $final_path
chmod -R o-rwx $final_path
setfacl -n -R -m user:$app-guacd:rx -m default:user:$app-guacd:rx $final_path
setfacl -n -R -m user:$app-tomcat:rx -m default:user:$app-tomcat:rx $final_path
chown -R $app-guacd:$app-guacd "/var/log/$app/guacd/"
chown -R $app-tomcat:$app-tomcat "/var/log/$app/tomcat/"
chown -R root:$app-tomcat "$final_path/etc/tomcat9/" "$final_path/etc/guacamole/"
chown -R "$app-tomcat":"$app-tomcat" "$final_path/var/lib/tomcat9/webapps"
setfacl -n -R -m user:$app-guacd:- -m default:user:$app-guacd:- "$final_path/var/lib/tomcat9/" "$final_path/etc/guacamole/" "$final_path/etc/tomcat9/"
#=================================================
# 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
2021-03-19 04:09:26 +01:00
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
2021-03-21 05:17:45 +01:00
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
2021-03-19 04:09:26 +01:00
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# 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_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