From d0b389a4e6805d2dc0ab13350656109e6cb163f9 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Mon, 29 Jun 2026 11:19:01 +0100 Subject: [PATCH] CONN_DEVICE_NAME is configurable by env var --- get_ip_addr.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/get_ip_addr.sh b/get_ip_addr.sh index f7f8ea2..ec8b0c6 100755 --- a/get_ip_addr.sh +++ b/get_ip_addr.sh @@ -14,15 +14,15 @@ 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 @@ -45,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