a better way to set IP address with the EDEX service manager

Former-commit-id: 1715e9fe60 [formerly 7bff0bb7a3] [formerly fba486d50c] [formerly 42288b53542e7e4cc01144956f19f70bfadc0dba [formerly 664e147e90c04836a158dc62409e3f8d2dc8d4b4] [formerly fba486d50c [formerly 25cb18c0c7]]]
Former-commit-id: 8ec868abf247c9a41279933ceb95bc4af4c79c4d [formerly ab8bc0442c55fa79498901b40a635e7bcfc3b07a] [formerly 43326f949f [formerly 2dfbe88894]]
Former-commit-id: 43326f949f
Former-commit-id: 4cfe53682b
This commit is contained in:
mjames-upc 2015-06-15 10:00:20 -06:00
parent 19bfef77c4
commit c41401f85a

View file

@ -43,48 +43,21 @@ options=( 'status' 'start' 'stop' 'log' 'setup' 'test' )
nopts=${options[@]}
# main program
#
# Construct IP subnet
#
# OS X
#IP=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'`
# Linux
# Simple solution
#IP=`hostname -I`
# For multiple IP addresses we need to account for non-routable IPs
#IP=`/sbin/ifconfig | grep "inet addr" | grep -v 127.0.0 | awk '{ print $2 }' | cut -d: -f2`
ethdev=`ip link show| grep ^[0-9]| awk '{ print $2}'`
if [[ $ethdev =~ eth0 ]]; then
usedev=eth0
elif [[ $ethdev =~ wlan0 ]]; then
usedev=wlan0
fi
# better solution: find interface for routeable IPs
usedev=`netstat -rn | egrep "^0.0.0.0" | awk '{print $8}'`
IP=`/sbin/ifconfig $usedev | grep "inet addr" | awk '{ print $2 }' | cut -d: -f2`
if [[ $IP =~ ^10\..* || $IP =~ ^192\.168.* ]] # non-routable IP range
then
if [[ $ethdev =~ eth1 ]]; then
IP=`/sbin/ifconfig eth1 | grep "inet addr" | awk '{ print $2 }' | cut -d: -f2`
fi
elif [[ $IP =~ ^172\..* ]]
then
IPb=`echo $IP | cut -d"." -f2`
if [[ $IPb -gt 15 && $IPb -lt 32 ]] # non-routable 172.16 to 172.32 range
then
IP=`/sbin/ifconfig eth1 | grep "inet addr" | awk '{ print $2 }' | cut -d: -f2`
fi
fi
# truncate
IP_CIDR="${IP%.*}"
editFiles=($PG_FILE $EDEX_ENV_FILE $LDMD_CONF)
boolFiles=(true true true)
editFuncs=(edit_pg edit_edex edit_ldm)