#!/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 ../settings/scripts/experimental_helper.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading settings..." #================================================= # RECREATE THE DEDICATED USER #================================================= ynh_script_progression --message="Recreating the dedicated system user..." --weight=3 # Create the dedicated user (if not existing) yunohost user create $YNH_APP_ID -F "Synapse Application" -d $domain -p "$synapse_user_app_pwd" adduser $YNH_APP_ID ssl-cert adduser turnserver ssl-cert #================================================= # FIX DB CONFIG #================================================= ynh_script_progression --message="Fixing database type..." --weight=1 ynh_psql_execute_as_root \ --sql="update pg_database set datcollate='C', datctype='C' where datname='$db_name';" #================================================= # RESTORE ALL CONFIG AND DATA #================================================= ynh_script_progression --message="Restoring directory and configuration..." --weight=10 ynh_restore mkdir -p /etc/matrix-$app/app-service # Check that the good python version is installed # If not upgrade the source ynh_script_progression --message="Check for source up to date..." --weight=5 install_sources #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= ynh_script_progression --message="Reload Fail2Ban..." --weight=6 ynh_systemd_action --action=restart --service_name=fail2ban #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=13 ynh_psql_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$synapse_db_name" #================================================= # RESTORE SYSTEMD #================================================= ynh_script_progression --message="Enable systemd services" --weight=2 # systemctl daemon-reload systemctl enable matrix-$app.service --quiet systemctl enable coturn-$app.service --quiet #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add matrix-$app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls yunohost service add coturn-$app --needs_exposed_ports $port_turnserver_tls #================================================= # CREATE A DH FILE #================================================= ynh_script_progression --message="Creating a dh file..." --weight=40 # WARNING : theses command are used in INSTALL, UPGRADE, RESTORE # For any update do it in all files # Make dh cert for synapse if it doesn't exist if [ ! -e /etc/ssl/private/dh2048.pem ] then ynh_exec_warn_less openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048 -dsaparam chown root:ssl-cert /etc/ssl/private/dh2048.pem chmod 640 /etc/ssl/private/dh2048.pem fi #================================================= # RECONFIGURE THE TURNSERVER #================================================= ynh_script_progression --message="Reconfiguring Coturn..." --weight=23 configure_coturn #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Configuring log rotation..." ynh_use_logrotate --logfile /var/log/matrix-$app #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= ynh_script_progression --message="Protecting directories..." --weight=3 set_permissions #================================================= # RELOAD NGINX, SYNAPSE AND COTURN #================================================= ynh_script_progression --message="Restarting Synapse services..." --weight=7 ynh_systemd_action --service_name=coturn-$app.service --action=restart ynh_systemd_action --service_name=matrix-$app --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Restoration completed for $app" --last