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
#=================================================
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
#=================================================
# 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
#=================================================
2019-03-12 20:09:45 +01: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)
admin=$(ynh_app_setting_get --app=$app --key=admin)
2017-03-01 19:37:00 +01:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Validating restoration parameters..."
2015-11-22 14:37:01 +01:00
2019-05-20 23:09:08 +02:00
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
2017-03-01 19:37:00 +01:00
test ! -d $final_path \
2019-05-20 23:09:08 +02:00
|| 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
#=================================================
# STANDARD RESTORE STEPS
#=================================================
2019-01-19 12:13:45 +01:00
# RESTORE THE NGINX CONFIGURATION
2017-03-01 19:37:00 +01:00
#=================================================
2019-05-20 23:09:08 +02:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
2019-01-19 12:13:45 +01:00
# RESTORE THE APP MAIN DIR
2017-03-01 19:37:00 +01:00
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Restoring the app main directory..."
2017-03-01 19:37:00 +01:00
2019-05-20 23:09:08 +02:00
ynh_restore_file --origin_path="$final_path"
2017-03-01 19:37:00 +01:00
#=================================================
2019-01-19 12:13:45 +01:00
# RESTORE THE MYSQL DATABASE
2017-03-01 19:37:00 +01:00
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Restoring the MySQL database..." --weight=3
2015-11-22 14:37:01 +01:00
2019-05-20 23:09:08 +02:00
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql
2017-03-01 19:37:00 +01:00
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Recreating the dedicated system user..." --weight=2
2017-03-01 19:37:00 +01:00
2019-01-19 12:13:45 +01:00
# Create the dedicated user (if not existing)
2019-05-20 23:09:08 +02:00
ynh_system_user_create --username=$app
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
2019-01-19 12:13:45 +01:00
# RESTORE THE PHP-FPM CONFIGURATION
2017-03-01 19:37:00 +01:00
#=================================================
2019-05-20 23:09:08 +02:00
ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf"
2017-03-01 19:37:00 +01:00
2017-12-11 20:37:45 +01:00
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
2019-03-12 20:09:45 +01: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
#=================================================
# SPECIFIC RESTORE
#=================================================
2019-01-19 12:13:45 +01:00
# RESTORE THE CRON FILE
2017-03-01 19:37:00 +01:00
#=================================================
2017-03-10 22:11:21 +01:00
2019-05-20 23:09:08 +02:00
ynh_restore_file --origin_path="/etc/cron.d/$app"
2017-03-01 19:37:00 +01:00
2017-03-10 22:11:21 +01:00
#=================================================
# RESTORE USER RIGHTS
#=================================================
2017-09-05 00:24:01 +02:00
chown -R $app $final_path/cache $final_path/plugins $final_path/updates
2017-03-10 22:11:21 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# GENERIC FINALISATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Reloading nginx web server and php-fpm..."
2017-03-01 19:37:00 +01:00
2019-05-20 23:09:08 +02:00
ynh_systemd_action --service_name=php7.0-fpm --action=reload
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