#!/bin/sh
# $Id: config.sh,v 1.2 1999/02/05 18:38:36 ghudson Exp $
# Set up various configuration files

# /tmp/vars inputs:
#	disk		disk device containing NetBSD partition
#	intf		network interface device
#	ifaddr		IP address of network interface
#	ifnetmask	netmask of network interface
#	ifbroadcast	broadcast address of network interface
#	ifmedia		media options for interface
#	ifgateway	gateway address of subnet
#	rootmail	where to forward root mail

. /tmp/vars

echo "running MAKEDEV"
(cd /hd/dev; ./MAKEDEV all)

echo "Finishing etc"
for i in `cat /srvd/usr/athena/lib/update/configfiles`; do
	if [ -f "/srvd/$i" ]; then
		cp -p "/srvd/$i" "/hd/$i"
	fi
done

cp -p /srvd/etc/athena/athinfo.access /etc/athena/athinfo.access

# Copy in /etc/ttys specially. It's a weird file, because its 
# contents are different depending on whether or not X is configured, 
# and we don't want public machines to revert to not running dm.
install -c -m 644 -o root -g wheel /srvd/etc/ttys /hd/etc/ttys

hostname=`/os/usr/sbin/host -i $ifaddr | awk '{a=$3} END {print a}' \
	| tr A-Z a-z`
hostname $hostname

if [ -r /srvd/etc/master.passwd ]; then
	cp -p /srvd/etc/master.passwd /hd/etc/ptmp
else
	cp -p /srvd/etc/master.passwd.fallback /hd/etc/ptmp
fi
pwd_mkdb -p -d /hd /hd/etc/ptmp
cp -p /srvd/etc/group /hd/etc/group

echo "Creating /etc/athena/rc.conf and /etc/athena/version"
sed -e	"s#^HOST=NONAME#HOST=$hostname#" \
    -e	"s#^ADDR=NOADDR#ADDR=$ifaddr#" \
    -e 	"s#^NETDEV=NODEV#NETDEV=$intf#" \
    -e 	"s#^NETMEDIA=NOMEDIA#NETMEDIA=$ifmedia#" \
	< /srvd/etc/athena/rc.conf > /hd/etc/athena/rc.conf
rm -f /hd/.rvdinfo
echo installed on `date` > /hd/etc/athena/version
sed  -e "s/RVD/Workstation/g" < /srvd/.rvdinfo >> /hd/etc/athena/version

echo "athena.mit.edu" > /hd/usr/vice/etc/ThisCell
for i in CellServDB SuidCells; do 
	cp -p /afs/athena/service/$i /hd/usr/vice/etc/
done
echo "Copied afs service files into var/usr/vice/etc"
size=`df -k | grep vice/cache | awk '{print $2}'`
if [ -n "$size" ]; then
	size=`expr $size \* 3 / 4`
else
	size="$u1cachesize"
fi
echo "Making $size kilobyte cache in /usr/vice/cache."
echo "/afs:/usr/vice/cache:${size}" > /hd/usr/vice/etc/cacheinfo


echo "Creating fstab"
cat > /hd/etc/fstab << EOM
/dev/${disk}a	/			ffs	rw	1 1
/dev/${disk}b	none			swap	sw
/dev/${disk}f	/u1			ffs	rw	1 1
/dev/${disk}e	/u1/usr/vice/cache	ffs	rw	1 1
EOM
cat >> /hd/etc/fstab << EOM
procfs	/proc	procfs	rw
kernfs	/kern	kernfs	rw
EOM

echo -n "Setting up root mail forwarding... "
if [ -n "$rootmail" ]; then
	ed -s /hd/etc/aliases << EOS
/root@localhost:/c
root@localhost: $rootmail
.
w
q
EOS
else
	ed -s /hd/etc/aliases << EOS
/root@localhost:/c
# root@localhost:
.
w
q
EOS
fi
echo "done."
chroot /hd newaliases

# Tweak some settings in /etc
# (provides reasonable defaults in case syncconf is not run)
echo "Editing /etc/rc.conf"
if [ -z "$ifmedia" ]; then
	media=""
else
	media="media $ifmedia"
fi
ed -s /hd/etc/rc.conf <<EOF
/rc_configured=NO/c
rc_configured=YES
.
/hostname=""/c
hostname="$hostname"
.
/defaultroute=""/c
defaultroute="$ifgateway"
.
/critical_filesystems=""/c
critical_filesystems="/u1 /u1/usr/vice/cache"
.
/named=/s/=[^ 	]*/=YES/
/xntpd=/s/=[^ 	]*/=YES/
w
q
EOF
netif="inet $ifaddr netmask $ifnetmask broadcast $ifbroadcast $media"
echo "$netif" > /etc/ifconfig.$intf

# Assume East Coast of the US. 
rm -f /hd/etc/localtime
ln -s /usr/share/zoneinfo/US/Eastern /hd/etc/localtime

sync
