Fix ifconfig output parsing against various OSes.

Signed-off-by: Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
This commit is contained in:
Sébastien Gross 2012-05-30 17:46:46 +02:00
parent cf980f2985
commit 4f303ecb27

View file

@ -20,19 +20,22 @@
# #
# List all network interfaces in explorer/ifaces. One interface per line. # List all network interfaces in explorer/ifaces. One interface per line.
# #
# If your OS is not supported please provide a ifconfig output
#
uname_s="$(uname -s)" uname_s="$(uname -s)"
REGEXP='s/^(.*)(:[[:space:]]*flags=|Link encap).*/\1/p'
case "$uname_s" in case "$uname_s" in
Linux) Darwin)
ifconfig | sed -n 's/^\([^[:space:]]\+\)[[:space:]].*/\1/p' ifconfig -a | sed -n -E "$REGEXP"
exit 0
;; ;;
Darwin|*BSD) Linux|*BSD)
ifconfig | sed -n 's/^\([^:]*\): flags.*/\1/p' ifconfig -a | sed -n -r "$REGEXP"
exit 0 ;;
*)
echo "Unsupported ifconfig output for $uname_s" >&2
exit 1
;; ;;
esac esac
echo "Unknown OS" >&2
exit 1