2022-12-13 17:04:48 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
2022-12-16 14:17:11 +01:00
|
|
|
DOCKER_CADDY_NAME="${DOCKER_CADDY_NAME:-proxy}"
|
|
|
|
DOCKER_CADDY_PORT="${DOCKER_CADDY_PORT:-2020}"
|
2022-12-13 17:04:48 +01:00
|
|
|
|
2022-12-17 10:30:41 +01:00
|
|
|
WRAP_START='{\n\tadmin :2020\n}\n'
|
2022-12-16 14:17:11 +01:00
|
|
|
WRAP_END='\n'
|
2022-12-17 10:30:41 +01:00
|
|
|
TEMPLATE='${LOCAL_WEB_HOST} {\n\treverse_proxy ${LOCAL_IP}:$LOCAL_WEB_PORT\n}'
|
2022-12-16 14:17:11 +01:00
|
|
|
SEPARATOR='\n'
|
|
|
|
OUT='/config/Caddyfile'
|
2022-12-13 17:04:48 +01:00
|
|
|
|
|
|
|
label_hook() {
|
|
|
|
LOCAL_WEB_PORT="${LOCAL_WEB_PORT:-80}"
|
|
|
|
}
|
|
|
|
|
|
|
|
template_hook() {
|
2022-12-17 10:30:41 +01:00
|
|
|
if grep -q '^[^ ]\+ {\\n\\treverse_proxy \(?::\|[.0-9a-e]\)\+\:[0-9]\+\\n}$' <<< "${PARTIAL_RESULT}"
|
2022-12-13 17:04:48 +01:00
|
|
|
then
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
return 1;
|
|
|
|
}
|
2022-12-16 14:17:11 +01:00
|
|
|
|
2022-12-17 10:30:41 +01:00
|
|
|
finally_hook() {
|
|
|
|
if curl --silent "${DOCKER_CADDY_NAME}:${DOCKER_CADDY_PORT}/load" -H "Content-Type: text/caddyfile" --data-binary "@${OUT}"
|
|
|
|
then
|
|
|
|
printf '%s | Updated Caddy Config\n' "$(get_date)"
|
|
|
|
else
|
|
|
|
printf '%s | Failed to update Caddy Config\n' "$(get_date)"
|
|
|
|
fi
|
|
|
|
}
|