#!/bin/sh
#
# /sbin/ifup-local
#
# This script updates the IP address of this hosts
# entry in /etc/hosts.
#
# PREREQUISITE: there must already be an entry in /etc/hosts
# for this system with the proper hostname.
#
if [ "${1}" = "" ]
then
 echo "Using eth0 by default ..."
 ipaddr=`/sbin/ifconfig eth0 | grep "inet addr:" | sed 's/.*addr:\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/1'`
else 
 ipaddr=`/sbin/ifconfig ${1} | grep "inet addr:" | sed 's/.*addr:\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/1'`
fi
    myname=`hostname`
    echo "Updating /etc/hosts file ..."
    if [ "$ipaddr" = "" ]
    then
    	echo "No address fount. Using 127.0.0.1"
	ipaddr="127.0.0.1"
    fi
    echo "Setting $ipaddr for host $myname"
    string="s/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\([^0-9A-Za-z]*$myname[^0-9A-Za-z]\)/$ipaddr\2/"
    sed "$string" /etc/hosts > /tmp/etc.hosts
#    sed "$string" /etc/hosts

    cp /tmp/etc.hosts /etc/hosts
    rm /tmp/etc.hosts
#fi
# EOF
