]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
vstart: use ip addr instead of ifconfig if available
authorDavid Disseldorp <ddiss@suse.de>
Wed, 27 Apr 2016 12:25:47 +0000 (14:25 +0200)
committerDavid Disseldorp <ddiss@suse.de>
Wed, 27 Apr 2016 21:49:52 +0000 (23:49 +0200)
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 <ddiss@suse.de>
src/vstart.sh

index cfbdd1fc863846808acc73cd16beb2c64dc27efb..018d322f34629b56bbbf3cef5da696bccdb3754b 100755 (executable)
@@ -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