matrix-appservice-irc_ynh/scripts/restore

84 lines
2.9 KiB
Text
Raw Normal View History

2023-01-29 19:52:07 +01:00
#!/bin/bash
#=================================================
# 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
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2024-08-09 17:34:56 +02:00
ynh_script_progression --message="Reinstalling NodeJS..." --weight=1
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
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
#=================================================
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
#=================================================
2024-08-09 17:34:56 +02:00
# RESTORE SYSTEM CONFIGURATIONS
2023-01-29 19:52:07 +01:00
#=================================================
2024-08-09 17:34:56 +02:00
ynh_script_progression --message="Restoring system configurations related to $app..." --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
2024-08-09 17:34:56 +02:00
yunohost service add "$app" --description="$app daemon for bridging IRC and Matrix messages." --log="/var/log/$app/$app.log"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
2023-01-29 19:52:07 +01:00
#=================================================
2024-08-09 17:34:56 +02:00
# RESTORE VARIOUS FILES
2023-01-29 19:52:07 +01:00
#=================================================
2024-08-09 17:34:56 +02:00
ynh_restore_file --origin_path="/var/log/$app/"
2023-09-20 01:01:37 +02:00
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
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-08-09 17:34:56 +02:00
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
2023-01-29 19:52:07 +01:00
2024-08-09 17:34:56 +02:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
2023-01-29 19:52:07 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2023-09-20 01:01:37 +02:00
ynh_script_progression --message="Restoration completed for $app" --last