From 6a6b3c0a949b51d581fe1a578517df602c005a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 8 Jan 2024 12:11:02 +0100 Subject: [PATCH] fix upgrade synapse domain --- scripts/_common.sh | 19 +++++++++++++++++++ scripts/change_url | 11 +++++++---- scripts/install | 11 +++++++++-- scripts/remove | 6 ------ scripts/restore | 1 - scripts/upgrade | 7 +++++++ 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..95d5663 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,6 +8,25 @@ # PERSONAL HELPERS #================================================= +#================================================= +# UPDATE SYNAPSE ENDPOINT +#================================================= + +_update_synapse_nginx_config() { + # This helper fixes when synapse changes domain, shouldn't happen though... + old_synapse_domain="$synapse_domain" + synapse_domain=$(ynh_app_setting_get --app="$synapse_app" --key=domain) + synapse_port=$(ynh_app_setting_get --app="$synapse_app" --key=synapse_port) + ynh_app_setting_set --app=$app --key=synapse_domain --value="$synapse_domain" + + if [[ "${synapse_domain}" != "${old_synapse_domain}" ]]; then + ynh_backup_if_checksum_is_different --file="/etc/nginx/conf.d/${old_synapse_domain}.d/$app.endpoint.conf" + ynh_delete_file_checksum --file="/etc/nginx/conf.d/${old_synapse_domain}.d/$app.endpoint.conf" + ynh_secure_remove --file="/etc/nginx/conf.d/${old_synapse_domain}.d/$app.endpoint.conf" + fi + + ynh_add_config --template="endpoint.nginx.conf" --destination="/etc/nginx/conf.d/${synapse_domain}.d/$app.endpoint.conf" +} #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/change_url b/scripts/change_url index beaae0c..a693ba5 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,6 +9,13 @@ source _common.sh source /usr/share/yunohost/helpers +#================================================= +# UPDATE SYNAPSE ENDPOINT +#================================================= +ynh_script_progression --message="Updating NGINX web server configuration for Synapse..." --weight=2 + +_update_synapse_nginx_config + #================================================= # MODIFY URL IN NGINX CONF #================================================= @@ -16,10 +23,6 @@ ynh_script_progression --message="Updating NGINX web server configuration..." -- ynh_change_url_nginx_config -synapse_domain=$(ynh_app_setting_get --app=$synapse_app --key=domain) -synapse_port=$(ynh_app_setting_get --app=$synapse_app --key=synapse_port) -ynh_add_config --template="endpoint.nginx.conf" --destination="/etc/nginx/conf.d/${synapse_domain}.d/$app.endpoint.conf" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index ac20a0d..c6cb612 100644 --- a/scripts/install +++ b/scripts/install @@ -9,6 +9,15 @@ source _common.sh source /usr/share/yunohost/helpers +#================================================= +# GET SYNAPSE SETTINGS +#================================================= +ynh_script_progression --message="Getting settings from Synapse..." --weight=2 + +synapse_domain=$(ynh_app_setting_get --app="$synapse_app" --key=domain) +synapse_port=$(ynh_app_setting_get --app="$synapse_app" --key=synapse_port) +ynh_app_setting_set --app=$app --key=synapse_domain --value="$synapse_domain" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -29,8 +38,6 @@ ynh_script_progression --message="Adding system configurations related to $app.. ynh_add_nginx_config # Create NGINX config to access /_synapse/admin endpoint -synapse_domain=$(ynh_app_setting_get --app="$synapse_app" --key=domain) -synapse_port=$(ynh_app_setting_get --app="$synapse_app" --key=synapse_port) ynh_add_config --template="endpoint.nginx.conf" --destination="/etc/nginx/conf.d/${synapse_domain}.d/$app.endpoint.conf" #================================================= diff --git a/scripts/remove b/scripts/remove index 2479a96..1e11c2e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -14,18 +14,12 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 -ynh_exec_warn ls -lah "/etc/nginx/conf.d/${synapse_domain}.d/$app.endpoint.conf" - # Remove the dedicated NGINX config ynh_remove_nginx_config -ynh_exec_warn ls -lah "/etc/nginx/conf.d/${synapse_domain}.d/$app.endpoint.conf" - # Remove NGINX config that enabled /_synapse/admin endpoint ynh_secure_remove --file="/etc/nginx/conf.d/${synapse_domain}.d/$app.endpoint.conf" -ynh_exec_warn ls -lah "/etc/nginx/conf.d/${synapse_domain}.d/$app.endpoint.conf" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index ef97584..45fd866 100644 --- a/scripts/restore +++ b/scripts/restore @@ -19,7 +19,6 @@ ynh_restore_file --origin_path="$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" - #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 39acb5b..21ad0a9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -56,6 +56,13 @@ fi chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" +#================================================= +# UPDATE SYNAPSE ENDPOINT +#================================================= +ynh_script_progression --message="Updating NGINX web server configuration for Synapse..." --weight=2 + +_update_synapse_nginx_config + #================================================= # REAPPLY SYSTEM CONFIGURATIONS #=================================================