2016-03-18 18:38:54 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
2022-01-15 10:05:56 +01:00
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2022-01-15 10:05:56 +01:00
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2020-11-17 23:55:57 +01:00
|
|
|
source ../settings/scripts/_common.sh
|
2018-08-14 22:18:22 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2022-01-15 10:05:56 +01: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
|
2018-08-14 22:18:22 +02:00
|
|
|
ynh_abort_if_errors
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2022-01-15 10:05:56 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2019-06-07 23:09:30 +02:00
|
|
|
|
2022-01-15 10:05:56 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2022-01-15 10:05:56 +01: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)
|
|
|
|
db_user=$db_name
|
|
|
|
|
|
|
|
#=================================================
|
2018-08-14 22:18:22 +02:00
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
2022-01-15 10:05:56 +01:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
|
|
|
|
|
|
|
test ! -d $final_path || ynh_die --message="There is already a directory: $final_path "
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
#=================================================
|
2022-01-15 10:05:56 +01:00
|
|
|
# REINSTALL DEPENDENCIES
|
2018-08-14 22:18:22 +02:00
|
|
|
#=================================================
|
2022-01-15 10:05:56 +01:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
# Define and install dependencies
|
2022-01-15 10:05:56 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
|
|
|
|
# Restore all config and data
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Restoring files..." --weight=10
|
2022-01-15 10:05:56 +01:00
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
ynh_restore
|
|
|
|
|
2022-01-15 10:05:56 +01:00
|
|
|
#=================================================
|
2018-08-14 22:18:22 +02:00
|
|
|
# RESTORE THE MYSQL DATABASE
|
2022-01-15 10:05:56 +01:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
|
|
|
|
|
|
|
|
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
|
2018-08-14 22:18:22 +02:00
|
|
|
|
|
|
|
# Enable stunnel at startup
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_replace_string --match_string "ENABLED=0" --replace_string "ENABLED=1" --target_file /etc/default/stunnel4
|
2018-08-14 22:18:22 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
2022-01-15 10:05:56 +01:00
|
|
|
#=================================================
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Protecting directory..."
|
2022-01-15 10:05:56 +01:00
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
set_permission
|
|
|
|
|
2022-01-15 10:05:56 +01:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app" --nonappend
|
2018-08-14 22:18:22 +02:00
|
|
|
|
2022-01-15 10:05:56 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
|
|
|
|
yunohost service add $app --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name=stunnel4 --action="restart" --log_path="systemd"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX AND PHP-FPM
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2020-05-24 00:32:03 +02:00
|
|
|
|
2019-06-07 23:09:30 +02:00
|
|
|
|
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|