From 18caa2025b7f8b51af72b8e804f1922afca0d2ca Mon Sep 17 00:00:00 2001 From: Kevin Baensch Date: Wed, 18 Jan 2023 15:02:13 +0100 Subject: [PATCH] Allow multiple hostnames for a container. --- templates/caddy.sh | 7 ++++++- templates/hosts.sh | 6 +----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/templates/caddy.sh b/templates/caddy.sh index 7333694..665c9f4 100644 --- a/templates/caddy.sh +++ b/templates/caddy.sh @@ -11,10 +11,15 @@ OUT='/config/Caddyfile' label_hook() { LOCAL_WEB_PORT="${LOCAL_WEB_PORT:-80}" + # Check if host contains spaces + if [[ "${LOCAL_WEB_HOST}" =~ \ ]] + then + LOCAL_WEB_HOST="$(sed 's/ /, /g' <<< ${LOCAL_WEB_HOST})" + fi } template_hook() { - if grep -q '^[^ ]\+ {\\n\\treverse_proxy \(?::\|[.0-9a-e]\)\+\:[0-9]\+\\n}$' <<< "${PARTIAL_RESULT}" + if [[ "${PARTIAL_RESULT}" =~ ^([^\{,\ ]+(,\ )?)+\ \{$'\\n\\t'reverse_proxy\ (::|[.0-9a-e]+)+\:[0-9]+$'\\n'\}$ ]] then return 0; fi diff --git a/templates/hosts.sh b/templates/hosts.sh index 810440c..7c8e2df 100644 --- a/templates/hosts.sh +++ b/templates/hosts.sh @@ -8,10 +8,6 @@ if [ -f "${HOST_CONF_PATH}" ] then WRAP_START=$(grep -ve "# Added by hostman$" "${HOST_CONF_PATH}") WRAP_START+="\n" -else - printf "[WARN]: No such file or directory: %s\n" "${HOST_CONF_PATH}" - printf "Creating %s" "${HOST_CONF_PATH}" - touch "${HOST_CONF_PATH}" fi if ! $RESOLVE_DOCKERHOST @@ -32,7 +28,7 @@ else fi template_hook() { - if grep -q '^[:.0-9a-e]\+ [^ ]\+ # Added by hostman$' <<< "${PARTIAL_RESULT}" + if [[ "${PARTIAL_RESULT}" =~ ^(::|[.0-9a-e]+)+\ ([^ ]+\ )+\#\ Added\ by\ hostman$ ]] then return 0; fi