make the valid IP checks consistent between IPv4 and IPv6

This commit is contained in:
diginc 2018-01-26 21:32:39 -06:00
parent 94f76397fd
commit a9b41c7099
1 changed files with 4 additions and 5 deletions

View File

@ -15,11 +15,10 @@ validate_env() {
exit 1
fi;
# Debian
nc_error='Name or service not known'
# Required ServerIP is a valid IP
if [[ "$(nc -4 -w1 -z "$ServerIP" 53 2>&1)" != "" ]]; then
# nc won't throw any text based errors when it times out connecting to a valid IP, otherwise it complains about the DNS name being garbage
# if nc doesn't behave as we expect on a valid IP the routing table should be able to look it up and return a 0 retcode
if [[ "$(nc -4 -w1 -z "$ServerIP" 53 2>&1)" != "" ]] || ! ip route get "$ServerIP" > /dev/null ; then
echo "ERROR: ServerIP Environment variable ($ServerIP) doesn't appear to be a valid IPv4 address"
exit 1
fi
@ -31,7 +30,7 @@ validate_env() {
unset ServerIPv6
exit 1
fi
if nc -6 -w 1 -z "$ServerIPv6" 53 2>&1 | grep -q "$nc_error" || ! ip route get "$ServerIPv6" > /dev/null ; then
if [[ "$(nc -6 -w1 -z "$ServerIPv6" 53 2>&1)" != "" ]] || ! ip route get "$ServerIPv6" > /dev/null ; then
echo "ERROR: ServerIPv6 Environment variable ($ServerIPv6) doesn't appear to be a valid IPv6 address"
echo " TIP: If your server is not IPv6 enabled just remove '-e ServerIPv6' from your docker container"
exit 1