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>
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