#!/bin/sh

#
# Run this after installing RedHat 6.0 with "Everything"
# to turn a "vanilla" redhat box into a Media Lab box.
#
# Version 0.1
#   very vismod specific - never actually ran...
#
# "Christopher R. Wren" <cwren@media.mit.edu>
# Lee Campbell <elwin@media.mit.edu>
# Tue Nov 24 14:25:12 EST 1998
#
# Updated for RedHat 6.0
# Josh Weaver <joshw@media.mit.edu>
# Fri Jul 23 01:53:47 EDT 1999

#
#
# YP config files
# 
#

if ( [ ! -f /etc/yp.conf.dist ] ) ; then
cp /etc/yp.conf /etc/yp.conf.dist
fi
cat >> /etc/yp.conf <<EOF
domain necsys-yp.media.mit.edu
ypserver heathrow.media.mit.edu
ypserver hub.media.mit.edu
ypserver syspro.media.mit.edu
EOF

if ( [ ! -f /etc/sysconfig/network.dist ] ) ; then
 cp /etc/sysconfig/network /etc/sysconfig/network.dist
fi
cat >> /etc/sysconfig/network <<EOF
NISDOMAIN="necsys-yp.media.mit.edu"
EOF

if ( [ ! -f /etc/nsswitch.conf.dist ] ) ; then
 cp /etc/nsswitch.conf /etc/nsswitch.conf.dist
fi
cat > /etc/nsswitch.conf <<EOF
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
#	nisplus or nis+		Use NIS+ (NIS version 3)
#	nis or yp		Use NIS (NIS version 2), also called YP
#	dns			Use DNS (Domain Name Service)
#	files			Use the local files
#	[NOTFOUND=return]	Stop searching if not found so far
#
passwd:     files nis
shadow:     files nis
group:      files nis
hosts:      files dns
services:   files nis
networks:   files
protocols:  files
rpc:        files
ethers:     files
netmasks:   files     
bootparams: files
netgroup:   nis
publickey:  [NOTFOUND=return]
automount:  files 
aliases:    files 
EOF

cat >> /etc/passwd <<EOF
+@necsys-group
+@vismod-users
EOF


#
#
# NFS static mounts
#
#

mkdir /mas

if ( [ ! -f /etc/fstab.dist ] ) ; then
cp /etc/fstab /etc/fstab.dist
fi
cat >> /etc/fstab <<EOF
mas-disk:/mas /mas nfs rw,nosuid,rsize=8192,wsize=8192,soft 0 0
EOF

#nfs is setup during install and running during reboot.
mount /mas

#
#
# Config and Start AMD
#
#

if ( [ ! -f /etc/amd.conf.dist ] ) ; then
mv /etc/amd.conf /etc/amd.conf.dist
fi
cat > /tmp/amd.conf <<EOF
/defaults fs:=${autodir}/${rhost}/root/${rfs};opts:=nosuid,nodev,rsize=8192,wsize=8192
*       rhost:=${key};type:=host;rfs:=/
EOF


if ( [ ! -f /etc/rc.d/init.d/amd.dist ] ) ; then
mv /etc/rc.d/init.d/amd /etc/rc.d/init.d/amd.dist
fi
ln -s /mas/etc/rc/i686-unknown-linux-amd /etc/rc.d/init.d/amd 
/etc/rc.d/init.d/amd start

#
#
# Install contrib packages
#
#

## But first erase extraneous howtos - this
## Xfrees up about 190MB (as of redhat 5.2)
rpm -e howto-chinese howto-croatian howto-french howto-german howto-greek
rpm -e howto-indonesian howto-italian howto-japanese howto-korean
rpm -e howto-polish howto-serbian howto-sgml howto-slovenian
rpm -e howto-spanish howto-swedish howto-turkish


rpm -Uiv /net/can/localtmp/redhat/contrib/libc5/i386/xpcd*
#rpm -Uiv /net/can/localtmp/redhat/contrib/noarch/noarch/latex2html-[^m]*
#rpm -Uiv /net/can/localtmp/redhat/contrib/noarch/noarch/latex2html-manual-html*
rpm -Uiv /net/can/localtmp/redhat/contrib/libc5/i386/ctwm-*
rpm -Uiv /net/can/localtmp/redhat/contrib/libc6/i386/mpeg*
rpm -Uiv /net/can/localtmp/redhat/contrib/libc6/i386/blas-*
#rpm -Uiv /net/can/localtmp/redhat/contrib/libc6/i386/zephyr-[0-9]*

#
#
# Install local (crypto) packages
#
#

##look for new ssh and pgp for RH6.
#rpm -Uiv /net/can/localtmp/redhat/ml-local/i386/ssh*
#rpm -Uiv --force /net/can/localtmp/redhat/ml-local/i386/pgp-*

#
#
# Update packages from /net/can/localtmp/redhat/redhat-6.0/updates
#
#

#don't do kernel updates!
rpm -Uiv -F /net/can/localtmp/redhat/redhat-6.0/updates/i386/[^k]*.rpm
rpm -Uiv -F /net/can/localtmp/redhat/redhat-6.0/updates/i386/k[^e]*.rpm

#
#
# Disable services in inetd.conf
#
#

# start ssh before we kill rlogin
/etc/rc.d/init.d/sshd start

if ( [ ! -f /etc/inetd.conf.dist ] ) ; then
mv /etc/inetd.conf /etc/inetd.conf.dist
fi
cat > /tmp/sed.script <<EOF
/ftp/s/^/#/
/gopher/s/^/#/
/telnet/s/^/#/
/shell/s/^/#/
/login/s/^/#/
/talk/s/^/#/
/pop/s/^/#/
/imap/s/^/#/
/time/s/^/#/
/linuxconf/s/^/#/
/swat/s/^/#/
EOF
sed -f /tmp/sed.script < /etc/inetd.conf.dist > /etc/inetd.conf
rm -f /tmp/sed.script
kill -HUP `cat /var/run/inetd.pid`

#
#
# Configure Xntp
#
#

if ( [ ! -f /etc/ntp.conf.dist ] ) ; then
mv /etc/ntp.conf /etc/ntp.conf.dist
fi
cat > /tmp/sed.script <<EOF
/fudge/s/^/#/
/^server/s/^/#/
EOF
sed -f /tmp/sed.script < /etc/ntp.conf.dist > /etc/ntp.conf
rm -f /tmp/sed.script
cat >> /etc/ntp.conf << EOF
server ntp-server1.media.mit.edu version 2
server ntp-server2.media.mit.edu version 2
server ntp-server3.media.mit.edu version 2
EOF

mv /etc/rc.d/rc3.d/K10xntpd /etc/rc.d/rc3.d/S55xntpd 
mv /etc/rc.d/rc5.d/K10xntpd /etc/rc.d/rc5.d/S55xntpd 

# use ntpdate to set the system clock
/usr/sbin/ntpdate ntp-server1.media.mit.edu

# use the system clock to set the hardware clock
/sbin/hwclock --utc --systohc
/sbin/hwclock --utc --show

#
#
# Configure Zephyr
#
#

#JAW# 
 #package not loaded.

#if ( [ ! -f /etc/sysconfig/zephyr.dist ] ) ; then
#mv /etc/sysconfig/zephyr /etc/sysconfig/zephyr.dist
#fi
#cat > /etc/sysconfig/zephyr << EOF
##
## Put the name of your zephyr server here.  If you do not specify one
## it will use your hostname
##
#ZEPHYR_HOST=\`cat /mas/vision/lib/common/zephyr_hosts\`
#EOF

#
#
# Configure ML printing
#
#

rpm -e lpr printtool rhs-printfilters
rpm -i /net/can/localtmp/redhat/contrib/libc6/i386/LPRng-*

if ( [ ! -f /etc/lpd.conf.dist ] ) ; then
cp /etc/lpd.conf /etc/lpd.conf.dist
fi
echo "default_remote_host=printhub" >> /etc/lpd.conf

#
#
# Vismod shortcut
#
#

ln -s /mas/vision /v

#required for login
ln -s /mas/vision/users /u

#
#
# Rc*.d directory mucking
#
#

#JAW# I think this breaks stuff

cd /etc/rc.d
rm -f rc?.d/S*apmd rc?.d/S*named rc?.d/S*sendmail \
      rc?.d/S*smb rc?.d/S*httpd  rc?.d/S*lpd rc?.d/S*nfs \
      rc?.d/S*dhcpd rc?.d/S*innb
cd /root

#
#
# Change default runlevel to 5
#
#

if ( [ ! -f /etc/inittab.dist ] ) ; then
mv /etc/inittab /etc/inittab.dist
fi
cat > /tmp/sed.script <<EOF
/id:3/s/3/5/
EOF
sed -f /tmp/sed.script < /etc/inittab.dist > /etc/inittab
rm -f /tmp/sed.script

#
#
# Random security measures
#
#

#You setup shadow passwords on the install, right?
#pwconv

cat << EOF
you're done!
Many, many user level configs can be found at the bottom of this file:
http://www.media.mit.edu/~tschroed/install-linux.html

you should reboot now!
EOF
