From 79a7d40ef1e5da3a68ffb7e6546499fbbfa99c26 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Wed, 27 Apr 2016 14:25:47 +0200 Subject: [PATCH] vstart: use ip addr instead of ifconfig if available Ifconfig is obsolete with Linux 2.0+, and may not be in a user's PATH. Use ip addr by default and fall-back to ifconfig if it's missing. Signed-off-by: David Disseldorp --- src/vstart.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/vstart.sh b/src/vstart.sh index cfbdd1fc863..018d322f346 100755 --- a/src/vstart.sh +++ b/src/vstart.sh @@ -387,8 +387,13 @@ if [ -n "$ip" ]; then IP="$ip" else echo hostname $HOSTNAME + if [ -x "$(which ip 2>/dev/null)" ]; then + IP_CMD="ip addr" + else + IP_CMD="ifconfig" + fi # filter out IPv6 and localhost addresses - IP="$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | head -n1)" + IP="$($IP_CMD | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | head -n1)" # if nothing left, try using localhost address, it might work if [ -z "$IP" ]; then IP="127.0.0.1"; fi fi -- 2.39.5