#!/bin/ksh -p
#pragma ident "@(#)jdhostmod	1.5 96/11/14 SMI"
#
# Copyright 14 Nov 1996 Sun Microsystems, Inc. All Rights Reserved
#
# Synopsis: jdhostmod name enet

(( $# == 2 )) || {
	print "usage: jdhostmod name enet"
	exit 1
}

fullname=$(whence $0)
dirname=${fullname%/*}
FPATH=${dirname%%/bin*}/lib

print Modifying $1

# Update dhcp database.  Do this first so failure won't corrupt /etc/ethers

ip=$(name_to_ip $1)
net=$(net_number $ip)
cid=$(client_id $2)

pntadm -M $1 -i $cid $net
ec=$?
(( $ec < 4 )) || {
	print "pntadm returned error $ec"
	exit 1
}

# Change /etc/ethers to contain the new Ethernet address

ethers=/etc/ethers
[[ -f $ethers ]] || {
        print "$ethers does not exist"
        exit 1
}
 
trap "rm -f $ethers.$$" EXIT
 
nawk -f - $ethers > $ethers.$$ <<-FINIS
\$2 == "$1"	{ print "$2\t$1"; next }
		{ print }
FINIS
 
cp $ethers.$$ $ethers
 
rm -f $ethers.$$
 
trap - EXIT

print $1 modified


	



