#!/bin/csh -f
#
# Network Installation Kit
#
# check.srvnet: make a generic netops server
#
# Tom Coppeto
# MIT Network Group
# 17 September 1994
#
# Last Modified: 28 January 1996 by jyp
#

source $util/aliases

vclear
vecho ""
vecho ""
vecho "                      Check configuration (NET)"
vecho $bar
vecho ""
vecho ""
vecho "New files:"
vecho "                 /bin/csh               /etc/athena/update_server"
vecho "                 /etc/athena/rc.local   /etc/athena/newsyslog"
vecho ""
vecho "Possible modified files:"
vecho "	                /etc/inetd.conf        /etc/rc{.local}"
vecho "                 /.klogin               /etc/fstab"
vecho "                 /.cshrc                /etc/syslog.conf"
vecho ""
vecho "Renamed files:"
vecho "			/usr/lib/lpd            /usr/etc/keyserv"
vecho "			/usr/etc/rpc.statd      /usr/etc/rpc.lockd"
vecho ""
vecho ""

if ($interactive == true) then
	vecho "If you only wish to see the list of modifications without"
	vecho "making any changes, use the 'list' option."
	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

vecho ""
vecho "access to /afs/net/admin/configs is required."
vecho ""
vecho ""
retry:
/bin/athena/kinit 
if($status) goto retry
/bin/athena/aklog net.mit.edu
vecho ""
vecho "User authenticated with kerberos tickets"
vecho ""
vecho "Running net server check"
vlog "**  running net server check:"

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

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

if ( -f /usr/lib/lpd) then
	if ($listonly == true) then
		vecho "     The file /usr/lib/lpd is present. Print services must be disabled."
		vecho "        Proposed Change: Rename file to /usr/lib/lpd.norun."
	else
		vecho "     disabling print services..."
		mv /usr/lib/lpd /usr/lib/lpd.norun
		vlog "     srvnet: renamed lpd"
	endif
endif

if ( -f /usr/etc/keyserv) then
	if ($listonly == true) then
		vecho "     The file /usr/etc/keyserv is present. Keyserv must be disabled." 
		vecho "        Proposed Change: Rename file to /usr/etc/keyserv.norun."
	else
		vecho "     disabling keyserv..."
		mv /usr/etc/keyserv /usr/etc/keyserv.norun
		vlog "     srvnet: renamed keyserv"
	endif
endif

if ( -f /usr/etc/rpc.statd || -f /usr/etc/rpc.lockd) then
	if ($listonly == true) then
		vecho "     The file(s) /usr/etc/rpc.statd and/or /usr/etc/rpc.lockd are present."
		vecho "        Proposed Change: Rename file(s) with .norun extension."
	else
		vecho "     disabling rpc services..."
		mv -f /usr/etc/rpc.statd /usr/etc/rpc.statd.norun
		mv -f /usr/etc/rpc.lockd /usr/etc/rpc.lockd.norun
		vlog "     srvnet: renamed rpc.statd and rpc.lockd"
	endif
endif

echo net.mit.edu > /usr/vice/etc/ThisCell

#
# sendmail 
#

grep "/usr/lib/sendmail -bd" /etc/rc.local | grep -v \# > /dev/null
if ($status == 0) then
	if ($listonly == true) then
		vecho "     Sendmail needs to be edited out of rc.local."
	else
		vecho "     sendmail..."
		sed "s:/usr/lib/sendmail -bd:\#       /usr/lib/sendmail  -bd:" /etc/rc.local > /tmp/rc.local
		cp /tmp/rc.local /etc/rc.local
		vlog "     srvnet: edited sendmail out of rc.local"
	endif
endif

#
# crontab
#
if ($listonly == true) then
	vecho "     crontab needs to be replaced."
	vecho "        Proposed Change: Replace contents of /usr/spool/cron/crontabs/root with $netconf/generic/newsyslog.crontab."
else	
	vecho "     crontab..."
	rm /usr/spool/cron/crontabs/root
	vlog "     srvnet: removed crontab"
endif

#
# newsyslog
#

if ($listonly == true) then
	vecho "     newsyslog needs to be installed."
	vecho "        Proposed Change: the files /etc/athena/newsyslog.conf and /etc/athena/newsyslog will be created."
else
	vecho "     newsyslog..."
	install -c -m 644 $netconf/generic/newsyslog.conf /etc/athena
	install -c -m 755 /usr/athena/etc/newsyslog /etc/athena
	cat $netconf/generic/newsyslog.crontab >> /usr/spool/cron/crontabs/root
endif

#
# custom configs
#
if ($listonly == true) then
	vecho "     klogin, inetd.conf, syslog.conf, .cshrc, etc. has to be updated."
else
	vecho "     updating klogin,inetd.conf,syslog.conf,.cshrc..."
	install -c -m 444 $netconf/generic/klogin /.klogin
	install -c -m 444 $netconf/generic/syslog.conf /etc
	install -c -m 444 $netconf/generic/inetd.conf.sun4 /etc/inetd.conf
	install -c -m 444 $netconf/generic/cshrc.sun4 /.cshrc
	vlog "     srvnet: updated klogin,.cshrc and syslog.conf"
endif

#
# syslog files
#
if (! -d /usr/adm/mailer) then
	if ($listonly == true) then
		vecho "     The directory /usr/adm/mailer is not present."
		vecho "        Proposed Change: Create /usr/adm/mailer."
	else
		mkdir /usr/adm/mailer
	endif
endif

if (! -d /usr/adm/popper) then
        if ($listonly == true) then
                vecho "     The directory /usr/adm/popper is not present."
                vecho "        Proposed Change: Create /usr/adm/popper."
        else
		mkdir /usr/adm/popper

	endif
endif

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

if (! -d /usr/adm/moira) then
        if ($listonly == true) then
                vecho "     The directory /usr/adm/moira is not present."
                vecho "        Proposed Change: Create /usr/adm/moira."
        else
                mkdir /usr/adm/moira

        endif
endif


if ($listonly == true) then
	vecho ""
	vecho "     The files /usr/adm/mailer/syslog  /usr/adm/named/syslog" 
	vecho "               /usr/adm/popper/syslog  /usr/adm/sulog"
	vecho "               /usr/adm/moira/syslog"
	vecho "     will be updated if present or will be created if absent."
	vecho ""
	vecho "     The file /var/log will be deleted if present."
	vecho ""
else
	touch /usr/adm/mailer/syslog
	touch /usr/adm/popper/syslog
	touch /usr/adm/named/syslog
	touch /usr/adm/moira/syslog
	touch /usr/adm/sulog
	rm -rf /var/log
endif

#
# tcsh
#

if (! -f /bin/athena/tcsh) then 
	if ($listonly == true) then
		vecho "     The file /bin/athena/tcsh needs to be created."
	else
		touch /bin/athena/tcsh
	endif
endif

if (-f /usr/athena/bin/tcsh) then
	diff /bin/athena/tcsh /usr/athena/bin/tcsh > /dev/null
	if ($status) then
		if ($listonly == true) then
			vecho "     tcsh needs to be installed."
		else
			vecho "     installing tcsh..."
			install -c -m 555 /usr/athena/bin/tcsh /bin/athena
			vlog "     srvnet: installed tcsh"	
		endif
	endif
endif

#
# update_server
#
if ($listonly == true) then
	vecho "     update_server needs to be installed."
else
	vecho "     update_server..."
	install -c -m 755 /usr/athena/etc/update_server /etc/athena
	vlog "     srvnet: installed update_server"
endif

#
# /tmp
#

fgrep swap /etc/fstab | fgrep tmp > /dev/null
if ($status) then
	if ($listonly == true) then
		vecho "     /tmp needs to be configured as swap."
	else
		vecho "     /tmp..."
        	echo "swap      /tmp    tmp rw 0 0" >> /etc/fstab
        	sed "s/#mount \/tmp/mount \/tmp/" /etc/rc.local > /tmp/rc.local
		if ($status == 0) cp /tmp/rc.local /etc/rc.local
		vlog "     srvnet: configured /tmp/ as swap"
	endif
endif

#
# ninit
#

grep ninit /etc/rc.local > /dev/null
if ($status == 0) goto skip

if ($listonly == true) then
	vecho "     ninit needs to be configured."
else
	vecho "     configuring ninit..."
ed /etc/rc.local << EOF > /dev/null
/in.named/
-
a

# alternative to named
if [ -f /etc/ninit ]; then
        echo -n ' named'
        /etc/ninit /etc/named.boot 
fi

.
w
q
EOF
endif

skip:

#
# rc.local
#
if ($listonly == true) then
	vecho "     rc.local needs to be installed."
else
	vecho "     rc.local..."
	install -c -m 755 $misc/rc.srvnet /etc/athena/rc.local
	vlog "     srvnet: installed rc.local"
	config.rc MRUPDATE false
endif

#
# new kernel
#

setenv arch `arch -k`
if (-f $netbin/vmunix.$arch) then
	diff /vmunix $netbin/vmunix.$arch > /dev/null
	if($status) then
		if ($listonly == true) then
			vecho "     New kernel needs to be installed."
		else
			vecho "     installing kernel... (make sure to reboot)"
			save /vmunix
			install -c -m 755 $netbin/vmunix.$arch /vmunix
			vlog "     srvnet: installed new kernel"
		endif
	endif
endif

#
# configure version
#
if ($listonly == true) then
	vecho "     version needs to be updated."
else
	vecho "     updating version..."
	version add NetworkServer $srvnetversion
	echo $srvnetversstr > /etc/athena/version.txt
endif

vlog "srvnet: done"


if ($interactive == true) then
        vecho ""
        vecho "Done with the configuration check. "
	vecho ""
	if ($listonly == true) then
        	get_response "Press <return> to go back to the Check menu..." "<return>"
		setenv listonly false
        	$generic/check.srvnet
	else 
		touch $misc/reboot_flag
		get_response "Press <return> to continue..." "<return>"
	endif
else
	touch $misc/reboot_flag
	vecho "done."
endif

exit 0









