#!/bin/bash #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 "Loading settings..." #================================================= # RECREATE THE DEDICATED USER #================================================= ynh_script_progression 'Configuring system groups' # Create the dedicated user (if not existing) adduser "$app" ssl-cert adduser turnserver ssl-cert #================================================= # FIX DB CONFIG #================================================= ynh_script_progression "Fixing database type..." ynh_psql_db_shell \ <<< "update pg_database set datcollate='C', datctype='C' where datname='$db_name';" #================================================= # RESTORE ALL CONFIG AND DATA #================================================= ynh_script_progression "Restoring directory and configuration..." ynh_restore_everything mkdir -p /etc/matrix-"$app"/app-service # Check that the good python version is installed # If not upgrade the source ynh_script_progression "Check for source up to date..." install_sources #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= ynh_script_progression "Reload Fail2Ban..." ynh_systemctl --action=restart --service=fail2ban #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= ynh_script_progression "Restoring the PostgreSQL database..." ynh_psql_db_shell < "${YNH_CWD}/dump.sql" #================================================= # RESTORE SYSTEMD #================================================= ynh_script_progression "Enable systemd services" # systemctl daemon-reload systemctl enable "$app".service --quiet systemctl enable "$app"-coturn.service --quiet #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add "$app" --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls --description 'Main matrix server service.' yunohost service add "$app-coturn" --needs_exposed_ports "$port_turnserver_tls" --description 'Turn server for matrix server. Used for audio and video call.' #================================================= # CREATE A DH FILE #================================================= ynh_script_progression "Creating a dh file..." # 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_hide_warnings openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -dsaparam 2048 chown root:ssl-cert /etc/ssl/private/dh2048.pem chmod 640 /etc/ssl/private/dh2048.pem fi #================================================= # RECONFIGURE THE TURNSERVER #================================================= ynh_script_progression "Reconfiguring Coturn..." configure_coturn #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression "Configuring log rotation..." ynh_config_add_logrotate /var/log/matrix-"$app" #================================================= # SECURE FILES AND DIRECTORIES #================================================= ynh_script_progression "Protecting directories..." set_permissions data #================================================= # RELOAD NGINX, SYNAPSE AND COTURN #================================================= ynh_script_progression "Restarting Synapse services..." ynh_systemctl --service="$app"-coturn.service --action=restart ynh_systemctl --service="$app".service --action=restart --wait_until="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 #================================================= # RELOAD NGINX #================================================= ynh_script_progression "Reloading NGINX web server..." ynh_systemctl --service=php"$php_version"-fpm --action=reload ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Restoration completed for $app"