2023-01-29 19:52:07 +01:00
|
|
|
#!/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
|
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
|
2023-01-29 19:52:07 +01:00
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
synapse_db_name="matrix_$synapse_instance"
|
|
|
|
bot_synapse_db_user="@$botname:$server_name"
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
2023-01-29 19:52:07 +01:00
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_restore_file --origin_path="$install_dir"
|
2023-01-29 19:52:07 +01:00
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R 750 "$install_dir"
|
|
|
|
chown -R "$app:$app" "$install_dir"
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
2023-01-29 20:25:18 +01:00
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
2023-01-29 19:52:07 +01:00
|
|
|
#=================================================
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
|
2023-01-29 19:52:07 +01:00
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-09-20 01:01:37 +02:00
|
|
|
# REGISTER SYNAPSE APP-SERVICE
|
2023-01-29 19:52:07 +01:00
|
|
|
#=================================================
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_script_progression --message="Registering Synapse app-service" --weight=1
|
2023-01-29 19:52:07 +01:00
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
__ynh_register_matrix_app_service
|
2023-01-29 19:52:07 +01:00
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
chmod 400 "$install_dir/config.yaml"
|
|
|
|
chown "$app:$app" "$install_dir/config.yaml"
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
2023-09-20 01:01:37 +02:00
|
|
|
systemctl enable "$app.service" --quiet
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
2023-09-20 01:01:37 +02:00
|
|
|
mkdir --parents "/var/log/$app"
|
|
|
|
chmod -R 600 "/var/log/$app"
|
|
|
|
chmod 700 "/var/log/$app"
|
|
|
|
chown -R "$app:$app" "/var/log/$app"
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2023-01-29 19:52:07 +01:00
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
yunohost service add $app --description="$app daemon for bridging IRC and Matrix messages." --log="/var/log/$app/$app.log"
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2023-01-29 19:52:07 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2023-09-20 01:01:37 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|