#!/bin/sh
#	$Id: sipbserv.add,v 1.2 1999/11/24 05:53:34 mhpower Exp $
#	$Revision: 1.2 $
#	$Platforms: sun4,sgi$

mach=`/bin/athena/machtype`
INETDIR=/etc/athena
SIPBTOP=/afs/sipb.mit.edu/service/solaris
SIPBCF=$SIPBTOP/cf
SIPBCBIN=$SIPBTOP/bin

# bsd or sysv style echo
TESTECHO=`echo -n`
case "$TESTECHO" in
   -n) N=''; C='\c';;
   *)  N='-n'; C='';;
esac

#getting a tty-style login
case "$mach" in
sun4)
	# delete console entry from inittab and replace with tty-style login
	echo $N "Fixing /etc/inittab...$C"
	driver=`strconf < /dev/console | tail -1`
	if test "$driver" = zs -o "$driver" = se
	then
		echo $N "$driver detected, setting term to vt100...$C"
		term=vt100
	else
		echo $N "term defaulting to sun...$C"
		term=sun
	fi
	sed -e "/^co.*etc.athena.dm/s;.*;co:234:respawn:/usr/lib/saf/ttymon -g -h -p \"\`uname -n\` console login: \" -T $term -d /dev/console -l console -m ldterm,ttcompat;" /etc/inittab > /tmp/inittab
	test -f /etc/inittab.old || mv -f /etc/inittab /etc/inittab.old
	mv -f /tmp/inittab /etc/inittab
	echo done.
	;;
sgi)
	# we don't want to run nanny.  Make the rc script go away.
	echo $N "Disabling nanny...$C"
	rm -f /etc/rc2.d/S98xdm
	# We need to enable using a serial console in the PROM.  Do this with:
	# setenv nogfxkbd 1
	# setenv console d
	# from the PROM, or with:
	# /sbin/nvram nogfxkbd 1
	# /sbin/nvram console d
	# from a root shell.
	echo done.
	;;
esac

echo $N "Creating syslog-files...$C"
case "$mach" in
sun4)
	touch /var/adm/sulog /var/adm/messages /var/spool/mqueue/syslog 
	echo done.
	;;
sgi)
	touch /var/adm/sulog /var/adm/SYSLOG /var/spool/mqueue/syslog
	echo done.
	;;
esac

echo "adduser hesiod nobody"	>> ${CONFCNG}
echo "conf NOCREATE true"	>> ${CONFCNG}
echo "conf RVDCLIENT false"	>> ${CONFCNG}
echo "conf MRUPDATE false"	>> ${CONFCNG}
#echo "conf ERRHALT false"	>> ${CONFCNG}
echo "conf AUTOUPDATE false"	>> ${CONFCNG}
echo "conf SNMP false"		>> ${CONFCNG}
echo "conf SSHD false"		>> ${CONFCNG}
echo "conf SYNCCONFIG false"	>> ${CONFCNG}

echo $N "Editing $INETDIR/inetd.conf...$C"
# the following comments out all entries in /etc/athena/inetd.conf on
# the system, then uncomments out the lines that contain the things listed
# below.  It then changes all occurrences of "switched" to "unswitched".
sed -n	-e '/^[a-z]/s/^/#/' \
	-e '/telnet/s/^#.*$/telnet	stream	tcp	nowait	unswitched	root	\/etc\/athena\/telnetd	telnetd -e -a user/' \
	-e '/eklogin/s/^#.*$/eklogin 	stream	tcp	nowait	unswitched	root	\/usr\/athena\/etc\/klogind	klogind -k -e/' \
	-e '/kshell/s/^#.*$/kshell	stream	tcp	nowait	unswitched	root	\/usr\/athena\/etc\/kshd	kshd -5ec/' \
	-e '/internal/s/^#//' \
	-e '/finger/s/^#//' \
	-e '/write/s/^#//' \
	-e 's/switched/unswitched/' \
	-e 's/unun/un/' \
	-e '/globalmessage/d' \
	-e p /srvd$INETDIR/inetd.conf > /tmp/inetd.conf
test -f $INETDIR/inetd.conf.old || mv -f $INETDIR/inetd.conf \
	$INETDIR/inetd.conf.old

grep globalmessage $INETDIR/inetd.conf.old >> /tmp/inetd.conf
mv -f /tmp/inetd.conf $INETDIR/inetd.conf
echo done.

# we don't want to run any services out of the native inetd.
case "$mach" in
sun4)
	sed -n -e '/^[0-9a-z]/s/^/#/' \
    	        -e p /etc/inet/inetd.conf > /tmp/native-inetd.conf
	test -f /etc/inet/inetd.conf.old || mv -f /etc/inet/inetd.conf \
		/etc/inet/inetd.conf.old
	mv -f /tmp/native-inetd.conf /etc/inet/inetd.conf
	;;
sgi)
	sed -n -e '/^[0-9a-z]/s/^/#/' \
		-e p /etc/inetd.conf > /tmp/native-inetd.conf
	test -f /etc/inetd.conf.old || mv -f /etc/inetd.conf \
		/etc/inetd.conf.old
	mv -f /tmp/native-inetd.conf /etc/inetd.conf
	;;
esac

if [ "$mach" = "sun4" ]; then
	egrep '^knfs|^nfs|^eos|^suninstall|^boot' ${SERVICES} >> /dev/null
	if [ $? != 0 ]; then
		# we're not an NFS server; disable rpcbind
		rm -f /etc/rc2.d/S71rpc
		sh /etc/init.d/rpc stop
	else
		# if the link already exists this should just fail
		# there's no reason to nuke the link first, on the off chance
		# someone repointed it.
		ln -s /etc/init.d/rpc /etc/rc2.d/S71rpc
	fi
	echo "Configuring zephyring syslogd..."
	sed -e  's;/usr/sbin/syslogd;/etc/athena/syslogd;g'     \
	    /etc/init.d/syslog   >  /tmp/syslog
	test -f /etc/init.d/syslog.old || \
	    mv -f /etc/init.d/syslog /etc/init.d/syslog.old
	mv -f /tmp/syslog /etc/init.d/syslog
fi

# don't allow root logins via ssh with the root password
(grep "^PermitRootLogin nopwd$" /etc/sshd_config >> /dev/null || \
	echo "PermitRootLogin nopwd" >> /etc/sshd_config )

if [ "$mach" = "sun4" ]; then
	ln -s /usr/lib/fs/ufs/ufsdump /etc/dump
fi

#enable savecore
case "$mach" in
sun4)
	echo $N "Enabling savecore...$C"
	patch -N /etc/init.d/sysetup << 'EOF'
*** /os/etc/init.d/sysetup      Wed Jul 16 00:22:09 1997
--- ./sysetup   Sun Feb 14 14:58:22 1999
***************
*** 32,40 ****
  ##
  ## Default is to not do a savecore
  ##
! #if [ ! -d /var/crash/`uname -n` ]
! #then mkdir -m 0700 -p /var/crash/`uname -n`
! #fi
! #                echo 'checking for crash dump...\c '
! #savecore /var/crash/`uname -n`
! #                echo ''
--- 32,40 ----
  ##
  ## Default is to not do a savecore
  ##
! if [ ! -d /var/crash/`uname -n` ]
! then mkdir -m 0700 -p /var/crash/`uname -n`
! fi
!                 echo 'checking for crash dump...\c '
! savecore /var/crash/`uname -n`
!                 echo ''
EOF
	echo done.
	;;
sgi)
	echo $N "Enabling savecore...$C"
	if [ ! -r /etc/rc2.d/S48savecore ]; then
	    ln -s /etc/init.d/savecore /etc/rc2.d/S48savecore
	fi
	echo done.
	;;
esac

if [ "$mach" = "sun4" ]; then
	# load useful programs into nvram
	/usr/sbin/eeprom use-nvramrc\?=true nvramrc='
( $jhawk: nvramrc,v 1.3 1998/06/26 05:21:40 jhawk Exp $ )
: ps
  base @
  decimal
  space ." proc_p" 4 spaces ." pid" 4 spaces ." uid" 2 spaces
  ." command" cr
  " practive" eval l@
  begin
    dup .h                              ( proc_p )
    dup 68 + l@ 4 + l@ 6 .r             ( p_pid->pid_id )
    dup 18 + l@ 4 + l@ 7 .r             ( p_cred -> uid )
    space dup 318 + dup cstrlen 38 min type ( 0x38 chars of command )
    cr
    48 + l@
    dup 0= exit? or                     ( loop or more? exit )
  until drop base !
;
: pid
  " practive" eval l@
  begin
    dup 68 + l@ 4 + l@ 2 pick <>
  while
    48 + l@ dup 0= abort" process not found"
  repeat nip
;
: kill
  9c + dup l@ 100 or swap l!
;
: su
  18 + l@ dup
    4 + 0 swap l!
    c + 0 swap l!
;
'
fi

$SIPBCBIN/comment-out /etc/init.d/inetsvc << _END_INETD_COMMENT_
/usr/sbin/inetd -s
_END_INETD_COMMENT_

$SIPBCBIN/comment-out /etc/init.d/inetsvc << _END_SLEEP_COMMENT_
sleep 5
_END_SLEEP_COMMENT_

# Make sure only root may log in
cp /dev/null /etc/athena/access

exit 0
