#	@(#)bnu:INSTALL	1.14
#	installation procedure for Basic Networking Utilities Package
#
#	Command packages are shipped on a file system '/install'.
#	Below that point are the following directories and files:
#	/install/install/		contains the installation procedure
#	/install/install/INSTALL	actually installs the commands
#	/install/install/packagename	(optional) package identification
#	/install/install/preinstall	(optional) actions performed before
#					files are copied.
#	/install/install/postinstall	(optional) actions performed after
#					files are copied.
#	/install/install/update.xxx	perform updates to system file xxx
#	/install/new			the "root" of the files to be installed
#	/install/new/root		top of files going to / file system


INSPATH=/install/new
PKGNAME=`cat ${INSPATH}/usr/options/uucp.name`
LAST=2

#
#	find mount device
#
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}"

#	check that USRENV is already installed
if [ ! -s /usr/options/usrenv.name ]
then
	echo "
**ERROR** The ${PKGNAME} package cannot be installed --
	  It requires the User Environment Utilities (USRENV)
	  package to be installed first."
	exit
fi

echo "Installing the ${PKGNAME}."
echo "Copyright (c) 1984 AT&T"
echo "All Rights Reserved"

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 that this floppy belongs to the package
	#

	while	[ ! -s ${INSPATH}/usr/options/uucp.name -o "${PKGNAME}" != "`cat ${INSPATH}/usr/options/uucp.name`" ]
	do
		echo "**ERROR**	Floppy does not belong to the ${PKGNAME}"
		cd /
		/etc/umount $mntdev 2>/dev/null
		echo "Remove floppy and insert correct floppy"
		echo "Type <return> when ready: \c"
		read answer
		/etc/mount $mntdev $mntname -r 2>/dev/null
	done

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

	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 \c"
			echo "'n' to try another floppy: \c"
			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
			answer=""
			/etc/mount $mntdev $mntname -r 2>/dev/null
			;;
		y)	expect=`cat /install/install/ORDER`
			;;
		esac
	done

	#
	# Verify that there is space for the Basic Networking Utilities Package.
	#
	
	#	with 2 floppies, 1st floppy must check that have
	#	space enough for both. must use hardcoded #'s, since
	#	2nd floppy isn't available for "du".
	#	THESE #'s MUST BE UPDATED WHEN BNU CODE CHANGES!!!!
	USRneeds=1987
	ROOTneeds=1
	
	
	USRspace=`expr "\`df /usr 2>/dev/null\`" : '.*: *\([0-9]*\)'`
	ROOTspace=`expr "\`df / 2>/dev/null\`" : '.*: *\([0-9]*\)'`
	
	
	if
		[ "$USRspace" -lt "$USRneeds" ]
	then
		echo "**ERROR**   ${PKGNAME} cannot be installed --"
		echo "Not enough space on the hard disk."
		echo "There are $USRspace blocks available"
		echo "on the /usr file system --"
		echo "$USRneeds blocks are needed."
		exit
	elif
		[ "$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
	
	#	Do special work before files are copied in.
	if [ "$expect" -eq 1 -a -f /install/install/preinstall ]
	then
		/bin/sh /install/install/preinstall
	fi
	
	cd ${INSPATH}
	
	echo "The following files are being installed:"
	find . -print | cpio -pduvm /

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

#	Do special work after files are copied in.
cd /install/install
if [ -f postinstall ]
then
	. ./postinstall
fi


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