Improved GetHostID if only ip binary is available

This commit is contained in:
mboelen 2014-09-25 17:57:25 +02:00
parent 27973d5c18
commit 9067551508

View File

@ -351,6 +351,7 @@
GetHostID() GetHostID()
{ {
HOSTID="-" HOSTID="-"
FIND=""
if [ ! "${SHA1SUMBINARY}" = "" ]; then if [ ! "${SHA1SUMBINARY}" = "" ]; then
case "${OS}" in case "${OS}" in
@ -378,7 +379,7 @@
#PREFERRED_INTERFACES="eth0 eth1 eth2 enp0s25" #PREFERRED_INTERFACES="eth0 eth1 eth2 enp0s25"
# Only use ifconfig if no ip binary has been found # Only use ifconfig if no ip binary has been found
if [ ! "${IFCONFIGBINARY}" = "" -a "${IPBINARY}" = "" ]; then if [ ! "${IFCONFIGBINARY}" = "" ]; then
# Determine if we have ETH0 at all (not all Linux distro have this, e.g. Arch) # Determine if we have ETH0 at all (not all Linux distro have this, e.g. Arch)
HASETH0=`${IFCONFIGBINARY} | grep "^eth0"` HASETH0=`${IFCONFIGBINARY} | grep "^eth0"`
# Check if we can find it with HWaddr on the line # Check if we can find it with HWaddr on the line
@ -405,11 +406,9 @@
ReportException "GetHostID" "No eth0 found (but HWaddr was found), using first network interface to determine hostid, with ifconfig" ReportException "GetHostID" "No eth0 found (but HWaddr was found), using first network interface to determine hostid, with ifconfig"
fi fi
fi fi
fi else
# See if we can use ip binary instead
# Check with ip binary (preferred to ifconfig)
if [ ! "${IPBINARY}" = "" ]; then if [ ! "${IPBINARY}" = "" ]; then
# Determine if we have the common available eth0 interface # Determine if we have the common available eth0 interface
FIND=`${IPBINARY} addr show eth0 2> /dev/null | egrep "link/ether " | head -1 | awk '{ print $2 }' | tr '[:upper:]' '[:lower:]'` FIND=`${IPBINARY} addr show eth0 2> /dev/null | egrep "link/ether " | head -1 | awk '{ print $2 }' | tr '[:upper:]' '[:lower:]'`
if [ "${FIND}" = "" ]; then if [ "${FIND}" = "" ]; then
@ -419,12 +418,15 @@
ReportException "GetHostID" "Can't create hostid (no MAC addresses found)" ReportException "GetHostID" "Can't create hostid (no MAC addresses found)"
fi fi
fi fi
else
ReportException "GetHostID" "Can't create hostid, missing both ifconfig and ip binary"
fi
fi
# Check if both commands give the same data # Check if we found a HostID
if [ ! "${FIND}" = "" ]; then if [ ! "${FIND}" = "" ]; then
HOSTID=`echo ${FIND} | ${SHA1SUMBINARY} | awk '{ print $1 }'` HOSTID=`echo ${FIND} | ${SHA1SUMBINARY} | awk '{ print $1 }'`
logtext "Result: Found HostID: ${HOSTID}" logtext "Result: Found HostID: ${HOSTID}"
fi
else else
ReportException "GetHostID" "Can't create HOSTID, command ip not found" ReportException "GetHostID" "Can't create HOSTID, command ip not found"
fi fi