#!/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/sgi_52/7.7tom/src/generic/RCS/check.client,v 1.3 94/10/06 15:10:54 tom Exp Locker: tom $
#

source $util/aliases

vclear
vecho ""
vecho ""
vecho "                        Check configuration"
vecho $bar
vecho ""
vecho ""
vecho "Possible modified files:"
vecho "			/etc/config/routed"
vecho "			/etc/config/ifconfig-1.options"
vecho "			/etc/init.d/network"
vecho ""
vecho "Renamed files:"
vecho "		/etc/hosts.equiv   -> /etc/hosts.equiv.insecure"
vecho ""
vecho ""
#	echo "If you only wish to see the list of modifications without"
#	echo "making any changes, use the 'list' option."
vecho ""
if($interactive == true) then
	get_response "continue? (yes/no) " "yes" "no" "list"
	if($status == 2) exit -1
endif
vecho ""

vlog "**   running config check:"
if (! -d /etc/athena) mkdir /etc/athena
if (! -d /bin/athena) mkdir /bin/athena

#
# check and/or fix netmask
#
if(! -f /etc/config/ifconfig-1.options) touch /etc/config/ifconfig-1.options
set netmask = `grep netmask /etc/config/ifconfig-1.options | awk '{print $2}' | head -1`
if($netmask != "0xffff0000") then
	vecho "     adding netmask..."
	echo "netmask 0xffff0000" > /etc/config/ifconfig-1.options
	vlog "     client: editing netmask in /etc/config/ifconfig-1.options"
else
	vecho "     netmask is ok"
	vlog "     client: netmask is ok ($netmask)"
endif


#
# check and/or fix bcast addr
#

set bcast = `grep broadcast /etc/config/ifconfig-1.options | awk '{print $2}' | head -1`
if($bcast != $broadcast) then
	vecho "     adding broadcast..."
	echo "netmask 0xffff0000" > /etc/config/ifconfig-1.options
	echo "broadcast $broadcast" >> /etc/config/ifconfig-1.options
	vlog "     client: editing broadcast in /etc/config/ifconfig-1.options"
else
	vecho "     broadcast is ok"
	vlog "     client: broadcast is ok ($bcast)"
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
	vlog "     client: renamed hosts.equiv"
endif

#
# move routed out of the way
#

if(! -f /etc/config/routed || `cat /etc/config/routed` == "on") then
	vecho "     turning off routed..."
	config.rc routed off
	vlog "     client: disabled routed"
endif

if(! -f /etc/config/rwhod || `cat /etc/config/rwhod` == "on") then
	vecho "     turning off rwhod..."
	config.rc rwhod off
	vlog "     client: disabled rhwod"
endif

if(! -f /etc/config/gated || `cat /etc/config/gated` == "on") then
	vecho "     turning off gated..."
	config.rc dated off
	vlog "     client: disabled gated"
endif

if(! -f /etc/config/network || `cat /etc/config/network` == "off") then
	vecho "     turning on network..."
	config.rc network on
	vlog "     client: enabled network"
endif

#
# default route
#

if (! -f /etc/config/staticroute) touch /etc/config/staticroute
if(! -f /etc/config/staticroute || `cat /etc/config/staticroute` != on) then
	vecho "     turning on static routing..."
	config.rc staticroute on
	vlog "     client: enabling static routing in /etc/config/staticroute"
endif

if (! -f /etc/config/staticroute.options) touch /etc/config/staticroute.options
if(! -f /etc/config/staticroute.options || `cat /etc/config/staticroute.options` != $router) then
		echo "     fixing static route..."
		echo $router >! /etc/config/staticroute.options
		vlog "     client: fixed static route via /etc/config/staticroute.options"
	else
		vecho "     default route is ok"
		vlog "     client: default route is ok ($network.0.1)"
	endif
endif

grep "staticroute.options" /etc/init.d/network > /dev/null
if($status) then
	vecho "     updating network init"
	install -c -m 755 $misc/network /etc/init.d/network
	vlog "     client: updated network init file"
endif

install -c -m 755 $misc/athena /etc/init.d/athena
if( ! -f /etc/rc2.d/S91athena) ln -s /etc/init.d/athena /etc/rc2.d/S91athena

if (-f /etc/rc0.d/K39network) then
	vecho "     old style static route detected.. disabling"
	rm -f /etc/rc0.d/K39network
	vlog "     client: removed old style static route"
endif

if (-f /etc/rc2.d/S31network) then
	vecho "     old style static route detected.. disabling"
	rm -f /etc/rc2.d/S31network
	vlog "     client: removed old style static route"
endif

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

vecho "done."
vlog "**   done"


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

exit 0
