#!/bin/sh
#	$Id: sipbserv93.add,v 1.1 2004/09/15 23:19:24 arolfe Exp arolfe $
#	$Revision: 1.1 $
#	$Platforms: sun4,sgi,linux$

if [ -d /var/server ]; then
    echo "Creating a 9.4 SIPB server"
else
    echo "/var/server doesn't exist.  Run 'mkserv remote' first"
    exit 1
fi

PATH=${PATH}:/afs/sipb/service/solaris/bin
ops=/afs/athena.mit.edu/astaff/project/ops
mach=`/bin/athena/machtype`
INETDIR=/etc/athena
SERVICES=/etc/services

# 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

	# Configure for alternate BREAK sequence.
	sed -e "/KEYBOARD_ABORT=alternate/s/^#//" /etc/default/kbd > \
	    /tmp/kbd
	test -f /etc/default/kbd.old || mv -f /etc/default/kbd \
	    /etc/default/kbd.old
	mv -f /tmp/kbd /etc/default/kbd

	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.
	;;
linux)
	touch /var/log/messages /var/log/maillog /var/log/secure
	echo done.
	;;
esac

echo $N "Disabling auto-update"
perl -p -i -e 's/AUTOUPDATE=true/AUTOUPDATE=false/' /etc/athena/rc.conf

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 p ${INETDIR}/inetd.conf > /tmp/inetd.conf
test -f $INETDIR/inetd.conf.old || mv -f $INETDIR/inetd.conf \
	$INETDIR/inetd.conf.old

mv -f /tmp/inetd.conf $INETDIR/inetd.conf
echo done.

echo $N "Disabling native inetd..."
# 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
	;;
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

echo "done."

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

# 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.*lockers/s/^/#/
/^0.*reactivate/s/^/#/
w
q
EOF

case "$mach" in
sun4)
	echo "Continuing with old change-config changes."
	;;
linux)
	echo "Done and exiting."
	exit 0
	;;
esac

# USERS
#
echo 'root:x:0:1:0000-Admin(0000):/:/bin/athena/tcsh' > /etc/passwd.tmpg
echo 'daemon:x:1:1:0000-Admin(0000):/:' >> /etc/passwd.tmpg
echo 'bin:x:2:1:0000-Admin(0000):/usr/bin:' >> /etc/passwd.tmpg
echo 'adm:x:4:1:0000-Admin(0000):/var/adm:' >> /etc/passwd.tmpg
echo 'lp:x:71:1:0000-lp(0000):/usr/spool/lp:' >> /etc/passwd.tmpg
echo 'uucp:x:5:1:0000-uucp(0000):/usr/lib/uucp:' >> /etc/passwd.tmpg
echo 'discuss:x:32000:101:Discuss System,,,,:/var/spool/discuss:/dev/null' >> /etc/passwd.tmpg
echo 'nobody:x:60001:60001:uid no body:/:' >> /etc/passwd.tmpg
echo 'noaccess:x:60002:60002:uid no access:/:' >> /etc/passwd.tmpg
mv /etc/passwd.tmpg /etc/passwd
cp /etc/passwd /etc/passwd.local
echo 'root::0:root' > /etc/group.tmpg
echo 'other::1:' >> /etc/group.tmpg
echo 'bin::2:root' >> /etc/group.tmpg
echo 'sys::3:root' >> /etc/group.tmpg
echo 'adm::4:root' >> /etc/group.tmpg
echo 'uucp::5:root' >> /etc/group.tmpg
echo 'mail::6:root' >> /etc/group.tmpg
echo 'tty::7:root' >> /etc/group.tmpg
echo 'lp::8:root' >> /etc/group.tmpg
echo 'nuucp::9:root' >> /etc/group.tmpg
echo 'staff::10:' >> /etc/group.tmpg
echo 'daemon::12:root' >> /etc/group.tmpg
echo 'sysadmin::14:' >> /etc/group.tmpg
echo 'nofiles::93:' >> /etc/group.tmpg
echo 'nobody::60001:' >> /etc/group.tmpg
echo 'noaccess::60002:' >> /etc/group.tmpg
echo 'nogroup::65534:' >> /etc/group.tmpg
mv /etc/group.tmpg /etc/group
cp /etc/group /etc/group.local
# no more sys user
rm -f /var/spool/cron/crontabs/sys

# Unnecessary init scripts
#
cd /etc/rc2.d
mv K07snmpdx k07snmpdx
mv K07dmi k07dmi
mv S20sysetup s20sysetup
mv S40llc2 s40llc2
mv S70uucp s70uucp
mv S72autoinstall s72autoinstall
mv S72dhcp.rename s72dhcp.rename
mv S73cachefs.daemon s73cachefs.daemon
mv S89PRESERVE s80PRESERVE
mv S91athena-sendmail s91athena-sendmail
mv S91athena-inetd s91athena-inetd
cd /etc/rc0.d
mv K33audit k33audit
mv K52llc2 k52llc2
mv K91athena-sendmail k91athena-sendmail
mv K91athena-inetd k91athena-inetd
cd /etc/rc1.d
mv K33audit k33audit
mv K52llc2 k52llc2
cd /etc/rcS.d
mv K33audit k33audit
mv K52llc2 k52llc2

# Unnecessary lines in init scripts and root's crontab
#
comment-out /etc/init.d/athena-ws << '_END_MOTD_COMMENT_'
  echo "Editing /etc/motd... \c"
  awk '{ prev = $0; } END { print prev; }' /etc/athena/version > /tmp/t1
  if [ "$PUBLIC" != true ]; then
    awk '{ if (NR > 1) print $0; }' /etc/motd >> /tmp/t1
  fi
  mv -f /tmp/t1 /etc/motd
  chmod 644 /etc/motd
  echo "done."
_END_MOTD_COMMENT_
#

# newsyslog
#
rm -f /etc/athena/newsyslog.conf
cat > /etc/athena/newsyslog.conf << '_END_NEWSYSLOG_CONF_'
#
# Newsyslog configuration file
# MIT Project Athena
#
# _Id_

/var/adm/lastlog 644 10 8000 * B
/usr/adm/wtmp 644 10 8000 * B
/usr/adm/wtmpx 644 10 8000 * B
/usr/adm/cron/log 644 1 10 * Z
/usr/adm/messages 644 30 1 * Z
/usr/spool/mqueue/syslog 600 10 1 * Z
p/usr/adm/sulog 600 30 1 * Z
_END_NEWSYSLOG_CONF_

sed -n -e '/@WSLOGGER\.MIT\.EDU/s/\*\.warning;kern,user,auth\.notice/kern.notice		/' -e p < /etc/syslog.conf > /var/syslog.conf
mv /var/syslog.conf /etc/syslog.conf
touch /var/adm/messages
chmod 0644 /var/adm/messages

# create /usr/local so it's there if other things need it.
if [ ! -d /usr/local ]; then
  mkdir /var/local
  ln -s /var/local /usr/local
fi
if [ ! -d /usr/local/bin ]; then
  mkdir /usr/local/bin
fi
if [ ! -d /usr/local/sbin ]; then
  mkdir /usr/local/sbin
fi
if [ ! -d /usr/local/man ]; then
  mkdir /usr/local/man
fi
if [ ! -d /usr/local/man/man1 ]; then
  mkdir /usr/local/man/man1
fi

# there is one tab in the line below that begins with "20"
perl -i -p -e 's/(.*clean_tmp_areas.*)/#\1/' /var/spool/cron/crontabs/root

rm -f /var/spool/cron/crontabs/root.old-*

chown root /var/tmp /var/rtmp
# Unnecessary suid/sgid files
chmod 0755 /usr/lib/fs/ufs/quota
chmod 0755 /usr/lib/fs/ufs/ufsdump
chmod 0755 /usr/lib/fs/ufs/ufsrestore
chmod 0755 /usr/bin/at
chmod 0755 /usr/bin/atq
chmod 0755 /usr/bin/atrm
chmod 0755 /usr/bin/crontab
chmod 0755 /usr/bin/eject
chmod 0755 /usr/bin/fdformat
chmod 0755 /usr/bin/login
chmod 0755 /usr/bin/passwd
chmod 0755 /usr/bin/rcp
chmod 0755 /usr/bin/rdist
chmod 0755 /usr/bin/rlogin
chmod 0755 /usr/bin/rsh
chmod 0755 /usr/bin/tip
chmod 0755 /usr/bin/yppasswd
chmod 0755 /usr/bin/chkey
chmod 0755 /usr/bin/nispasswd
chmod 0755 /usr/bin/volcheck
chmod 0755 /usr/bin/volrmmount
chmod 0755 /usr/openwin/bin/xlock
chmod 0755 /usr/openwin/lib/mkcookie
if [ -f /usr/sbin/sparcv7/whodo ]; then
   chmod 0755 /usr/sbin/sparcv7/whodo
fi
if [ -f /usr/sbin/sparcv9/whodo ]; then
   chmod 0755 /usr/sbin/sparcv9/whodo
fi
chmod 0755 /usr/sbin/allocate
chmod 0755 /usr/sbin/mkdevalloc
chmod 0755 /usr/sbin/mkdevmaps
chmod 0755 /usr/sbin/sacadm
chmod 0755 /usr/sbin/ufsdump
chmod 0755 /usr/sbin/traceroute
chmod 0755 /usr/sbin/deallocate
chmod 0755 /usr/sbin/list_devices
chmod 0755 /usr/sbin/afbconfig
chmod 0755 /usr/sbin/ffbconfig
chmod 0755 /usr/sbin/m64config
chmod 0755 /usr/sbin/pmconfig
chmod 0755 /usr/lib/fs/ufs/ufsdump
if [ -f /usr/platform/sun4u/sbin/eeprom ]; then
   chmod 0755 /usr/platform/sun4u/sbin/eeprom
fi
if [ -f /usr/platform/sun4u/sbin/prtdiag ]; then
   chmod 0755 /usr/platform/sun4u/sbin/prtdiag
fi
if [ -f /usr/platform/sun4m/sbin/eeprom ]; then
   chmod 0755 /usr/platform/sun4m/sbin/eeprom
fi
if [ -f /usr/platform/sun4m/sbin/prtdiag ]; then
   chmod 0755 /usr/platform/sun4m/sbin/prtdiag
fi
chmod 0755 /usr/bin/mail
chmod 0755 /usr/bin/mailx
chmod 0755 /usr/bin/passwd
chmod 0755 /usr/bin/write
chmod 0755 /usr/bin/yppasswd
chmod 0755 /usr/bin/nispasswd
if [ -f /usr/openwin/bin/Xsun ]; then
  chmod 0755 /usr/openwin/bin/Xsun
fi
if [ -f /usr/sbin/sparcv7/prtconf ]; then
  chmod 0755 /usr/sbin/sparcv7/prtconf
fi
if [ -f /usr/sbin/sparcv7/swap ]; then
  chmod 0755 /usr/sbin/sparcv7/swap
fi
if [ -f /usr/sbin/sparcv7/sysdef ]; then
  chmod 0755 /usr/sbin/sparcv7/sysdef
fi

if [ -f /usr/sbin/sparcv9/prtconf ]; then
  chmod 0755 /usr/sbin/sparcv9/prtconf
fi
if [ -f /usr/sbin/sparcv9/swap ]; then
  chmod 0755 /usr/sbin/sparcv9/swap
fi
if [ -f /usr/sbin/sparcv9/sysdef ]; then
  chmod 0755 /usr/sbin/sparcv9/sysdef
fi
chmod 0755 /usr/sbin/arp
chmod 0755 /usr/sbin/wall

rm -f /etc/netspy
cat >> /etc/system << _END_ETC_SYSTEM_ 
set noexec_user_stack=1
set noexec_user_stack_log=1
_END_ETC_SYSTEM_

# for /usr/sbin/strerr
#
if [ ! -d /var/adm/streams ]; then
   mkdir /var/adm/streams
fi
chmod 700 /var/adm/streams
# Changes to trusting AFS cells
#
echo '-athena.mit.edu' > /usr/vice/etc/SuidCells.local
echo '-net.mit.edu' >> /usr/vice/etc/SuidCells.local
echo '-sipb.mit.edu' >> /usr/vice/etc/SuidCells.local
echo '-dev.mit.edu' >> /usr/vice/etc/SuidCells.local
echo '-ops.mit.edu' >> /usr/vice/etc/SuidCells.local

echo root > /etc/localusers
echo daemon >> /etc/localusers
echo bin >> /etc/localusers
echo adm >> /etc/localusers
echo lp >> /etc/localusers
echo uucp >> /etc/localusers
echo discuss >> /etc/localusers
echo nobody >> /etc/localusers
echo noaccess >> /etc/localusers

# World-writeable files and directories
chmod 0644 /var/sadm/install/.pkg.lock
chmod 0644 /var/adm/spellhist
chmod 0644 /var/adm/vold.log
if [ -r /var/adm/X0msgs ]; then
   chmod 0644 /var/adm/X0msgs
fi
if [ -r /var/spool/lp/fifos/FIFO ]; then
   chmod 0644 /var/spool/lp/fifos/FIFO
fi
if [ -r /var/dmi/db/1l.comp ]; then
   chmod 0644 /var/dmi/db/1l.comp
fi
if [ -r /var/dmi/db/1l.tbl ]; then
   chmod 0644 /var/dmi/db/1l.tbl
fi
if [ -r /var/snmp/snmpdx.st ]; then
   chmod 0644 /var/snmp/snmpdx.st
fi
if [ -r /var/snmp/snmpdx.st.old ]; then
   chmod 0644 /var/snmp/snmpdx.st.old
fi
#
chmod 0755 /var/mail
chmod 0755 /var/preserve
chmod 0755 /var/spool/pkg
chmod 0755 /var/spool/uucppublic
#
#
if [ -d /var/rtmp/.X11-unix ]; then
  chmod 0755 /var/rtmp/.X11-unix
fi
if [ -d /var/rtmp/.X11-pipe ]; then
  chmod 0755 /var/rtmp/.X11-pipe
fi
if [ -d /var/rtmp/.pcmcia ]; then
  chmod 0755 /var/rtmp/.pcmcia
fi
chmod 0755 /var/mail
chmod 0755 /var/preserve
chmod 0755 /var/spool/pkg
chmod 0755 /var/spool/uucppublic

attach gnu
# Changes to rc.conf
#
/mit/gnu/bin/ggrep --quiet \^SSHD=true /etc/athena/rc.conf
if [ $? -eq 0 ]; then
   sed -n -e 's/^SSHD=true/SSHD=false/' -e p < /etc/athena/rc.conf > /etc/athena/rc.conf.tmp
   mv /etc/athena/rc.conf.tmp /etc/athena/rc.conf
fi
/mit/gnu/bin/ggrep --quiet \^SNMP=true /etc/athena/rc.conf
if [ $? -eq 0 ]; then
   sed -n -e 's/^SNMP=true/SNMP=false/' -e p < /etc/athena/rc.conf > /etc/athena/rc.conf.tmp
   mv /etc/athena/rc.conf.tmp /etc/athena/rc.conf
fi
#
/mit/gnu/bin/ggrep --quiet \^SYNCCONFIG=true /etc/athena/rc.conf
if [ $? -eq 0 ]; then
   sed -n -e 's/^SYNCCONFIG=true/SYNCCONFIG=false/' -e p < /etc/athena/rc.conf > /etc/athena/rc.conf.tmp
   mv /etc/athena/rc.conf.tmp /etc/athena/rc.conf
fi

# init file for ssh and Kerberos logins
#
cat > /etc/init.d/remlogin << '_END_REMLOGIN_INIT_1_'
#!/bin/sh
# /etc/init.d/remlogin - Start/Stop the remote-login daemons
#

HOME=/; export HOME
PATH=/bin; export PATH

umask 022

case "$1" in
'start')
        echo "Starting remote-login daemons."
_END_REMLOGIN_INIT_1_
/usr/bin/echo '       /usr/local/sbin/tcpserver -H -l\c' >> /etc/init.d/remlogin
/usr/bin/echo `/bin/hostname`\\c >> /etc/init.d/remlogin
cat >> /etc/init.d/remlogin << '_END_REMLOGIN_INIT_2_'
 -R -v -c 50 0 eklogin /usr/athena/etc/klogind -k -e 2>&1 | /usr/local/sbin/splogger eklogind 4 &
_END_REMLOGIN_INIT_2_
/usr/bin/echo '       /usr/local/sbin/tcpserver -H -l\c' >> /etc/init.d/remlogin
/usr/bin/echo `/bin/hostname`\\c >> /etc/init.d/remlogin
cat >> /etc/init.d/remlogin << '_END_REMLOGIN_INIT_3_'
 -R -v -c 50 0 kshell /usr/athena/etc/kshd -5ec 2>&1 | /usr/local/sbin/splogger kshd 4 &
_END_REMLOGIN_INIT_3_
/usr/bin/echo '       /usr/local/sbin/tcpserver -H -l\c' >> /etc/init.d/remlogin
/usr/bin/echo `/bin/hostname`\\c >> /etc/init.d/remlogin
cat >> /etc/init.d/remlogin << '_END_REMLOGIN_INIT_4_'
 -R -v -c 50 0 telnet /etc/athena/telnetd -e -a user 2>&1 | /usr/local/sbin/splogger telnetd 4 &
       /etc/athena/sshd &
        ;;
'stop')
        echo "Stopping remote-login daemons."
        kill `/bin/cat /var/athena/sshd.pid`
        ;;
*)
        echo "usage: /etc/init.d/remlogin {start|stop}"
        ;;
esac
exit 0
_END_REMLOGIN_INIT_4_
chmod 755 /etc/init.d/remlogin
ln -s /etc/init.d/remlogin /etc/rc0.d/K94remlogin
ln -s /etc/init.d/remlogin /etc/rc2.d/S94remlogin

# for savecore
mkdir -p /var/crash/`/bin/uname -n`
/usr/sbin/dumpadm -m 15000k -y
chmod -R 0700 /var/crash

sed 's/TCP_STRONG_ISS=1/TCP_STRONG_ISS=2/' < /etc/default/inetinit > /var/inetinit
rm -f /etc/default/inetinit
mv /var/inetinit /etc/default/inetinit
chmod 0644 /etc/default/inetinit

cp /afs/sipb.mit.edu/service/qmail/src/ucspi-tcp-0.88/tcpserver /usr/local/sbin/tcpserver
(cd /afs/sipb.mit.edu/service/qmail/src/netqmail-1.05/netqmail-1.05; make splogger)
cp /afs/sipb.mit.edu/service/qmail/src/netqmail-1.05/netqmail-1.05/splogger /usr/local/sbin/splogger


exit 0
