#!/bin/csh -f
#
# Network Installation Kit
#
# check.client-sunos: make a generic client for SunOS machines
#
# Tom Coppeto
# MIT Network Group
# 17 September 1994
#
# Last Modified 28 January 1996 by jyp
#

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 ""
vecho "If you would like the modifications to take place automatically,"
vecho "please select the 'yes' option."
vecho ""
vecho "If you do not want any modifications to take place,"
vecho "please select the 'no' option."
vecho ""
vecho "If you only wish to see the list of modifications without"
vecho "making any changes, use the 'list' option."
vecho ""

if ($interactive == true) then
	get_response "continue? (yes/no/list) " "yes" "no" "list"
	set choice = $status
        if ($choice == 2) then
                exit -1
        else 
                if ($choice == 3) then
                        setenv listonly true
                endif
        endif
endif

vecho ""
vecho "Running config check..."
vecho ""

vlog "**  running client config check:"

if (! -d /etc/athena) then
	if ($listonly == true) then
		vecho "     The directory /etc/athena is not present"
		vecho "        Proposed Change: Create /etc/athena"
	else 
		mkdir /etc/athena
	endif 
endif


#
# check and/or fix netmask
#

set netmask = `grep "^18" /etc/netmasks | awk '{print $2}'`

if ($netmask == "") then
	if ($listonly == true) then
		vecho "     There is no netmask"
		vecho "        Proposed Change: Add 255.255.0.0 to /etc/netmasks"
	else
		vecho "     adding netmask..."
		echo "18             255.255.0.0" >> /etc/netmasks	
		vlog "     client: appending netmask to /etc/netmasks"
	endif
endif

if ($netmask != "255.255.0.0") then
	if ($listonly == true) then
		vecho "     Netmask incorrect value"
		vecho "        Proposed Change: Correct netmask to 255.255.0.0"
	else
		vecho "     correcting netmask..."
		save /etc/netmasks
		vlog "     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
		vlog "     client: corrected netmask from $netmask"
	endif
else
	vecho "     netmask is ok"
	vlog "     client: netmask is ok ($netmask)"
endif

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

if (-f /etc/hosts.equiv) then
	if ($listonly == true) then
		vecho "     The file /etc/hosts.equiv is present and cannot be used"
		vecho "        Proposed Change: Rename /etc/hosts.equiv to /etc/hosts.equiv.insecure"
	else
		vecho "     renaming /etc/hosts.equiv..."
		mv /etc/hosts.equiv /etc/hosts.equiv.insecure
		vlog "     client: renamed hosts.equiv"
	endif
endif

#
# move routed out of the way
#

if (-f /usr/etc/in.routed) then
	if ($listonly == true) then
		vecho "     The file /usr/etc/in.routed is present and cannot be used"
		vecho "        Proposed Change: Rename /usr/etc/in.routed to /usr/etc/in.routed.notuseatmit"  
	else
		vecho "     renaming /usr/etc/in.routed..."
		mv /usr/etc/in.routed /usr/etc/in.routed.notuseatmit
		vlog "     client: renamed /usr/etc/in.routed"
	endif
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
		if ($listonly == true) then
			vecho "     Default route is not present"
			vecho "        Proposed Change: Add default route via /etc/defaultrouter"
		else
			vecho "     adding default route..."
			echo $router >! /etc/defaultrouter
			vlog "     client: added default route via /etc/defaultrouter"
	        endif
	else	
		if (`cat /etc/defaultrouter` != $router) then
			if ($listonly == true) then
				vecho "     Default route in /etc/defaultrouter is incorrect"
				vecho "        Proposed Change: Fix default route"
			else
				vecho "    fixing default route..."
				rm -f /etc/defaultrouter
				echo $router >! /etc/defaultrouter
				vlog "    client: fixed default route via /etc/defaultrouter"
			endif
		else
			vecho "     default route is ok"
			vlog "     client: default route is ok ($router)"
		endif
	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
	if ($listonly == true) then
		vecho "     Broadcast address needs to be fixed"
	else
		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	
		vlog "     client: changed broadcast address to $broadcast"
	endif
endif

#
# version
#

if ($listonly == true) then
	vecho "     Version needs to be updated"
else
	vecho "     updating version..."
	version add GenericClient  $clientversion
	echo $clientversstr > /etc/athena/version.txt
	vlog "     client: updated version"
	vecho "     done."
	vlog "client: done"
endif
vecho ""

if ($listonly == true) then
	vecho "Network Check: done."
	vecho ""
endif

if ($interactive == true) then	
	if ($listonly == true) then
		get_response "Press <return> to go back to the config check menu..." "<return>"
		setenv listonly false
		$generic/check.client-sunos
	else
		get_response "Press <return> to continue..." "<return>"
	endif
endif

exit 0
