#!/bin/csh -f
#
# Network Installation Kit
#
# check.client: make a generic client
#
# Tom Coppeto
# MIT Network Group
# 17 September 1994
#
# $Header: /afs/net.mit.edu/project/netconf/sun4/src/generic/RCS/check.client,v 1.1 94/09/18 11:50:28 tom Exp $
#

source $util/aliases

clear
vecho ""
vecho ""
vecho "                        Check configuration"
vecho $bar
vecho ""
vecho ""
vecho "Possible modified files:"
vecho "			/etc/defaultrouter (4.1.2 and later)"
vecho "			/etc/rc{.local}	   (4.1.1 and earlier)"
vecho "			/etc/netmasks"
vecho ""
vecho "Renamed files:"
vecho "		/etc/hosts.equiv   -> /etc/hosts.equiv.insecure"
vecho "		/usr/etc/in.routed -> /usr/etc/in.routed.notuseatmit"
vecho ""
vecho ""

#	echo "If you only wish to see the list of modifications without"
#	echo "making any changes, use the 'list' option."
#	echo ""

if($interactive == true) then
	get_response "continue? (yes/no) " "yes" "no"
	if($status == 2) exit -1
endif

log "**  running client config check:"

if (! -d /etc/athena) mkdir /etc/athena

#
# check and/or fix netmask
#

set netmask = `grep "^18" /etc/netmasks | awk '{print $2}'`
if($netmask == "") then
	vecho "     adding netmask..."
	echo "18             255.255.0.0" >> /etc/netmasks	
	log "     client: appending netmask to /etc/netmasks"
endif

if($netmask != 255.255.0.0) then
	vecho "     correcting netmask..."
	save /etc/netmasks
	log "     client: saved /etc/netmasks to /etc/netmasks.`date`"

ed /etc/netmasks << EOF > /dev/null
/^18/
d
a
18 	255.255.0.0
.
w
q
EOF

	log "     client: corrected netmask from $netmask"
else
	vecho "     netmask is ok"
	log "     client: netmask is ok ($netmask)"
endif


#
# move hosts.equiv file out of the way
#

if(-f /etc/hosts.equiv) then
	vecho "     renaming /etc/hosts.equiv..."
	mv /etc/hosts.equiv /etc/hosts.equiv.insecure
	log "     client: renamed hosts.equiv"
endif

#
# move routed oput of the way
#

if(-f /usr/etc/in.routed) then
	vecho "     renaming /usr/etc/routed..."
	mv /usr/etc/in.routed /usr/etc/in.routed.notuseatmit
	log "     client: renamed /usr/etc/in.routed"
endif


#
# default route is version specific (should we fix this)?
#

if($router != "" && ($osversion == SUNOS4.1.2) || ($osversion == SUNOS4.1.3) || ($osversion == SUNOS4.1.3C) || ($osversion == SUNOS4.1.3_U1)) then
	if(! -f /etc/defaultrouter) then
		vecho "     adding default route..."
		echo $router >! /etc/defaultrouter
		log "     client: added default route via /etc/defaultrouter"
	endif

	if(`cat /etc/defaultrouter` != $router) then
		echo "    fixing default route..."
		rm -f /etc/defaultrouter
		echo $router >! /etc/defaultrouter
		log "    client: fixed default route via /etc/defaultrouter"
	else
		vecho "     default route is ok"
		log "     client: default route is ok ($router)"
	endif
endif


#
# deal with IP broadcast address
#

set ifconfig = `grep ifconfig /etc/rc.local` > /dev/null

if("$ifconfig" != "ifconfig -a netmask + broadcast 18." && $broadcast != "+") then
	vecho "     fixing broadcast address..."
	sed "s/ifconfig -a netmask + broadcast +/ifconfig -a netmask + broadcast $broadcast/" /etc/rc.local > /etc/rc.local.new
	save /etc/rc.local
	mv /etc/rc.local.new /etc/rc.local	
	log "     client: changed broadcast address to $broadcast"
endif

#
# version
#

vecho "     updating version..."
version add GenericClient  $clientversion
echo $clientversstr > /etc/athena/version.txt
log "     client: updated version"

vecho "done."
log "client: done"


if($interactive == true) then	
	echo ""
	get_response "Press <return> to continue..." "<return>"
endif

exit 0
