#!/bin/sh

PERL=$SI_CONFIG_DIR/bin/perl
patches=/opt/install

#
# This system's filesystems are mounted at this point.
# The other filesystems need only be mounted read-only,
# at they are NFS filesystems that are owned by the server.
#
getpaths ()
{
    for f
    do
	echo $f
	dir=`dirname $f`
	case $dir in
	/) ;;
	/*) getpaths $dir;;
	esac
    done
}

echo "Trying to mount /usr, /usr/share and /usr/kvm, $patches"

for mp in `getpaths /usr/kvm /usr/share $patches|sort -u`
do
    if readvfstab $mp
    then
	mountfs ro
    fi
done

echo "mounting ${newroot}/tmp"
/usr/sbin/chroot ${newroot} /usr/sbin/mount -m -F tmpfs swap /tmp

# This item moved to the start of the finish script.
#echo "Switching filesystems to fast"
#$SI_CONFIG_DIR/bin/fastfs -a fast
if [ ! -d ${newroot}${patches} ]
then
    echo Failed to mount patch directory
    echo "Type control-D to continue"
    /sbin/sulogin > /dev/console < /dev/console 2>&1
fi
echo "running patch script"
status=1
if [ -x ${newroot}${patches}/fastpatch ]
then
    echo ""
    echo "WARNING: Using experimental fastpatch program (if you have $PERL)"
    echo "if this fails, we'll fallback to do-patch"
    echo ""
    $PERL ${newroot}${patches}/fastpatch -R ${newroot} \
	`/usr/sbin/chroot ${newroot} ${patches}/do-patch -c -d 2>/dev/null`
    status=$?
    /usr/sbin/chroot ${newroot} ${patches}/fix-modes
fi
[ $status = 0 ] || /usr/sbin/chroot ${newroot} ${patches}/do-patch -n -c
#echo "Switching filesystems to slow"
#$SI_CONFIG_DIR/bin/fastfs -a slow
sync
