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
|
|
|
|
|
2024-01-14 22:09:01 +01:00
|
|
|
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
|
|
|
|
|
2024-07-03 20:22:54 +02:00
|
|
|
synapse_db_name="$(get_synapse_db_name $synapse_instance)"
|
2024-01-14 22:09:01 +01:00
|
|
|
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"
|
2024-01-14 22:09:01 +01:00
|
|
|
chmod 750 "$install_dir/$APP_BIN"
|
2024-02-10 09:15:49 +01:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R 750 "$install_dir"
|
|
|
|
chown -R $app:$app "$install_dir"
|
2023-12-30 19:24:43 +01:00
|
|
|
|
|
|
|
#=================================================
|
2024-01-14 22:09:01 +01:00
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
2023-12-30 19:24:43 +01:00
|
|
|
#=================================================
|
2024-01-14 22:09:01 +01:00
|
|
|
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8
|
2023-12-30 19:24:43 +01:00
|
|
|
|
2024-01-14 22:09:01 +01:00
|
|
|
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
|
2023-12-30 19:24:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
2024-01-14 22:09:01 +01:00
|
|
|
# REGISTER SYNAPSE APP-SERVICE
|
2023-12-30 19:24:43 +01:00
|
|
|
#=================================================
|
2024-01-14 22:09:01 +01:00
|
|
|
ynh_script_progression --message="Registering Synapse app-service" --weight=1
|
2023-12-30 19:24:43 +01:00
|
|
|
|
2024-01-14 22:09:01 +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
|
|
|
|
#=================================================
|
|
|
|
|
2024-01-14 22:09:01 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
2024-02-10 09:15:49 +01:00
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
mkdir --parents "/var/log/$app"
|
|
|
|
chmod -R 600 "/var/log/$app"
|
|
|
|
chmod 700 "/var/log/$app"
|
|
|
|
chown -R $app:$app /var/log/$app
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
|
|
|
|
#=================================================
|
2024-01-14 22:09:01 +01:00
|
|
|
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"
|
2024-01-14 22:09:01 +01:00
|
|
|
# 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
|