#!/bin/csh -f

echo "Backing up the kernel"

/bin/mv /vmunix /vmunix.6.1.1
/bin/cp /vmunix.6.1.1 /vmunix

echo "Modifying the kernel"
/bin/adb -w /vmunix << EOF
max_nofile?W0x1000
nfile?W0x1200
ngnode?W0x1100
nchsize?W0x12bc
flckinfo?W0x6cc
flckinfo+4?W0x1bc
EOF

echo "Making device"
/usr/local/cmmkdir `/bin/hostname`:/dev
./cmmknod `/bin/hostname`:/dev/rawdisk c 8 0

echo "Installing datavault software"
/bin/mv /usr/local/etc/fsserver /usr/local/etc/fsserver.6.1.1
/bin/mv /usr/local/etc/unfsd /usr/local/etc/unfsd.6.1.1
/bin/mv /usr/local/etc/unfsmntd /usr/local/etc/unfsmntd.6.1.1
/bin/cp ./fsserver /usr/local/etc
/bin/cp ./unfsd ./unfsmntd ./cmmknod /usr/local/etc

echo "Trying to install on the second disk"
echo "Checking Second disk"

fsck -p /dev/ra1g

if ($status) then
    echo "fsck on the second user disk fail!  Aborting..."
    echo "Install incomplete.  Cannot install on the second disk"
    exit 1
endif
echo "mounting and installing it on the second disk"

mount /dev/ra1g /mnt
/bin/cp ./fsserver /mnt/local/etc
/bin/cp ./unfsd ./unfsmntd ./cmmknod /mnt/local/etc
/bin/sync
/etc/umount /mnt


fsck -p /dev/ra1a

if ($status) then
    echo "fsck on the second root disk fail!  Aborting..."
    echo "Install incomplete.  Cannot install on the second disk"
    exit 1
endif
echo "fixing the kernel on the second disk"
mount /dev/ra1a /mnt

/bin/cp /mnt/vmunix /mnt/vmunix.6.1.1

echo "Updating the backup kernel"
/bin/adb -w /mnt/vmunix << EOF
max_nofile?W0x1000
nfile?W0x1200
ngnode?W0x1100
nchsize?W0x12bc
flckinfo?W0x6cc
flckinfo+4?W0x1bc
EOF
sync
umount /mnt

echo "Installation complete, please reboot now"
