#!/bin/sh
if [ -n "$DEBUG" ];then set -x;fi
#	AddIPAddr addr name [alias]...
#
# Add an address and a list of names to /etc/hosts.  This is used by the
# AddSlipMaster and AddslipSlave scripts; it must work properly even when
# the address and/or names are already in the file.  This may have to be
# radically revised if Ultrix ever goes to a database instead of a flat 
# file.

if [ $# -lt 2 ];then echo Usage: "$0 IPaddr name [alias]..."; exit -1; fi
test "$TMPDIR" || TMPDIR=/tmp; export TMPDIR
test -d "$TMPDIR" || echo "***** Warning: $TMPDIR directory missing."

A=$1
shift
E=$TMPDIR/$$.ed

if grep  >/dev/null "^$A[	 ]" /etc/hosts;then
	echo "$A already in /etc/hosts; adding aliases."
	echo >$E "/^$A/" 
	echo>>$E 's/$/ '$*'/'
else
	echo "$A not in /etc/hosts; adding new entry."
	echo >$E '$' 
	echo>>$E 'a'
	echo>>$E $A'	'$*
	echo>>$E '.'
fi
echo>>$E 'w'
echo>>$E 'q'
ed   <$E >/dev/null /etc/hosts
echo Here is the new /etc/hosts entry:
grep "^$A[	 ]" /etc/hosts

rm -f $E
