CONN_DEVICE_NAME is configurable by env var

This commit is contained in:
2026-06-29 11:19:01 +01:00
parent d2716eda75
commit d0b389a4e6
+5 -5
View File
@@ -14,15 +14,15 @@ fi
set -eu set -eu
CONN_NAME=${CONN_NAME:-nevis} 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)" 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 if [ -z "${CONN_DEVICE_NAME:-}" ]; then
echo "Could not find the connection device name for connection: \"$CONN_NAME\"" >&2 echo "Could not find the connection device name for connection: \"$CONN_NAME\"" >&2
exit 1 exit 1
fi 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 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 exit 1
fi fi
@@ -45,7 +45,7 @@ else
fi fi
ip="$(echo "$ip_addr_output_for_device" | grep "scope global" | grep -oE $ip_regex | head -n 1)" ip="$(echo "$ip_addr_output_for_device" | grep "scope global" | grep -oE $ip_regex | head -n 1)"
if [ -z "${ip:-}" ]; then 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 exit 1
fi fi