net-lib: add find_iface_with_link()
authorWill Woods <wwoods@redhat.com>
Thu, 23 Aug 2012 20:31:09 +0000 (16:31 -0400)
committerHarald Hoyer <harald@redhat.com>
Thu, 13 Jun 2013 12:07:17 +0000 (14:07 +0200)
Add a function to look at the system network interfaces and return the
first one it finds with an active link (if any.)

modules.d/40network/net-lib.sh

index 4161021..7b8d1d7 100644 (file)
@@ -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