added netGetIfaces() 1.02.04
authorMichael Gebetsroither <michael.geb@gmx.at>
Tue, 8 Nov 2005 17:16:33 +0000 (18:16 +0100)
committerMichael Gebetsroither <michael.geb@gmx.at>
Tue, 8 Nov 2005 17:16:33 +0000 (18:16 +0100)
debian/changelog
debian/control
sh-lib

index d1a57f2..01ee267 100644 (file)
@@ -1,8 +1,10 @@
 sh-lib (1.02.04) unstable; urgency=low
 
   * added TODO 
+  * added iproute to dependencies (ip)
+  * added netGetIfaces()
 
- -- Michael Gebetsroither <michael.geb@gmx.at>  Wed,  5 Oct 2005 18:42:31 +0200
+ -- Michael Gebetsroither <michael.geb@gmx.at>  Tue,  8 Nov 2005 18:10:49 +0100
 
 sh-lib (1.02.03) unstable; urgency=low
 
index 1f4e966..19a6d4d 100644 (file)
@@ -7,6 +7,6 @@ Standards-Version: 3.6.1
 
 Package: sh-lib
 Architecture: all
-Depends: ${misc:Depends}, procps, net-tools, gawk
+Depends: ${misc:Depends}, procps, net-tools, gawk, iproute
 Description: Generic shell library
  The sh-lib is developed on zsh, only partially tested on bash.
diff --git a/sh-lib b/sh-lib
index 2183b56..4d858a9 100644 (file)
--- a/sh-lib
+++ b/sh-lib
@@ -428,6 +428,28 @@ function netValidIp
   return $ret_
 }
 
+function netGetIfaces
+{
+       local error_function_=${1:-"eprint"}    # function to call on error
+       local message_="$2"    # user supplied error message
+       local if_=''
+       local ret_=''
+
+       #ip a|grep 'inet ' |awk '$NF !~ /lo/{print $NF}'
+       if_="`ip a|grep 'inet ' |awk '{print $NF}'`"
+       ret_=$?
+       if [ -z "$if_" ]; then
+               if [ -z "$message_" ]; then
+                       "$error_function_" "no interfaces found" $ret_
+               else
+                       "$error_function_" "$message_" $ret_
+               fi
+               return 1
+       fi
+       dprint "interfaces found" $ret_
+       echo "$if_"
+}
+
 # FIXME
 function netGetDefaultGateway
 {