Compare commits

..

2 Commits

+8 -7
View File
@@ -7,21 +7,22 @@ if [ -z "${ip_version:-}" ] || ([ "$ip_version" != 4 ] && [ "$ip_version" != 6 ]
fi
if [ $ip_version = 4 ]; then
curl -4 http://icanhazip.com 2> /dev/null
exit 0
dig +short myip.opendns.com @resolver1.opendns.com \
&& exit 0 \
|| exit 1
fi
set -eu
CONN_NAME=${CONN_NAME:-nevis}
conn_device_name="$(nmcli --fields NAME,DEVICE con show | grep ^$CONN_NAME | sed 's/\s\+/ /g' | cut -d' ' -f 2)"
if [ -z "${conn_device_name:-}" ]; then
CONN_DEVICE_NAME="${CONN_DEVICE_NAME:-$(nmcli --fields NAME,DEVICE con show | grep ^$CONN_NAME | sed 's/\s\+/ /g' | cut -d' ' -f 2)}"
if [ -z "${CONN_DEVICE_NAME:-}" ]; then
echo "Could not find the connection device name for connection: \"$CONN_NAME\"" >&2
exit 1
fi
device_line_no="$(ip addr | grep -En ^[0-9]+:\ $conn_device_name | cut -d':' -f 1)"
device_line_no="$(ip addr | grep -En ^[0-9]+:\ $CONN_DEVICE_NAME | cut -d':' -f 1)"
if [ -z "${device_line_no:-}" ]; then
echo "Could not find device: \"$conn_device_name\" in output of ip addr" >&2
echo "Could not find device: \"$CONN_DEVICE_NAME\" in output of ip addr" >&2
exit 1
fi
@@ -44,7 +45,7 @@ else
fi
ip="$(echo "$ip_addr_output_for_device" | grep "scope global" | grep -oE $ip_regex | head -n 1)"
if [ -z "${ip:-}" ]; then
echo "Could not find global IP in output of ip addr under device: $conn_device_name ($CONN_NAME)"
echo "Could not find global IP in output of ip addr under device: $CONN_DEVICE_NAME ($CONN_NAME)"
exit 1
fi