diff --git a/scripts/_common.sh b/scripts/_common.sh index bb04a03..3dfc879 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,5 +1,18 @@ #!/bin/bash +#================================================= +# COMMON HELPERS -- SHOULD BE ADDED TO YUNOHOST +#================================================= + +# 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 ]] +} + # ============= FUTURE YUNOHOST HELPER ============= # Delete a file checksum from the app settings # @@ -10,4 +23,4 @@ ynh_delete_file_checksum () { local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' ynh_app_setting_delete $app $checksum_setting_name -} \ No newline at end of file +} diff --git a/scripts/install b/scripts/install index 4cf7704..a34abf5 100644 --- a/scripts/install +++ b/scripts/install @@ -70,6 +70,20 @@ ynh_setup_source "$final_path" # NGINX CONFIGURATION #================================================= +# Do not serve .well-known if it's already served on the domain +if https://github.com/YunoHost-Apps/nextcloud_ynh/blob/962cc61ec8ffb045d89dd460cf8b55778d862ffc/scripts/install "https://${domain}/.well-known/caldav" ; then + sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \ + "../conf/nginx.conf" +fi + +# Taken from https://github.com/YunoHost-Apps/nextcloud_ynh/blob/962cc61ec8ffb045d89dd460cf8b55778d862ffc/scripts/install +# Commented for now +# +# Handle root path, avoid double slash. +# Temporary fix, in waiting for an upgrade of the helper. (#361) +#path_url_slash_less=${path_url%/} +#ynh_replace_string "__PATH__/" "$path_url_slash_less/" "../conf/nginx.conf" + # Create a dedicated nginx config ynh_add_nginx_config diff --git a/scripts/upgrade b/scripts/upgrade index d267063..71d5a9f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -64,6 +64,20 @@ ynh_setup_source "$final_path" # NGINX CONFIGURATION #================================================= +# Delete current nginx configuration to be able to check if .well-known is already served. +ynh_remove_nginx_config +ynh_app_setting_delete $app "checksum__etc_nginx_conf.d_$domain.d_$app.conf" || true +# 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" +fi + +# Handle root path, avoid double slash. +# Temporary fix, in waiting for an upgrade of the helper. (#361) +#path_url_slash_less=${path_url%/} +#ynh_replace_string "__PATH__/" "$path_url_slash_less/" "../conf/nginx.conf" + # Create a dedicated nginx config ynh_add_nginx_config