2017-03-02 15:44:54 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-09-03 23:31:52 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2017-03-02 15:44:54 +01:00
|
|
|
|
2018-09-03 23:31:52 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2017-03-02 15:44:54 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2018-09-03 23:31:52 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
#### Remove this function if there's nothing to clean before calling the remove script.
|
|
|
|
true
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2021-01-20 08:46:17 +01:00
|
|
|
ynh_script_progression --message="Loading settings..." --weight=1
|
2018-09-03 23:31:52 +02:00
|
|
|
|
2017-03-29 19:25:52 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-07-10 19:22:37 +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)
|
|
|
|
|
|
|
|
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
|
|
|
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
|
2018-09-03 23:31:52 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2021-01-20 08:46:17 +01:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2018-09-03 23:31:52 +02:00
|
|
|
|
2020-07-10 19:22:37 +02: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 "
|
2017-03-09 17:27:59 +01:00
|
|
|
|
2018-09-03 23:31:52 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-10 19:22:37 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2018-09-03 23:31:52 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
2021-01-20 08:46:17 +01:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=2
|
2018-09-03 23:31:52 +02:00
|
|
|
|
2020-07-10 19:22:37 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2017-03-10 16:59:58 +01:00
|
|
|
|
2018-09-03 23:39:42 +02:00
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2021-01-20 08:46:17 +01:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=3
|
2018-09-03 23:39:42 +02:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2020-07-10 19:22:37 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
2017-03-10 16:59:58 +01:00
|
|
|
|
2018-09-03 23:31:52 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
2017-03-10 16:59:58 +01:00
|
|
|
|
2020-07-10 19:22:37 +02:00
|
|
|
# Restore permissions on app files
|
|
|
|
chown -R $app:www-data $final_path
|
2021-03-25 08:38:38 +01:00
|
|
|
find $final_path -type f -exec chmod 660 {} \;
|
|
|
|
find $final_path/bin -type f -exec chmod 770 {} \;
|
|
|
|
find $final_path -type d -exec chmod 770 {} \;
|
2020-07-10 19:22:37 +02:00
|
|
|
find $final_path -type d -exec chmod +s {} \;
|
2017-03-09 17:27:59 +01:00
|
|
|
|
2018-09-03 21:35:41 +02:00
|
|
|
#=================================================
|
2021-02-07 17:05:09 +01:00
|
|
|
# RESTORE THE CRON
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/cron.d/$app"
|
|
|
|
|
|
|
|
#=================================================
|
2018-09-03 23:31:52 +02:00
|
|
|
# RESTORE THE PHP-FPM CONFIGURATION
|
2018-09-03 21:35:41 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-07-10 19:22:37 +02:00
|
|
|
# Restore the file first, so it can have a backup if different
|
|
|
|
ynh_restore_file --origin_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf"
|
2017-03-02 15:44:54 +01:00
|
|
|
|
2020-07-10 19:22:37 +02:00
|
|
|
# Recreate a dedicated php-fpm config
|
2021-01-21 22:40:50 +01:00
|
|
|
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --package="$extra_php_dependencies"
|
2017-03-09 17:27:59 +01:00
|
|
|
|
2018-09-03 23:31:52 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX AND PHP-FPM
|
|
|
|
#=================================================
|
2021-01-20 08:52:18 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
|
2017-04-01 17:03:40 +02:00
|
|
|
|
2020-07-10 19:22:37 +02:00
|
|
|
ynh_systemd_action --service_name=php${YNH_PHP_VERSION}-fpm --action=restart
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-10-26 15:25:19 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-01-20 08:46:17 +01:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|