#!/bin/ksh -p
#pragma ident "@(#)jdhostgbl	1.13 97/02/27 SMI"
#
# Copyright 02/27/97 Sun Microsystems, Inc. All Rights Reserved
#
# Synopsis: jdhostgbl dnsdomain dnsserver subnetmask router [nisdomain]
#    where - is used to indicate a missing parameter

(( $# == 4 || $# == 5 )) || {
	print "usage: jdhostgbl dnsdomain dnsserver subnetmask" \
		     "router [nisdomain]"
	exit 1
}

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

print Configuring Global Data

# Create dhcptab if necessary (see dhcptab(4) and dhtadm(1m) for info)
# And make sure the correct JOScmd symbols are present

for i in 1 2 3 4
do
        dhtadm -D -s JOScmd$i 2> /dev/null
        dhtadm -A -s JOScmd$i -d Vendor=SUNW.JavaStation,10$i,ASCII,1,0
done

# Clean up leftover garbage.  Remove when bug fixed.  Sigh...

rm -f /var/dhcp/AAA*

# Set up a new SUNW.JavaStation macro after deleting existing one

dhtadm -D -m SUNW.JavaStation 2> /dev/null

# Specify an infinite lease time

dhtadm -A -m SUNW.JavaStation -d ":LeaseTim=-1:"

# Use this host as RFC868 time server

dhtadm -M -m SUNW.JavaStation -e "Timeserv=$(name_to_ip $(uname -n))"

# Add DNS domain name

[[ $1 == "-" ]] && {
	print "DNS domain name required"
	exit 1
}
dhtadm -M -m SUNW.JavaStation -e "DNSdmain=$1"

# And DNS server IP address

[[ $2 == "-" ]] && {
	print "DNS server IP address required"
	exit 1
}
dhtadm -M -m SUNW.JavaStation -e "DNSserv=$2"

# Add subnet mask

[[ $3 == "-" ]] && {
	print "Subnet mask required"
	exit 1
}
dhtadm -M -m SUNW.JavaStation -e "Subnet=$3"

# Timezone is optional (default is UTC)

dhtadm -M -m SUNW.JavaStation -e "JOScmd1=\"+tz $(tzprint)\""

# NIS domain is optional (default is guest login)

NISdmain=${5:-$(domainname)}
[[ $NISdmain == "" ]] || \
	dhtadm -M -m SUNW.JavaStation -e "NISdmain=$NISdmain"

# Router is optional (default and prefered is router discovery)

[[ $4 == "-" ]] || dhtadm -M -m SUNW.JavaStation -e "Router=$4"

print Global Data Updated

