Skip to content

Instantly share code, notes, and snippets.

@craigtracey
Created October 11, 2013 22:32
Show Gist options
  • Save craigtracey/6943040 to your computer and use it in GitHub Desktop.
Save craigtracey/6943040 to your computer and use it in GitHub Desktop.
late_command.sh for preseeding udev net rules. MACs obfuscated to protect the guilty.
# this sucks, but I think we need it.
declare -A mac_devices
mac_devices["aa:bb:cc:dd:ee:ff"]="eth0"
mac_devices["bb:cc:dd:ee:ff:aa"]="eth1"
mac_devices["cc:dd:ee:ff:aa:bb"]="eth8"
mac_devices["dd:ee:ff:aa:bb:cc"]="eth9"
UDEV_NET_RULES="/etc/udev/rules.d/70-persistent-net.rules"
echo "# This file was at least partially configured via pressed late command" > $UDEV_NET_RULES
for MAC in `ifconfig -a | grep HWaddr | awk '{print $5}'`; do
for i in "${!mac_devices[@]}"; do
if [ "$MAC" == "$i" ]; then
echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$i\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"${mac_devices[$i]}\"" >> $UDEV_NET_RULES
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment