#!/bin/sh
#	$Id: sipbserv84.add,v 1.4 2000/12/29 01:08:26 mhpower Exp $
#	$Revision: 1.4 $
#	$Platforms: sun4,sgi$

mach=`/bin/athena/machtype`
INETDIR=/etc/athena

# 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 SAVECORE true"	>> ${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 occurances of "switched" to "unswitched".

sed -n	-e '/^[a-z]/s/^/#/' \
	-e '/klogin/s/^#//' \
	-e '/^klogin/s/klogind$/Klogind/' \
	-e '/kshell/s/^#//' \
	-e '/rkinit/s/^#//' \
	-e '/internal/s/^#//' \
	-e '/finger/s/^#//' \
	-e '/write/s/^#//' \
	-e '/athinfo/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 shoudl just fail
		# thre'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
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

if [ "$mach" = "sun4" ]; then
	# load useful programs into nvram
	/usr/sbin/eeprom use-nvramrc\?=true nvramrc='
( $jhawk: nvramrc,v 1.4 2000/09/29 04:14:38 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 64 + l@ 4 + l@ 6 .r             ( p_pid->pid_id )
    dup 14 + l@ 4 + l@ 7 .r             ( p_cred -> uid )
    space dup 2f8 + dup cstrlen 38 min type ( 0x38 chars of command )
    cr
    44 + l@
    dup 0= exit? or                     ( loop or more? exit )
  until drop base !
;
: pid
  " practive" eval l@
  begin
    dup 64 + l@ 4 + l@ 2 pick <>
  while
    44 + l@ dup 0= abort" process not found"
  repeat nip
;
: kill
  98 + dup l@ 100 or swap l!
;
: su
  14 + l@ dup
    4 + 0 swap l!
    c + 0 swap l!
;
'
fi

exit 0
