From a1b469b10b90b594c256295c140e837726058b87 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 7 Feb 2014 13:37:03 -0500 Subject: [PATCH] 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 --- .../install.d/dhcp-all-interfaces.sh | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh b/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh index 7d53352d..60b3179e 100755 --- a/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh +++ b/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh @@ -1,7 +1,10 @@ #!/bin/bash +INTERFACE=$1 #optional, if not specified configure all available interfaces ENI_FILE="/etc/network/interfaces" +PATH=/bin:/sbin:$PATH + if [ -d "/etc/network" ]; then CONF_TYPE="eni" elif [ -d "/etc/sysconfig/network-scripts/" ]; then @@ -63,16 +66,17 @@ function config_exists() { fi } -for interface in $(ls /sys/class/net | grep -v ^lo$) ; do - MAC_ADDR_TYPE="$(cat /sys/class/net/${interface}/addr_assign_type)" +function inspect_interface() { + local interface=$1 + local mac_addr_type="$(cat /sys/class/net/${interface}/addr_assign_type)" echo -n "Inspecting interface: $interface..." if config_exists $interface; then echo "Has config, skipping." - elif [ "$MAC_ADDR_TYPE" != "0" ]; then + elif [ "$mac_addr_type" != "0" ]; then echo "Device has generated MAC, skipping." - else - ip link set dev $interface up >/dev/null 2>&1 + else + ip link set dev $interface up &>/dev/null HAS_LINK="$(get_if_link $interface)" TRIES=10 @@ -91,4 +95,13 @@ for interface in $(ls /sys/class/net | grep -v ^lo$) ; do disable_interface "$interface" fi fi -done + +} + +if [ -n "$INTERFACE" ]; then + inspect_interface $INTERFACE +else + for iface in $(ls /sys/class/net | grep -v ^lo$); do + inspect_interface $iface + done +fi