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

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 ""
if ($interactive == true) then
	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, please use the 'list' option."
	vecho ""
	vecho ""
	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 ""

vlog "**   running 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

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

#
# check and/or fix netmask
#
if (! -f /etc/config/ifconfig-1.options) then 
	if ($listonly == true) then
		vecho "     The file /etc/config/ifconfig-1.options is not present"
	        vecho "        Proposed Change: Create /etc/config/ifconfig-1.options"
	else
		touch /etc/config/ifconfig-1.options
	endif
endif

if (-f /etc/config/ifconfig-1.options) then
	set netmask = `grep netmask /etc/config/ifconfig-1.options | awk '{print $2}' | head -1`
	if ($netmask != "0xffff0000") then
		if ($listonly == true) then
			vecho "     There is no netmask"
			vecho "        Proposed Change: Add netmask value of 0xffff0000 to /etc/config/ifconfig-1.options"
		else
			vecho "     adding netmask..."
			echo "netmask 0xffff0000" > /etc/config/ifconfig-1.options
			vlog "     client: editing netmask in /etc/config/ifconfig-1.options"
		endif
	else
		vecho "     netmask is ok"
		vlog "     client: netmask is ok ($netmask)"
	endif
endif

#
# check and/or fix bcast addr
#
if (-f /etc/config/ifconfig-1.options) then 
	set bcast = `grep broadcast /etc/config/ifconfig-1.options | awk '{print $2}' | head -1`
	if ($bcast != $broadcast) then
		if ($listonly == true) then
			vecho "     Broadcast not present"
			vecho "        Proposed Change: Add broadcast to /etc/config/ifconfig-1.options"
		else
			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"
		endif
	else
		vecho "     broadcast is ok"
		vlog "     client: broadcast is ok ($bcast)"
	endif
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 has been detected. It needs to be renamed."
		vecho "        Proposed Change: /etc/hosts.equiv will be renamed 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 /etc/config/routed) || (`cat /etc/config/routed` == "on")) then
	if ($listonly == true) then
		vecho "     routed needs to be turned off."
	else	
		vecho "     turning off routed..."
		config.rc routed off
		vlog "     client: disabled routed"
	endif
endif

if ((! -f /etc/config/rwhod) || (`cat /etc/config/rwhod` == "on")) then
	if ($listonly == true) then
		vecho "     rwhod needs to be turned off"
	else
		vecho "     turning off rwhod..."
		config.rc rwhod off
		vlog "     client: disabled rhwod"
	endif
endif

if ((! -f /etc/config/gated) || (`cat /etc/config/gated` == "on")) then
	if ($listonly == true) then
		vecho "     gated needs to be turned off."
	else
		vecho "     turning off gated..."
		config.rc gated off
		vlog "     client: disabled gated"
	endif
endif

if ((! -f /etc/config/network) || (`cat /etc/config/network` == "off")) then
	if ($listonly == true) then
		vecho "     network needs to be turned on."
	else
		vecho "     turning on network..."
		config.rc network on
		vlog "     client: enabled network"
	endif
endif

#
# default route
#

if (! -f /etc/config/staticroute) then 
	if ($listonly == true) then
		vecho "     The file /etc/config/staticroute is not present."
		vecho "        Proposed Change: Create /etc/config/staticroute."
	else
		touch /etc/config/staticroute
	endif
endif

if ((! -f /etc/config/staticroute) || (`cat /etc/config/staticroute` != "on")) then
	if ($listonly == true) then
		vecho "     static routing needs to be turned on."
	else
		vecho "     turning on static routing..."
		config.rc staticroute on
		vlog "     client: enabling static routing in /etc/config/staticroute"
	endif
endif

if (! -f /etc/config/staticroute.options) then
	if ($listonly == true) then
		vecho "     The file /etc/config/staticroute.options is not present."
		vecho "        Proposed Change: Create /etc/config/staticroute.options" 
	else
		touch /etc/config/staticroute.options
	endif
endif

if ((! -f /etc/config/staticroute.options) || (`cat /etc/config/staticroute.options` != $router)) then
	if ($listonly == true) then
		vecho "     Static route needs to be fixed."
		vecho "        Proposed Change: Fix static route via /etc/config/staticroute.options"
	else	
		vecho "     fixing static route..."
		echo $router >! /etc/config/staticroute.options
		vlog "     client: fixed static route via /etc/config/staticroute.options"
	endif
else
	vecho "     default route is ok"
	vlog "     client: default route is ok ($network.0.1)"
endif

grep "staticroute.options" /etc/init.d/network > /dev/null
if ($status) then
	if ($listonly == true) then
		vecho "     Network init needs to be updated."	
		vecho "        Proposed Change: Update $misc/network"
	else
		vecho "     updating network init"
		install -c -m 755 $misc/network /etc/init.d/network
		vlog "     client: updated network init file"
	endif
endif

install -c -m 755 $misc/athena /etc/init.d/athena


if (! -f /etc/rc2.d/S91athena) then
	if ($listonly == true) then
		vecho "     The file /etc/rc2.d/S91athena is not present."
		vecho "        Proposed Change: Create a symbolic link to /etc/init.d/athena."
	else
		ln -s /etc/init.d/athena /etc/rc2.d/S91athena
	endif
endif

if (-f /etc/rc0.d/K39network) then
	if ($listonly == true) then
		vecho "     Old style static route detected."
		vecho "        Proposed Change: Remove /etc/rc0.d/K39network." 	
	else
		vecho "     old style static route detected.. disabling"
		rm -f /etc/rc0.d/K39network
		vlog "     client: removed old style static route"
	endif
endif

if (-f /etc/rc2.d/S31network) then
	if ($listonly == true) then
		vecho "     Old style static route detected."
		vecho "        Proposed Change: Remove /etc/rc2.d/S31network."
	else
		vecho "     old style static route detected.. disabling"
		rm -f /etc/rc2.d/S31network
		vlog "     client: removed old style static route"
	endif
endif

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

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

vlog "**   done"

vecho ""

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-sgi
        else
                get_response "Press <return> to continue..." "<return>"
        endif
endif

exit 0
