mirror of
https://github.com/YunoHost-Apps/mailman3_ynh.git
synced 2024-09-03 19:36:17 +02:00
135 lines
5 KiB
Bash
Executable file
135 lines
5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
source ../settings/scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
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
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
ynh_script_progression --message="Validating restoration parameters..."
|
|
|
|
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
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORATION
|
|
#=================================================
|
|
# REINSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Reinstalling dependencies..."
|
|
|
|
# Define and install dependencies
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# RESTORE THE POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the PostgreSQL database..."
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
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
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# RESTORE VARIOUS FILES
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring various files..."
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
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"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
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
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoration completed for $app"
|