
#
# Save mount point of floppy (INSPATH), package name (PKGNAME) and
# information for the mount & umount commands (mntdev & mntname).
#

INSPATH=/install
GROUP=AS
PKGNAME=`cat ${INSPATH}/usr/options/${GROUP}.name`
LAST=2
if
	test -b "$1"
then
	mntdev=$1
elif
	test -b /dev/diskette
then
	mntdev=/dev/diskette
elif
	test -b /dev/install
then
	mntdev=/dev/install
else
	echo "**ERROR**  Can't find mount device"
	exit
fi
mntname=${2:-/install}

echo "Installing the ${PKGNAME}."

#
# Check that the necessary packages have already been installed.
#


	eflag=0
	if
		test ! -s /usr/options/AU.name
	then
		echo "**ERROR**  The Administered Systems Utilities cannot be installed --"
		echo "It requires the Advanced Utilities to be installed first."
		eflag=1
	fi
	
	if
		[ $eflag -eq 1 ]
	then
		exit
	fi

# Do any pre-installation work.
if [ -f /install/install/preinstall ]; then
	/install/install/preinstall
	if [ $? -ne 0 ]; then
		exit 255
	fi
fi


#
# Is enough space available to install the package?
#

ROOTneeds=`expr "\`du -s ${INSPATH}\`" : "\([0-9]*\).*"`

#
# How much space is available in the necessary filesystems?
#

ROOTspace=`expr "\`df / 2>/dev/null\`" : '.*: *\([0-9]*\)'`

#
# Now see if the package fits!
# Inform the user and exit immediately, if not.
#

if
	[ "$ROOTspace" -lt "$ROOTneeds" ]  
then
	echo "**ERROR**  ${PKGNAME} cannot be installed --"
	echo "Not enough space on the hard disk."
	echo "There are $ROOTspace blocks available"
	echo "on the / (root) file system --"
	echo "$ROOTneeds blocks are needed."
	exit
fi


#
# Begin loop for multiple floppies
#

expect=1
while
	[ $expect -le $LAST ]
do
	if
		[ $expect -gt 1 ]
	then
		cd /
		/etc/umount $mntdev 2>/dev/null
		echo "Remove floppy and insert floppy number $expect"
		echo "Type <return> when ready:  \c"
		read answer
		/etc/mount $mntdev $mntname -r 2>/dev/null
	fi

	#
	# Check to make sure this is the correct floppy of the set.
	#

	answer=""
	while
		[ `cat /install/install/ORDER` != $expect -a "$answer" != y ]
	do
		echo "**WARNING**   Floppy out of sequence"
		echo "Expecting floppy diskette number $expect"
		while
			[ "$answer" != y -a "$answer" != n ]
		do
			echo "Type 'y' to continue or 'n' to try another floppy:  \c"
			echo ""
			read answer
		done
		case $answer in
			n)	cd /
				/etc/umount $mntdev 2>/dev/null
				echo "Remove floppy and insert correct floppy"
				echo "Type <return> when ready:  \c"
				read answer

				#
				# Reset answer to ""
				# check to make sure that this
				# is now the correct floppy
				#

				answer=""
				/etc/mount $mntdev $mntname -r 2>/dev/null
				;;

			y)	expect=`cat /install/install/ORDER`
				;;
		esac
	done

	echo "The following files are being installed:"
	# Do not cpio in 032 files on 332 release & vice versa.
	# After 032/332 specific files are installed, eliminate the
	#  file extension.
	if [ -f /bin/ns32332 ]; then
		/bin/ns32332
		NS332=$?
	else
		NS332=1
	fi
	if [ -f /bin/ns32000 ]; then
		/bin/ns32000
		NS032=$?
	else
		NS032=1
	fi
	if [ $NS332 -eq 0 ]; then
		cd ${INSPATH}
		find . -print | sed "/^\.\/install/d
				/\.032$/d" | tee /tmp/list | cpio -pdumv /
		LIST=`grep '.332$' /tmp/list`
		for i in $LIST
		do
			j=`echo $i | sed 's/\.332$//'`
			mv /$i /$j
		done
		rm -f /tmp/list
	elif [ $NS032 -eq 0 ]; then
		cd ${INSPATH}
		find . -print | sed "/^\.\/install/d
				/\.332$/d" | tee /tmp/list | cpio -pdumv /
		LIST=`grep '.032$' /tmp/list`
		for i in $LIST
		do
			j=`echo $i | sed 's/\.032$//'`
			mv /$i /$j
		done
		rm -f /tmp/list
	else
		cd ${INSPATH}
		find . -print | sed "/^\.\/install/d" | cpio -pdumv /
	fi

	#
	# Increment number for next expected floppy.
	#

	echo "Floppy diskette number $expect is complete"
	expect=`expr $expect + 1`
done

#
# Invoke setup file
#

if [ -f /install/install/setup ]; then
	/install/install/setup
fi

#
# Give user closing message
#

echo "Installation of the ${PKGNAME} is complete."
exit

