2015-05-30 19:37:21 +02:00
|
|
|
#!/bin/bash
|
2015-12-18 14:11:35 +01:00
|
|
|
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2018-05-22 20:01:55 +02:00
|
|
|
# GENERIC START
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-12-14 16:02:43 +01:00
|
|
|
|
2022-03-12 15:39:54 +01:00
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2018-07-13 17:37:28 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2016-12-14 16:02:43 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2018-05-22 20:01:55 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2017-08-05 23:16:02 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2021-07-11 16:19:12 +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-07-11 17:07:22 +02:00
|
|
|
db_user=$db_name
|
2021-07-11 13:22:15 +02:00
|
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
2015-05-30 19:37:21 +02:00
|
|
|
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2021-07-11 16:19:12 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2015-05-30 19:37:21 +02:00
|
|
|
|
2017-08-05 23:16:02 +02:00
|
|
|
test ! -d $final_path \
|
2021-07-11 16:19:12 +02:00
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
2017-08-05 23:16:02 +02:00
|
|
|
|
2018-05-22 20:01:55 +02:00
|
|
|
#=================================================
|
|
|
|
# ACTIVATE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_maintenance_mode_ON
|
|
|
|
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
# STANDARD RESTORATION STEPS
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2021-07-11 16:19:12 +02:00
|
|
|
ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1
|
2017-08-05 23:16:02 +02:00
|
|
|
|
2021-07-11 16:19:12 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2015-05-30 19:37:21 +02:00
|
|
|
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
# RECREATE THE DEDICATED USER
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2021-07-11 16:19:12 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
2016-12-14 16:02:43 +01:00
|
|
|
|
2021-07-11 16:19:12 +02:00
|
|
|
# Create the dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2017-08-05 23:16:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-07-11 16:19:12 +02:00
|
|
|
# RESTORE THE APP MAIN DIR
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2021-07-11 16:19:12 +02:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
2016-12-14 16:02:43 +01:00
|
|
|
|
2021-07-11 16:19:12 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2017-08-05 23:16:02 +02:00
|
|
|
|
2022-03-14 00:52:27 +01:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2016-12-14 16:02:43 +01:00
|
|
|
# Les fichiers appartiennent à root
|
2022-03-14 23:50:58 +01:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2018-11-21 16:19:57 +01:00
|
|
|
# Sauf les dossiers includes, files et upload
|
|
|
|
chown -R $app $final_path/{includes,files,upload}
|
2017-08-05 23:16:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
# RESTORE THE PHP-FPM CONFIGURATION
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
ynh_script_progression --message="Restoring the PHP-FPM configuration..."
|
2017-08-05 23:16:02 +02:00
|
|
|
|
2021-07-11 16:09:09 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
|
2017-08-05 23:16:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORE
|
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
# RESTORE THE MYSQL DATABASE
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
|
2017-08-05 23:16:02 +02:00
|
|
|
|
2022-03-12 15:39:54 +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
|
2017-08-05 23:16:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
# RESTORE VARIOUS FILES
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
2022-03-12 15:39:54 +01:00
|
|
|
ynh_script_progression --message="Restoring various files..."
|
2017-08-05 23:16:02 +02:00
|
|
|
|
2021-07-11 13:22:15 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/cron.d/$app"
|
2016-12-14 16:02:43 +01:00
|
|
|
|
2022-03-12 15:39:54 +01:00
|
|
|
ynh_restore_file --origin_path="/etc/$app/sk.php"
|
|
|
|
chown -R $app "/etc/$app/sk.php"
|
|
|
|
|
2017-08-05 23:16:02 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALISATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX AND PHP-FPM
|
|
|
|
#=================================================
|
2021-07-11 13:22:15 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
|
2015-12-18 14:11:35 +01:00
|
|
|
|
2021-07-11 13:22:15 +02:00
|
|
|
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-05-22 20:01:55 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DEACTIVE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_maintenance_mode_OFF
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SEND A README FOR THE ADMIN
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
message="If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/teampass_ynh"
|
|
|
|
|
2018-07-13 17:37:28 +02:00
|
|
|
ynh_send_readme_to_admin --app_message="$message" --recipients="root"
|
2021-07-11 16:19:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|