From: Will Woods Date: Thu, 23 Aug 2012 20:31:09 +0000 (-0400) Subject: net-lib: add find_iface_with_link() X-Git-Tag: 029~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd0f2c034a58f555d92e266552ce857e442eef0e;p=thirdparty%2Fdracut.git net-lib: add find_iface_with_link() Add a function to look at the system network interfaces and return the first one it finds with an active link (if any.) --- diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh index 416102169..7b8d1d76b 100644 --- a/modules.d/40network/net-lib.sh +++ b/modules.d/40network/net-lib.sh @@ -34,6 +34,19 @@ iface_has_link() { # XXX Do we need to reset the flags here? anaconda never bothered.. } +find_iface_with_link() { + local iface_path="" iface="" + for iface_path in /sys/class/net/*; do + iface=${iface_path##*/} + str_starts "$iface" "lo" && continue + if iface_has_link $iface; then + echo "$iface" + return 0 + fi + done + return 1 +} + all_ifaces_up() { local iface="" IFACES="" [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces