HOSTIP=$(ip addr | sed -e '/127.0.0.1/d' -e 's/ *inet *\([^\/]*\).*/\1/;tx;d;:x')
This gets interface information using ip command, sed is used to remove everything except the inet4 ip address.
As this involves screen scraping it's prone to failure if the remote site changes
MYGLOBALIP=$(curl http://www.myglobalip.com/ 2>/dev/null | sed -n 's/.*>\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/p')