mirror of
https://github.com/YunoHost-Apps/baikal_ynh.git
synced 2024-09-03 18:16:11 +02:00
add new helper 'is_url_handled_rewrited' + use it
This commit is contained in:
parent
1057d7150c
commit
70646d5675
3 changed files with 55 additions and 33 deletions
|
@ -13,16 +13,25 @@ is_url_handled() {
|
|||
[[ ! ${output[0]} =~ \/yunohost\/sso\/ && ${output[1]} != 404 ]]
|
||||
}
|
||||
|
||||
is_url_handled_custom() {
|
||||
local output=($(curl -k -s -o /dev/null \
|
||||
-w 'x%{redirect_url} %{http_code}' "$1"))
|
||||
echo "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤"
|
||||
echo "contenu variable 'output' : $output"
|
||||
echo "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤"
|
||||
# It's handled if it does not redirect to the SSO nor return 404
|
||||
[[ ! ${output[0]} =~ \/yunohost\/sso\/ && ${output[1]} != 404 ]]
|
||||
#[[ ! ${output[0]} =~ \/yunohost\/sso\/ ]] && [[ ${output[1]} != 404 ]]
|
||||
#[[ ! ${output[0]} =~ \/yunohost\/sso\/ ]]
|
||||
is_url_handled_rewrited() {
|
||||
local url="$1"
|
||||
# Try to get the url with curl, and keep the http code and an eventual redirection url.
|
||||
local curl_output="$(curl --insecure --silent --output /dev/null \
|
||||
--write-out '%{http_code};%{redirect_url}' "$url")"
|
||||
|
||||
# Cut the output and keep only the first part to keep the http code
|
||||
local http_code="${curl_output%%;*}"
|
||||
# Do the same thing but keep the second part, the redirection url
|
||||
local redirection="${curl_output#*;}"
|
||||
|
||||
# Return 1 if the url isn't handled.
|
||||
# Return 1 if the url has returned 404
|
||||
if [ "$http_code" = "404" ]; then
|
||||
return 1
|
||||
# Return 1 if the url is redirected to the SSO
|
||||
elif [[ $redirection =~ "/yunohost/sso" ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
is_url_handled_rewrited() {
|
||||
|
|
|
@ -30,6 +30,21 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
|
||||
# Stop installation if another app serves "https://${domain}/.well-known/caldav"
|
||||
## Waiting for Yunohost to handles this kind of conflict
|
||||
## See https://github.com/YunoHost-Apps/baikal_ynh/issues/17
|
||||
error_text="Baikal cannot be installed because of a conflit with another application, Nextcloud usually. This app handles the location where you want to install Baikal (https://${domain}/.well-known/caldav). You can either install Baikal on another domain, subdomain or move Nextcloud to another location"
|
||||
|
||||
if is_url_handled_rewrited "https://${domain}/.well-known/caldav"; then
|
||||
ynh_die "$error_text"
|
||||
fi
|
||||
|
||||
# Same test for path "/.well-known/carddav"
|
||||
if is_url_handled_rewrited "https://${domain}/.well-known/carddav"; then
|
||||
ynh_die "$error_text"
|
||||
fi
|
||||
|
||||
|
||||
# Normalize the url path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
|
||||
|
@ -70,22 +85,6 @@ ynh_setup_source "$final_path"
|
|||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Exits if another app serves "https://${domain}/.well-known/caldav" and display an error message for user
|
||||
# Waiting for Yunohost to handles this kind of conflict https://github.com/YunoHost-Apps/baikal_ynh/issues/17
|
||||
echo "je suis devant le if"
|
||||
if is_url_handled_custom "https://${domain}/.well-known/caldav" ; then
|
||||
echo "je passe dans le if"
|
||||
ynh_die "Baikal cannot be installed because of a conflit with another application, Nextcloud usually. This app handles the location where you want to install Baikal (https://${domain}/.well-known/caldav). You can either install Baikal on another domain, subdomain or move Nextcloud to another location"
|
||||
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
|
||||
|
||||
|
|
|
@ -64,19 +64,33 @@ ynh_setup_source "$final_path"
|
|||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
# 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"
|
||||
#if is_url_handled_rewrited "https://${domain}/.well-known/caldav" ; then
|
||||
# sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
|
||||
# "../conf/nginx.conf"
|
||||
#fi
|
||||
|
||||
# Stop installation if another app serves "https://${domain}/.well-known/caldav"
|
||||
## Waiting for Yunohost to handles this kind of conflict
|
||||
## See https://github.com/YunoHost-Apps/baikal_ynh/issues/17
|
||||
error_text="Baikal cannot be installed because of a conflit with another application, Nextcloud usually. This app handles the location where you want to install Baikal (https://${domain}/.well-known/caldav). You can either install Baikal on another domain, subdomain or move Nextcloud to another location"
|
||||
|
||||
if is_url_handled_rewrited "https://${domain}/.well-known/caldav"; then
|
||||
ynh_die "$error_text"
|
||||
fi
|
||||
|
||||
# Same test for path "/.well-known/carddav"
|
||||
if is_url_handled_rewrited "https://${domain}/.well-known/carddav"; then
|
||||
ynh_die "$error_text"
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue