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.
#
# If your OS is not supported please provide a ifconfig output
#
uname_s="$(uname -s)"
REGEXP='s/^(.*)(:[[:space:]]*flags=|Link encap).*/\1/p'
case "$uname_s" in
Linux)
ifconfig | sed -n 's/^\([^[:space:]]\+\)[[:space:]].*/\1/p'
exit 0
Darwin)
ifconfig -a | sed -n -E "$REGEXP"
;;
Darwin|*BSD)
ifconfig | sed -n 's/^\([^:]*\): flags.*/\1/p'
exit 0
Linux|*BSD)
ifconfig -a | sed -n -r "$REGEXP"
;;
*)
echo "Unsupported ifconfig output for $uname_s" >&2
exit 1
;;
esac
echo "Unknown OS" >&2
exit 1