From 22edbf98f3910588db78aae295f41465f471da6c Mon Sep 17 00:00:00 2001 From: toby Date: Thu, 4 Oct 2018 18:12:55 +0200 Subject: [PATCH] adding mac udev rules through DNS lookup configs --- debian/wit-network-config.postinst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/debian/wit-network-config.postinst b/debian/wit-network-config.postinst index 2ad5aaa..5e0a2fa 100755 --- a/debian/wit-network-config.postinst +++ b/debian/wit-network-config.postinst @@ -36,8 +36,11 @@ case "$1" in exit 2 fi - - MGMT_MAC=$(ip -br link show dev $(ip -4 -br addr | grep 10.0. | awk '{ print $1 }') | awk '{ print $3 }') + declare -A MACS + for if in mgmt feth1 feth2 up1 up2 + do + MACS["$if"]=$(dig txt +short mac.$if.$HOSTNAME) ## careful mac will be wrapped in quotes, but we don't care since we'll need it again wrapped in quotes (so far) + done ## END variables @@ -104,15 +107,12 @@ case "$1" in # write udev rules for device names - echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$MGMT_MAC'", ATTR{type}=="1", NAME="mgmt1"' >/etc/udev/rules.d/70-persistent-net.rules - i=0 - for nic in $(ip -br link | awk '{ print $1 }'); do - if ethtool $nic | grep -q 10000; then - i=$((i+1)) - echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$(cat /sys/class/net/$nic/address)'", ATTR{type}=="1", NAME="feth'$i'"' >>/etc/udev/rules.d/70-persistent-net.rules - fi - done - sed -i "/$MGMT_MAC.*feth./d" /etc/udev/rules.d/70-persistent-net.rules + for if in ${!MACS[@]} + do + ifmac=${MACS[$if]} + [ "$if" == "mgmt" ] && if=mgmt1 + [ -z "$ifmac" ] || echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=='$mac', ATTR{type}=="1", NAME="'${if}'"' + done >/etc/udev/rules.d/70-persistent-net.rules