#!/bin/csh -f
#
# Network Installation Kit
#
# install.net: install generic network utils
#
# Tom Coppeto
# MIT Network Group
# 17 September 1994
#
# Last Modified: 24 January 1996 by jyp
#

set pltfrm = `/usr/bin/uname`

source $util/aliases

vclear
vecho "INSTALL"
vecho ""
vecho "                        Network Utilities"
vecho $bar
vecho ""
vecho "New files:"
vecho "                /bin/athena/hesinfo"
vecho "                /bin/athena/hostinfo"
vecho "                /etc/named.*"
vecho "                /etc/resolv.conf"
vecho "                /etc/athena/gettime"
vecho "                /etc/athena/rc"

if ($pltfrm == "SunOS") then
	vecho "                /etc/athena/snmpd"
	vecho "Modified files:"
	vecho "                /etc/rc.local          /etc/services"
	vecho "                /usr/lib/libc.so.*"
	vecho "Renamed files:"
	vecho "                /usr/etc/in.named    -> /usr/etc/in.named.sun"
	vecho "                /usr/etc/sendmail.mx -> /usr/etc/sendmail"
endif
 
vecho "Disk consumed:"
if ($pltfrm == "SunOS") then
	vecho "                /             232Kb"
	vecho "                /usr          2088Kb"
	vecho ""
	df / /usr | vcat
else 
	vecho "                /               ?Kb"
	vecho "                /usr          540Kb"
	vecho ""
	df / | vcat
endif
vecho ""
if ($interactive == true) then
	get_response "continue? (yes/no) " "yes" "no"
	if ($status == 2) then
		exit -1
	endif
endif
vlog "**   running install.net:"

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

#
# named
#

vecho "     installing named configs..."
vlog "     net: installing named configs"
install -c -m 444 $net/named.boot /etc/named.boot
install -c -m 444 $net/named.root /etc/named.root
install -c -m 444 $net/named.mit /etc/named.mit
install -c -m 444 $net/resolv.conf /etc/resolv.conf


vecho "     installing named..."
if (($pltfrm != "SunOS") && ( ! -f /usr/sbin/named)) then
        install -c -m 555 $net/named /usr/sbin
else
	install -c -m 555 $net/named /etc/named
endif

vlog "     net: installed named"

if ($pltfrm == "IRIX") then
	if (! -f /usr/lib/libsocket.so) then
        	vecho "     installing  libsocket..."
        	install -c -m 444 $net/libsocket.so /usr/lib
        	vlog "     net: installed libsocket"
	endif
	if (! -f /usr/lib/libnsl.so) then
        	vecho "     installing libnsl..."
        	install -c -m 444 $net/libnsl.so /usr/lib
        	vlog "     net: installed libnsl"
	endif
	if(! -f /etc/config/named || `cat /etc/config/named` == "off") then
        	vecho "     turning on named..."
        	config.rc named on
        	vlog "     net: enabled named"
	endif
endif

if ($pltfrm == "SunOS") then
	if (-f /usr/etc/in.named) then
		mv /usr/etc/in.named /usr/etc/in.named.sun
		ln -s /etc/named /usr/etc/in.named
		vlog "     net: renamed /usr/etc/in.named"
	endif
endif

if( ! -f /etc/named.local) then
	cp /dev/null /etc/named.local
else
	vlog "     net: /etc/named.local exists"
endif

vecho "     installing dns binaries..."
vlog "     net: installing dns binaries"

install -c -m 555 $net/hostinfo /bin/athena
install -c -m 555 $net/hesinfo  /bin/athena

#
# deal with host table
#

set n = `grep -v "#" /etc/hosts | wc -l`
if($n != 2) then
	vecho "     editing host table..."
	save /etc/hosts
	echo "#" > /etc/hosts
	echo "# Host Database" >> /etc/hosts
	echo "#" >> /etc/hosts
	echo "#" >> /etc/hosts
	echo "127.0.0.1     localhost" >> /etc/hosts
	echo "#" >> /etc/hosts
	if ($pltfrm == "SunOS") then
		echo "$address     `hostname` loghost" >> /etc/hosts
	else 
		echo "$address     `hostname` " >> /etc/hosts
        endif
	vlog "     net: editing host table"
endif

#
# rc and version 
#

install -c -m 555 $util/version /etc/athena/version
version add DNS $dnsversion
version add TimeClient $timeversion
version add SNMP $snmpversion

if ($pltfrm == "SunOS") $util/install.rc

vlog "     net: updated rc and version"

#
# time
#

vecho "     installing time..."
vlog "     net: installing timed and friends"

install -c -m 555 $net/gettime /etc/athena/gettime

if ($pltfrm == "SunOS") then
	$util/config.rc TIMECLIENT true
	$util/config.rc TIMEHUB kerberos.mit.edu
else
	$util/config.rc timeclient on
	echo time.mit.edu >! /etc/config/timeclient.options
endif

#
# snmp (for SunOS)
#
if ($pltfrm == "SunOS") then
	vecho "     installing snmpd..."
	vlog "     net: installing snmpd & snmpd.conf"
	install -c -m 555 $net/snmpd /etc/snmpd
	chown daemon /etc/snmpd
	install -c -m 444 $net/snmpd.conf /etc/snmpd.conf
	config.rc SNMP true
endif

#
# shared C library (for SunOS)
# 

if ($pltfrm == "SunOS") then
	if (! -f /usr/lib/shlib.etc/lorder-sparc) then 
		cp /dev/null /usr/lib/shlib.etc/lorder-sparc
	endif
	if( -f /usr/lib/shlib.etc/lorder-sparc) then	
		vecho "     installing shared library..."
		grep res_query /usr/lib/shlib.etc/lorder-sparc > /dev/null
		if ($status) then
			vlog "     net: installing shared library"
			install -c $net/libc.so.1.9.4 /usr/lib
			install -c $net/libc.so.1.8.2 /usr/lib
			install -c $net/libc.so.1.7.3 /usr/lib	
			install -c $net/libc.so.1.6.1 /usr/lib
			/usr/etc/ldconfig
		else
			vecho "Looks like you already have dns... good boy."
		endif
	endif
endif
	
#
# sendmail (for SunOS)
#

if ($pltfrm == "SunOS") then
	if (-f /usr/lib/sendmail.mx) then
		vecho "     installing MX sendmail..."
		mv /usr/lib/sendmail /usr/lib/sendmail.nomx
		mv /usr/lib/sendmail.mx /usr/lib/sendmail
		vlog "     net: installed sendmail.mx"
	endif
endif

#
# /etc/services (for SunOS)
#

if ($pltfrm == "SunOS") then
	vecho "     services..."
	grep athena-timed /etc/services > /dev/null
	if ($status) then
        	save /etc/services
		vlog "     net: adding net services to /etc/services"
		cat $misc/services.add >> /etc/services
	endif
endif

vlog "**   done."
vecho "done."

if ($interactive == true) then
	echo ""
	echo "These changes will take effect after the next reboot."
	get_response "Press <return> to continue..." "<return>"
else
	sleep 5
endif

exit 0




