2013-03-05 17:34:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Generate $INTERFACES_FILE on first boot
|
|
|
|
# This will add any unconfigured network interfaces to /etc/network/interfaces
|
|
|
|
# and configure them for DHCP
|
|
|
|
|
|
|
|
INTERFACES_FILE="/etc/network/interfaces"
|
|
|
|
|
2013-10-11 18:02:52 +00:00
|
|
|
# Serialize runs so that we don't miss hot-add interfaces
|
|
|
|
FLOCK=${1:-}
|
|
|
|
if [ -z "$FLOCK" ] ; then
|
|
|
|
exec flock -x $INTERFACES_FILE $0 flocked
|
|
|
|
fi
|
|
|
|
|
2013-03-05 17:34:19 +00:00
|
|
|
function get_if_link() {
|
|
|
|
cat /sys/class/net/${1}/carrier
|
|
|
|
}
|
|
|
|
|
|
|
|
for interface in $(ls /sys/class/net | grep -v ^lo$) ; do
|
|
|
|
echo -n "Inspecting interface: $interface..."
|
2013-10-11 18:01:06 +00:00
|
|
|
if ifquery $interface >/dev/null 2>&1 ; then
|
|
|
|
echo "Has config, skipping."
|
|
|
|
else
|
2013-03-05 17:34:19 +00:00
|
|
|
ip link set dev $interface up >/dev/null 2>&1
|
|
|
|
HAS_LINK="$(get_if_link $interface)"
|
|
|
|
|
|
|
|
TRIES=3
|
|
|
|
while [ "$HAS_LINK" == "0" -a $TRIES -gt 0 ]; do
|
|
|
|
HAS_LINK="$(get_if_link $interface)"
|
|
|
|
if [ "$HAS_LINK" == "1" ]; then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
TRIES=$(( TRIES - 1 ))
|
|
|
|
done
|
|
|
|
if [ "$HAS_LINK" == "1" ] ; then
|
2013-10-11 18:04:54 +00:00
|
|
|
printf "auto $interface\niface $interface inet dhcp\n\n" >>$INTERFACES_FILE
|
2013-03-05 17:34:19 +00:00
|
|
|
echo "Configured"
|
|
|
|
else
|
|
|
|
echo "No link detected, skipping"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|