From cf253b170ac0493afb6eb460f81f34fd8e9c5cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Mon, 18 Jul 2016 21:46:28 +0200 Subject: [PATCH] [fix] Improve how .well-known path is checked --- scripts/_common.sh | 9 +++++++++ scripts/install | 8 +++----- scripts/upgrade | 8 +++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 0628249..bc841ed 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -71,3 +71,12 @@ exec_occ() { (cd "$WORKDIR" && exec_as "$AS_USER" \ php occ --no-interaction --no-ansi "$@") } + +# Check if an URL is already handled +# usage: is_url_handled URL +is_url_handled() { + local OUTPUT=($(curl -k -s -o /dev/null \ + -w 'x%{redirect_url} %{http_code}' "$1")) + # it's handled if it does not redirect to the SSO nor return 404 + [[ ! ${OUTPUT[0]} =~ \/yunohost\/sso\/ && ${OUTPUT[1]} != 404 ]] +} diff --git a/scripts/install b/scripts/install index 6e18111..48c4b48 100755 --- a/scripts/install +++ b/scripts/install @@ -72,12 +72,10 @@ sed -i "s@#APP#@${app}@g" ../conf/nginx.conf sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nginx.conf -# check if .well-known is already served on the domain -if [[ $(curl -s -o /dev/null -w '%{http_code}' \ - "https://${domain}/.well-known/caldav") =~ ^[23] ]] ; then - # ... and delete it from nginx configuration +# do not serve .well-known if it's already served on the domain +if is_url_handled "https://${domain}/.well-known/caldav" ; then sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \ - ../conf/nginx.conf + ../conf/nginx.conf fi sudo cp ../conf/nginx.conf "$nginx_conf" diff --git a/scripts/upgrade b/scripts/upgrade index 6b84e5a..6896935 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -49,12 +49,10 @@ sed -i "s@#APP#@${app}@g" ../conf/nginx.conf sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nginx.conf -# check if .well-known is already served on the domain -if [[ $(curl -s -o /dev/null -w '%{http_code}' \ - "https://${domain}/.well-known/caldav") =~ ^[23] ]] ; then - # ... and delete it from nginx configuration +# do not serve .well-known if it's already served on the domain +if is_url_handled "https://${domain}/.well-known/caldav" ; then sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \ - ../conf/nginx.conf + ../conf/nginx.conf fi sudo cp ../conf/nginx.conf "$nginx_conf"