diff options
| author | Joe Carstairs <me@joeac.net> | 2026-06-29 11:19:01 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-06-29 11:19:01 +0100 |
| commit | d0b389a4e6805d2dc0ab13350656109e6cb163f9 (patch) | |
| tree | 37cd195c048a83fdd5d8486acc2ffc21fcbd53b0 | |
| parent | d2716eda7582f3b6a39b44565f571bdb7d286394 (diff) | |
CONN_DEVICE_NAME is configurable by env var
| -rwxr-xr-x | get_ip_addr.sh | 10 |
1 files 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 |
