# The variables AORB, DEV, HOW, and MEDIA
# get passed from the script iload.

echo "\nInsert CORE ${MEDIA} 1 in drive ${AORB}.  Type <cr> to continue: \c"
read ANS
if [ "$ANS" = "q" -o "$ANS" = quit ]; then
	exit 1
fi
if [ "$DEV" = "/dev/rmt/0m" ]; then
	cd /install
	/opus/bin/tape rew > /dev/null 2>&1
	if [ "${HOW}" = "force" ]; then
		cpio -cimdvBuC512000 < /dev/rmt/${AORB}m
	else
		cpio -cimdBvC512000 < /dev/rmt/${AORB}m
	fi
	RTN=$?
else
	DISKNO=1
	ANS=y
	while [ "$ANS" != q -a "$ANS" != Q ] ; do
		mount -r "${DEV}" /mnt > /dev/null 2>&1
		if [ -r "/mnt/install/ORDER" ] ; then
	    	mounted="TRUE"
	    	if [ "`grep '^' /mnt/install/ORDER`" != "${DISKNO}" ] ; then
				echo "\nDiskette out of sequence, please insert diskette ${DISKNO} in drive${AORB}"
				echo "\tfollowed by <cr> to continue (or type 'q' to quit): \c"
				read ANS
				if [ "x${ANS}" != "x!" ] ; then
					umount "${DEV}"
					continue
				fi
		   	fi
			cd /mnt
			find . -print | cpio -pdum /install
		else
		    umount "${DEV}" > /dev/null 2>&1
		    mounted="FALSE"
			cd /install
		    if [ "${HOW}" = "force" ]; then
				cpio -icvdumB < ${DEV}
		    else
				cpio -icvdmB < ${DEV}
		    fi
		fi
		RTN=$?
		cd /install/install
		if [ -s "CO.setup" ]; then
			# '$ROOT' in the setup script for the CORE 
			# diskettes should be set to '/install'
			# when run during initial installation.
			ROOT=/install; export ROOT
			sh CO.setup
		fi
		sync
		if [ -r "/install/install/LAST" ]; then
			if [ "`grep '^' /install/install/LAST`" = "${DISKNO}" ]; then
				rm -f /install/install/*
				break
			fi
		fi
		cd /
		if [ "${mounted}" = "TRUE" ] ; then
			umount "${DEV}"
		fi
		DISKNO=`expr ${DISKNO} + 1`
		echo "\nInsert CORE ${MEDIA} ${DISKNO} in drive ${AORB}.  Type <cr> to continue: \c"
		read ANS
	done
fi
if [ "${RTN}" -eq 0 ] ; then
	echo "\nLoad complete."
else
	echo "\nERROR LOADING $MEDIA;\c"
	echo " please see Opus User Manual."
	echo "\tType <cr> to continue: \c";
	line
	exit 1;
fi
exit 0
