1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mautrix_discord_ynh.git synced 2024-09-03 19:36:35 +02:00
mautrix_discord_ynh/scripts/restore

83 lines
3.2 KiB
Text
Raw Normal View History

2023-12-30 19:24:43 +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
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
synapse_db_name="matrix_$synapse_instance"
bot_synapse_db_user="@$botname:$server_name"
async_media=$(ynh_app_setting_get --app=$app --key=async_media)
2023-12-30 19:24:43 +01:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$install_dir"
chown -R $app:www-data "$install_dir"
chmod 750 "$install_dir/$APP_BIN"
2023-12-30 19:24:43 +01:00
#=================================================
# RESTORE THE POSTGRESQL DATABASE
2023-12-30 19:24:43 +01:00
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8
2023-12-30 19:24:43 +01:00
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
2023-12-30 19:24:43 +01:00
#=================================================
# REGISTER SYNAPSE APP-SERVICE
2023-12-30 19:24:43 +01:00
#=================================================
ynh_script_progression --message="Registering Synapse app-service" --weight=1
2023-12-30 19:24:43 +01:00
$install_dir/$APP_BIN -g -c $install_dir/config.yaml -r /etc/matrix-$synapse_instance/app-service/$app.yaml
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration"
chmod 400 "$install_dir/config.yaml"
chown $app:$app "$install_dir/config.yaml"
2023-12-30 19:24:43 +01:00
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=3
2023-12-30 19:24:43 +01:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
yunohost service add $app --description="Matrix Discord pupetting bridge for YunoHost" --log="/var/log/$app/$app.log"
2023-12-30 19:24:43 +01:00
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading $app's service..." --weight=1
2023-12-30 19:24:43 +01:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
# Wait until the synapse user is created
sleep 30
# (Note that, by default, non-admins might not have your homeserver's permission to create communities.)
if [ "$bot_synapse_adm" = true ]
then
ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";"
fi
ynh_systemd_action --service_name=$app --action="restart"
2023-12-30 19:24:43 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last