Support adding DHCP interfaces one at a time.

Refactors dhcp-all-interfaces.sh so that if an optional
INTERFACE argument (the first argument) is passed to the script
it only inspects that single interface. If no argument is
passed then the previous default behaviour use used which
causes all interfaces to be inspected.

Also sets PATH so that the commands within the script
can all be found if it isn't set properly (/sbin/ip, /bin/cat, etc.)

This is a move towards using udev rules to add these types
of interfaces automatically.

Change-Id: Ia482c1d3ddce0f0d8d77f9bc3ac76d6924640715
This commit is contained in:
Dan Prince 2014-02-07 13:37:03 -05:00
parent a3f2836625
commit a1b469b10b

View File

@ -1,7 +1,10 @@
#!/bin/bash #!/bin/bash
INTERFACE=$1 #optional, if not specified configure all available interfaces
ENI_FILE="/etc/network/interfaces" ENI_FILE="/etc/network/interfaces"
PATH=/bin:/sbin:$PATH
if [ -d "/etc/network" ]; then if [ -d "/etc/network" ]; then
CONF_TYPE="eni" CONF_TYPE="eni"
elif [ -d "/etc/sysconfig/network-scripts/" ]; then elif [ -d "/etc/sysconfig/network-scripts/" ]; then
@ -63,16 +66,17 @@ function config_exists() {
fi fi
} }
for interface in $(ls /sys/class/net | grep -v ^lo$) ; do function inspect_interface() {
MAC_ADDR_TYPE="$(cat /sys/class/net/${interface}/addr_assign_type)" local interface=$1
local mac_addr_type="$(cat /sys/class/net/${interface}/addr_assign_type)"
echo -n "Inspecting interface: $interface..." echo -n "Inspecting interface: $interface..."
if config_exists $interface; then if config_exists $interface; then
echo "Has config, skipping." echo "Has config, skipping."
elif [ "$MAC_ADDR_TYPE" != "0" ]; then elif [ "$mac_addr_type" != "0" ]; then
echo "Device has generated MAC, skipping." echo "Device has generated MAC, skipping."
else else
ip link set dev $interface up >/dev/null 2>&1 ip link set dev $interface up &>/dev/null
HAS_LINK="$(get_if_link $interface)" HAS_LINK="$(get_if_link $interface)"
TRIES=10 TRIES=10
@ -91,4 +95,13 @@ for interface in $(ls /sys/class/net | grep -v ^lo$) ; do
disable_interface "$interface" disable_interface "$interface"
fi fi
fi fi
}
if [ -n "$INTERFACE" ]; then
inspect_interface $INTERFACE
else
for iface in $(ls /sys/class/net | grep -v ^lo$); do
inspect_interface $iface
done done
fi