# Copyright (c) 1995 by the Student Information Processing Board
# 	  of the Massachusetts Institute of Technology
#  
# Permission to use, copy, modify, and distribute this software
# and its documentation for any purpose and without fee is
# hereby granted, provided that the above copyright notice
# appear in all copies and that both that copyright notice and
# this permission notice appear in supporting documentation,
# and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
# used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# M.I.T. and the M.I.T. S.I.P.B. make no representations about
# the suitability of this software for any purpose.  It is
# provided "as is" without express or implied warranty.
#
#	$Id: athena-inst.sh,v 1.32 1996/03/10 20:18:40 ghudson Exp ghudson $
#	$Source: /mit/netbsd/dev/install/server/RCS/athena-inst.sh,v $

# /tmp/vars inputs:
#	kernel		whether this system is adp or other
#	athena_inst	whether to run Athena installation
#	athenarev	Athena version number
#	distsite	distribution site for FTPing tarfiles
#	installdir	installation directory for FTPing tarfiles

. /tmp/vars
. /utils

if [ "$athena_inst" != "yes" ]; then
	exit 0
fi

srvd=/afs/sipb.mit.edu/system/i386_nbsd1/srvd.${athenarev}

echo ""
echo "Athena installation"
echo "-------------------"

cd /mnt
ftp -n $distsite << EOM
user anonymous netbsdinstaller@
cd $installdir
bin
get afs.tar.gz "|/extract afs"
get athena.tar.gz "|/extract athena"
EOM

if [ ! -e /mnt/afs ]; then mkdir /mnt/afs; fi
chmod u+s /mnt/bin/athena/attach

echo -n "Making symlinks... "
if [ ! -L /mnt/srvd ]; then ln -s $srvd /mnt/srvd; fi
if [ ! -L /mnt/usr/athena ]; then ln -s /srvd/usr/athena /mnt/usr/athena; fi
if [ ! -L /mnt/usr/andrew ]; then ln -s /srvd/usr/andrew /mnt/usr/andrew; fi
if [ ! -L /mnt/usr/X11R6 ]; then ln -s /srvd/usr/X11R6 /mnt/usr/X11R6; fi
if [ ! -L /mnt/usr/X11 ]; then ln -s X11R6 /mnt/usr/X11; fi
if [ ! -L /mnt/emul ]; then rm -rf /mnt/emul; ln -s /srvd/emul /mnt/emul; fi
if [ ! -L /mnt/usr/src ]; then
	if [ -d /mnt/usr/src ]; then rmdir /mnt/usr/src; fi
	ln -s /afs/sipb.mit.edu/project/netbsd/release/netbsd-1.1/source/src \
		/mnt/usr/src
fi
echo "done."

echo -n "Adding to /etc/fstab... "
if ! grep -q kernfs /mnt/etc/fstab; then
	mkdir -p -m 755 /mnt/kern /mnt/proc
	cat /usr/distrib/fstab.add >>/mnt/etc/fstab
fi
echo "done."

echo -n "Making PCVT devices... "
if [ ! -e /dev/ttyv6 ]; then
	chroot /mnt sh -c 'cd /dev; sh MAKEDEV ttyv0 ttyv1 ttyv2 ttyv3 ttyv4 \
					       ttyv5 ttyv6 ttyv7 ttyv8'
fi
echo "done."

echo -n "Replacing generic kernel with Athena kernel..."
rm -f /mnt/netbsd
cp /usr/distrib/athena-$kernel /mnt/netbsd
echo "done."

# Make /etc/group.local
if [ ! -e /mnt/etc/group.local ]; then
	echo "Creating /etc/group.local from /etc/group."
	cp /mnt/etc/group /mnt/etc/group.local
fi

echo -n "Changing root's shell to /bin/athena/tcsh... "
chroot /mnt /usr/bin/chsh -s /bin/athena/tcsh root 2> /dev/null
echo "done."

echo -n "Making floppy devices world-readable and world-writable... "
chmod a+rw /mnt/dev/fd* /mnt/dev/rfd*
echo "done."

if [ ! -e /mnt/usr/vice/etc/cacheinfo ]; then
	size=`df -k | grep /mnt/u1/usr/vice/cache | awk '{print $4}'`
	if [ -n "$size" ]; then
		size=`expr $size \* 8 / 10`
	else
		size="$u1cachesize"
	fi
	echo "Making $size kilobyte cache in /usr/vice/cache."
	echo "/afs:/usr/vice/cache:${size}" > /mnt/usr/vice/etc/cacheinfo
fi

echo "Creating /etc/noremote to disallow unauthorized remote logins."
touch /mnt/etc/noremote

sync; sleep 5

echo ""
echo "The Athena installation is now complete."

