2019-09-20 12:55:12 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2019-09-20 12:55:12 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_clean_check_starting
|
2019-09-20 12:55:12 +02:00
|
|
|
}
|
2021-08-21 17:30:03 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
2019-09-20 12:55:12 +02:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
2021-08-21 17:30:03 +02:00
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
db_name_app=$(ynh_app_setting_get --app=$app --key=db_name_app)
|
|
|
|
db_user_app=$db_name_app
|
|
|
|
db_name_web=$(ynh_app_setting_get --app=$app --key=db_name_web)
|
|
|
|
db_user_web=$db_name_web
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
test ! -d /usr/share/mailman3-web \
|
|
|
|
|| ynh_die --message="There is already an installation present at /usr/share/mailman3-web?"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
# Define and install dependencies
|
2021-08-25 19:08:27 +02:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Restoring the PostgreSQL database..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_psql_test_if_first_run
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
db_pwd_app=$(ynh_app_setting_get --app=$app --key=db_pwd_app)
|
|
|
|
ynh_psql_setup_db --db_user=$db_user_app --db_name=$db_name_app --db_pwd=$db_pwd_app
|
|
|
|
ynh_psql_execute_file_as_root --file="./db_app.sql" --database=$db_name_app
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
db_pwd_web=$(ynh_app_setting_get --app=$app --key=db_pwd_web)
|
|
|
|
ynh_psql_setup_db --db_user=$db_user_web --db_name=$db_name_web --db_pwd=$db_pwd_web
|
|
|
|
ynh_psql_execute_file_as_root --file="./db_web.sql" --database=$db_name_web
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
# RESTORE VARIOUS FILES
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Restoring various files..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-25 03:39:10 +02:00
|
|
|
ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/98-postfix_mailman3"
|
|
|
|
yunohost tools regen-conf postfix
|
|
|
|
ynh_systemd_action --service_name=postfix --action="restart"
|
|
|
|
|
|
|
|
ynh_secure_remove --file="/etc/$app/mailman.cfg"
|
|
|
|
ynh_restore_file --origin_path="/etc/$app/mailman.cfg"
|
|
|
|
|
|
|
|
ynh_secure_remove --file="/etc/$app/mailman-hyperkitty.cfg"
|
|
|
|
ynh_restore_file --origin_path="/etc/$app/mailman-hyperkitty.cfg"
|
|
|
|
|
|
|
|
ynh_secure_remove --file="/etc/$app/mailman-web.py"
|
|
|
|
ynh_restore_file --origin_path="/etc/$app/mailman-web.py"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..."
|
|
|
|
|
|
|
|
systemctl enable $app.service --quiet
|
|
|
|
systemctl enable "$app-web".service --quiet
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-25 03:39:10 +02:00
|
|
|
yunohost service add $app --description="Mailman3 daemon" --log="/var/log/$app/mailman.log"
|
|
|
|
yunohost service add "$app-web" --description="Mailman3 web daemon" --log="/var/log/$app/web/mailman-web.log"
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
# START SYSTEMD SERVICE
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action=restart
|
|
|
|
ynh_systemd_action --service_name="$app-web" --action=restart
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2021-08-25 03:39:10 +02:00
|
|
|
# RELOAD NGINX
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app"
|