From 5556fb6549d8602ba0ccd8455f2c081065f6692d Mon Sep 17 00:00:00 2001 From: Kayou Date: Thu, 1 Aug 2024 11:44:40 +0200 Subject: [PATCH 1/5] wait until nginx has actually remove the nextcloud conf during upgrade before checking the url_handled --- scripts/upgrade | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index e36d62e..aa391c0 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -357,6 +357,15 @@ ynh_app_setting_delete --app=$app --key="checksum__etc_nginx_conf.d_$domain.d_$a # Wait untils NGINX has fully reloaded ynh_systemd_action --service_name=nginx --action=reload --line_match="Reloaded" --log_path="systemd" +# Nginx may take some time to support the new configuration, wait for the nextcloud configuration file to disappear from nginx before checking the CalDAV/CardDAV URL. +timeout=30 +for i in $(seq 1 $timeout); do + if ! ynh_exec_warn_less nginx -T | grep --quiet "# configuration file /etc/nginx/conf.d/$domain.d/$app.conf:"; then + break + fi + sleep 1 +done + # Check if .well-known is available for this domain if is_url_handled --domain="$domain" --path="/.well-known/caldav" || is_url_handled --domain="$domain" --path="/.well-known/carddav" then From d7f9b2c9fd77fac51d1d7dad0f6d0ff6572d2e71 Mon Sep 17 00:00:00 2001 From: Kayou Date: Thu, 1 Aug 2024 11:53:16 +0200 Subject: [PATCH 2/5] create a function for that --- scripts/_common.sh | 13 +++++++++++++ scripts/upgrade | 9 +-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 65cce78..f060a27 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,6 +8,19 @@ # EXPERIMENTAL HELPERS #================================================= +wait_nginx_reload() { + # Nginx may take some time to support the new configuration, + # wait for the nextcloud configuration file to disappear from nginx before checking the CalDAV/CardDAV URL. + timeout=30 + for i in $(seq 1 $timeout); do + if ! ynh_exec_warn_less nginx -T | grep --quiet "# configuration file /etc/nginx/conf.d/$domain.d/$app.conf:"; then + break + fi + sleep 1 +done +} + + # Check if an URL is already handled # usage: is_url_handled --domain=DOMAIN --path=PATH_URI is_url_handled() { diff --git a/scripts/upgrade b/scripts/upgrade index aa391c0..ad0e4c6 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -357,14 +357,7 @@ ynh_app_setting_delete --app=$app --key="checksum__etc_nginx_conf.d_$domain.d_$a # Wait untils NGINX has fully reloaded ynh_systemd_action --service_name=nginx --action=reload --line_match="Reloaded" --log_path="systemd" -# Nginx may take some time to support the new configuration, wait for the nextcloud configuration file to disappear from nginx before checking the CalDAV/CardDAV URL. -timeout=30 -for i in $(seq 1 $timeout); do - if ! ynh_exec_warn_less nginx -T | grep --quiet "# configuration file /etc/nginx/conf.d/$domain.d/$app.conf:"; then - break - fi - sleep 1 -done +wait_nginx_reload # Check if .well-known is available for this domain if is_url_handled --domain="$domain" --path="/.well-known/caldav" || is_url_handled --domain="$domain" --path="/.well-known/carddav" From 49ec72b6ef87e7a803ecf21793b275249ccd77e5 Mon Sep 17 00:00:00 2001 From: Kayou Date: Thu, 1 Aug 2024 11:53:29 +0200 Subject: [PATCH 3/5] fix change-url dav detection --- scripts/change_url | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index aac12f0..f43ed11 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -14,6 +14,16 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2 +# Check if .well-known is available for this domain +if is_url_handled --domain="$new_domain" --path="/.well-known/caldav" || is_url_handled --domain="$new_domain" --path="/.well-known/carddav" +then + ynh_print_warn --message="Another app already uses the domain $new_domain to serve a CalDAV/CardDAV feature. You may encounter issues when dealing with your calendar or address book." + + # Remove lines about .well-known/carddav and caldav with sed. + sed --in-place --regexp-extended '/location = \/\.well\-known\/(caldav|carddav)/d' "/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" +fi + ynh_change_url_nginx_config #================================================= @@ -37,16 +47,6 @@ then # Reload php fpm, necessary for force nextcloud to re-read config.php, cf opcache.revalidate_freq ynh_systemd_action --service_name=php${phpversion}-fpm --action=reload - - # Check if .well-known is available for this domain - if is_url_handled --domain="$new_domain" --path="/.well-known/caldav" || is_url_handled --domain="$new_domain" --path="/.well-known/carddav" - then - ynh_print_warn --message="Another app already uses the domain $new_domain to serve a CalDAV/CardDAV feature. You may encounter issues when dealing with your calendar or address book." - - # Remove lines about .well-known/carddav and caldav with sed. - sed --in-place --regexp-extended '/location = \/\.well\-known\/(caldav|carddav)/d' "/etc/nginx/conf.d/$new_domain.d/$app.conf" - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - fi fi #================================================= From 73a3498b93011ea6dd897fa409944740a8f466fa Mon Sep 17 00:00:00 2001 From: Kayou Date: Thu, 1 Aug 2024 11:54:17 +0200 Subject: [PATCH 4/5] only if domain has changed... --- scripts/change_url | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index f43ed11..8cadcea 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -14,14 +14,17 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2 -# Check if .well-known is available for this domain -if is_url_handled --domain="$new_domain" --path="/.well-known/caldav" || is_url_handled --domain="$new_domain" --path="/.well-known/carddav" +if [ $change_domain -eq 1 ] then - ynh_print_warn --message="Another app already uses the domain $new_domain to serve a CalDAV/CardDAV feature. You may encounter issues when dealing with your calendar or address book." + # Check if .well-known is available for this domain + if is_url_handled --domain="$new_domain" --path="/.well-known/caldav" || is_url_handled --domain="$new_domain" --path="/.well-known/carddav" + then + ynh_print_warn --message="Another app already uses the domain $new_domain to serve a CalDAV/CardDAV feature. You may encounter issues when dealing with your calendar or address book." - # Remove lines about .well-known/carddav and caldav with sed. - sed --in-place --regexp-extended '/location = \/\.well\-known\/(caldav|carddav)/d' "/etc/nginx/conf.d/$domain.d/$app.conf" - ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" + # Remove lines about .well-known/carddav and caldav with sed. + sed --in-place --regexp-extended '/location = \/\.well\-known\/(caldav|carddav)/d' "/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" + fi fi ynh_change_url_nginx_config From fa5da4fe666feee04e0988590e98a2944dc0188d Mon Sep 17 00:00:00 2001 From: Kayou Date: Thu, 1 Aug 2024 14:07:39 +0200 Subject: [PATCH 5/5] Update scripts/_common.sh --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index f060a27..653a0b0 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,7 +17,7 @@ wait_nginx_reload() { break fi sleep 1 -done + done }