Skip to content

Commit

Permalink
vstart: use ip addr instead of ifconfig if available
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ddiss committed Apr 27, 2016
1 parent cafe882 commit 79a7d40
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/vstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 79a7d40

Please sign in to comment.