40 lines
938 B
Bash
40 lines
938 B
Bash
#!/usr/bin/env bash
|
|
set -e
|
|
HOST_CONF_PATH="${HOST_CONF_PATH:-/config/hosts}"
|
|
RESOLVE_DOCKERHOST="${RESOLVE_DOCKERHOST:-false}"
|
|
DOCKER_HOSTNAME_VAR="${DOCKER_HOSTNAME_VAR:-LOCAL_WEB_HOST}"
|
|
|
|
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
|
|
then
|
|
TEMPLATE='127.0.0.1 '
|
|
else
|
|
TEMPLATE='$LOCAL_IP '
|
|
fi
|
|
|
|
TEMPLATE="${TEMPLATE}\${${DOCKER_HOSTNAME_VAR}} # Added by hostman"
|
|
|
|
# Allow overriding out for debugging and testing purposs
|
|
if [ -z "${HOST_CONF_OUT+.}" ]
|
|
then
|
|
OUT="${HOST_CONF_PATH}"
|
|
else
|
|
OUT="${HOST_CONF_OUT}"
|
|
fi
|
|
|
|
template_hook() {
|
|
if grep -q '^[:.0-9a-e]\+ [^ ]\+ # Added by hostman$' <<< "${PARTIAL_RESULT}"
|
|
then
|
|
return 0;
|
|
fi
|
|
return 1;
|
|
}
|