2015-11-22 14:37:01 +01:00
#!/bin/bash
2017-03-01 19:37:00 +01:00
#=================================================
2017-09-05 00:24:01 +02:00
# GENERIC START
2017-03-01 19:37:00 +01:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2021-05-16 16:15:54 +02:00
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
2018-07-13 17:33:34 +02:00
source ../settings/scripts/_common.sh
2016-07-16 13:05:02 +02:00
source /usr/share/yunohost/helpers
2017-09-05 00:24:01 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2022-10-20 00:14:07 +02:00
ynh_clean_setup () {
true
}
2017-09-05 00:24:01 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-03-01 19:37:00 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2022-10-20 00:14:07 +02:00
ynh_script_progression --message="Loading settings..." --weight=2
2017-03-01 19:37:00 +01:00
2016-06-29 00:13:30 +02:00
app=$YNH_APP_INSTANCE_NAME
2017-03-01 19:37:00 +01:00
2019-05-20 23:09:08 +02:00
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)
2021-05-16 16:15:54 +02:00
db_user=$db_name
2020-11-25 20:55:09 +01:00
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2021-05-16 16:15:54 +02:00
admin=$(ynh_app_setting_get --app=$app --key=admin)
2017-03-01 19:37:00 +01:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2022-10-20 00:14:07 +02:00
ynh_script_progression --message="Validating restoration parameters..." --weight=1
2015-11-22 14:37:01 +01:00
2022-10-20 00:14:07 +02:00
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
2017-03-01 19:37:00 +01:00
2018-07-13 17:33:34 +02:00
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Activating maintenance mode..." --weight=2
2018-07-13 17:33:34 +02:00
ynh_maintenance_mode_ON
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
# STANDARD RESTORATION STEPS
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
# RECREATE THE DEDICATED USER
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Recreating the dedicated system user..." --weight=2
2017-03-01 19:37:00 +01:00
2021-05-16 16:15:54 +02:00
# Create the dedicated user (if not existing)
2022-10-20 00:14:07 +02:00
ynh_system_user_create --username=$app --home_dir="$final_path"
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
# RESTORE THE APP MAIN DIR
2017-03-01 19:37:00 +01:00
#=================================================
2022-10-20 00:14:07 +02:00
ynh_script_progression --message="Restoring the app main directory..." --weight=1
2017-03-01 19:37:00 +01:00
2021-05-16 16:15:54 +02:00
ynh_restore_file --origin_path="$final_path"
2017-03-01 19:37:00 +01:00
2021-05-16 16:15:54 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2015-11-22 14:37:01 +01:00
2017-12-11 20:37:45 +01:00
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=7
2017-12-11 20:37:45 +01:00
2019-05-20 23:09:08 +02:00
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
2019-01-19 12:00:42 +01:00
ynh_systemd_action --action=restart --service_name=fail2ban
2017-12-11 20:37:45 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
# SPECIFIC RESTORATION
2022-10-20 00:14:07 +02:00
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the PHP-FPM configuration..." --weight=1
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
# RESTORE THE MYSQL DATABASE
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Restoring the MySQL database..." --weight=3
2017-03-10 22:11:21 +01:00
2021-05-16 16:15:54 +02: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
2017-03-01 19:37:00 +01:00
2017-03-10 22:11:21 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
# RESTORE VARIOUS FILES
2017-03-10 22:11:21 +01:00
#=================================================
2022-10-20 00:14:07 +02:00
ynh_script_progression --message="Restoring various files..." --weight=1
2017-03-10 22:11:21 +01:00
2021-05-16 16:15:54 +02:00
ynh_restore_file --origin_path="/etc/cron.d/$app"
2017-03-10 22:11:21 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
# GENERIC FINALIZATION
2017-03-01 19:37:00 +01:00
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
2022-10-20 00:14:07 +02:00
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
2017-03-01 19:37:00 +01:00
2021-05-16 16:15:54 +02:00
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
2019-05-20 23:09:08 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2018-07-13 17:33:34 +02:00
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Disabling maintenance mode..." --weight=2
2018-07-13 17:33:34 +02:00
ynh_maintenance_mode_OFF
2017-12-16 23:21:37 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2019-01-21 13:09:35 +01:00
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
2017-12-16 23:21:37 +01:00
2019-01-30 19:26:05 +01:00
echo "You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
2019-01-21 13:09:35 +01:00
2019-01-30 19:26:05 +01:00
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/leed_ynh__URL_TAG3__." > mail_to_send
2019-01-21 13:09:35 +01:00
2019-05-20 23:09:08 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type=restore
2019-01-30 16:15:24 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Restoration completed for $app" --last