#!/bin/sh
#	$Id: sipbserv90.add,v 1.3 2002/04/14 06:14:52 kolya Exp $
#	$Revision: 1.3 $
#	$Platforms: sun4,sgi,linux$

ops=/afs/athena.mit.edu/astaff/project/ops
mach=`/bin/athena/machtype`
INETDIR=/etc/athena

# Linux doesn't have an srvd
if [ "$mach" != linux ]; then
    srvd=/srvd
else
    srvd=''
fi

# 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)
	/sbin/chkconfig windowsystem off
	/sbin/chkconfig xdm off
	sed -e "/^tp/s/:off:/:respawn:/" /os/etc/inittab > /tmp/inittab
	test -f /etc/inittab.old || mv -f /etc/inittab /etc/inittab.old
	mv -f /tmp/inittab /etc/inittab
	# 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.
	;;
linux)
	sed -e "/:initdefault:/s/5/3/" \
	    -e "/sbin\/getty/s/^#//" \
	    -e "/Type CTRL-ALT-F7 to log in/s/^/#/" /etc/inittab > /tmp/inittab
	test -f /etc/inittab.old || mv -f /etc/inittab /etc/inittab.old
	mv -f /tmp/inittab /etc/inittab
	echo "# Run a getty on /dev/ttyS0" >> /etc/inittab
	echo "S0:12345:respawn:/sbin/uugetty ttyS0 DT38400 vt220" >> \
	    /etc/inittab
	(grep serial /etc/lilo.conf) 2>&1 >/dev/null
	if [ $? != 0 ]; then
	    (echo 'serial=0,38400n8' ; cat /etc/lilo.conf) > /tmp/lilo.conf
	    echo '        append="console=ttyS0,38400"' >> \
		/tmp/lilo.conf
	    test -f /etc/lilo.conf.old || mv -f /etc/lilo.conf \
		/etc/lilo.conf.old
	    mv -f /tmp/lilo.conf /etc/lilo.conf
	    echo ttyS0 >> /etc/securetty
	    /sbin/lilo
	fi
	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.
	;;
linux)
	touch /var/log/messages /var/log/maillog /var/log/secure
	echo done.
	;;
esac

echo "adduser hesiod nobody"	>> ${CONFCNG}
echo "conf NOCREATE true"	>> ${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}

# RVDCLIENT and SAVECORE don't exist on Linux.
if [ "$mach" != linux ]; then
    echo "conf RVDCLIENT false"	>> ${CONFCNG}
    echo "conf SAVECORE true"   >> ${CONFCNG}
fi

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 '/kshell/s/ -e$//' \
	-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
	;;
linux)
	# fingerd runs out of the vendor inetd on Linux, and we still
	# want to run that.
	sed -n -e '/^[0-9a-z]/s/^/#/' \
	       -e '/^#finger/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 )

echo done.

case "$mach" in
sun4)
	ln -s /usr/lib/fs/ufs/ufsdump /etc/dump
	;;
linux)
	ln -s /sbin/dump /etc/dump
	;;
esac

if [ "$mach" = "sun4" ]; then
	# load useful programs into nvram
	ln -s sun4u /usr/platform/SUNW,Sun-Fire-280R
	/usr/sbin/eeprom use-nvramrc\?=true nvramrc='
( prom-ps for 32- and 64-bit Solaris 8 )
: v7?
  " kernelheap" eval w@
;
: v9v7
  v7? if swap then drop
;
: p@
  v7? if " l@" else " x@" then eval
;
: ps
  base @
  decimal
  space ." proc_p" 6 spaces ." pid" 4 spaces ." uid" 2 spaces
  ." command" cr
  " practive" eval p@
  begin
    dup .h                              ( proc_p )
    dup b0 64 v9v7 + p@ 4 + l@ 6 .r     ( p_pid->pid_id )
    dup 20 14 v9v7 + p@ 4 + l@ 7 .r     ( p_cred -> uid )
    space dup 4c0 300 v9v7 + dup cstrlen 35 min type ( 0x35 chars of command )
    cr
    70 44 v9v7 + p@                     ( p_next )
    dup 0= exit? or                     ( loop or more? exit )
  until drop base !
;
: pid
  " practive" eval p@
  begin
    dup b0 64 v9v7 + p@ 4 + l@ 2 pick <>
  while
    70 44 v9v7 + p@ dup 0= abort" process not found"
  repeat nip
;
: kill
  108 98 v9v7 + dup l@ 100 or swap l!
;
: su
  20 14 v9v7 + p@ dup
    4 + 0 swap l!
    c + 0 swap l!
;
'
fi

umask 22
if [ "$mach" = "sun4" ]; then
	if [ -r /var/ops/etc/system.local ]; then
		echo $N "adding local additions to /etc/system...$C"
		cp -p /etc/system /etc/system.bak
		cat /var/ops/etc/system.local >> /etc/system
		echo done.
        fi
fi
if [ ! -d /var/ops/bin ]; then
	mkdir -p /var/ops/bin
fi
if [ ! -f /var/ops/bin/gtar ]; then
	cp -p ${ops}/bin/gtar /var/ops/bin/gtar
	chown root /var/ops/bin/gtar
	chgrp 0 /var/ops/bin/gtar
	chmod 755 /var/ops/bin/gtar
fi

if [ ! -f /var/ops/bin/perl ]; then
	echo "Creating /var/ops/bin/perl symlink"
	rm -f /var/ops/bin/perl
	ln -s /usr/athena/bin/perl /var/ops/bin/perl
fi

# comment out local-netscape cron job.
if [ "$mach" = linux ]; then
	crontab=/etc/cron.d/athena
else
	crontab=/var/spool/cron/crontabs/root
fi

ed ${crontab} <<EOF
/^30.*netscape/s/^/#/
/^0.*reactivate/s/^/#/
w
q
EOF

exit 0
