#! /bin/sh
# Install script for System V.
#

#
# Set up some defaults
#
InstallTime="15 minutes"
FreeBlocks=19000
CreateDir=false
TapeDevice=${Tape-/dev/nrmt0}
if [ "$Install" = "" ] ; then
	InstallDir=`pwd`
fi

#
# Do sanity checking asking the user for information.
#
# Get the correct installation directory.
#
if [ $# -gt 1 ] ; then
	echo "$0 takes only one argument.
Usage: $0 install_directory"
	exit 1
fi
if [ $# -eq 1 ] ; then
	if [ ! -d $1 ] ; then
		echo "$i does not exist."
		echo -n "Would you like me to create it [y/n](y)? "
		read ans
		case $ans in
			y*|Y*|"")
				CreateDir=true
				InstallDir=$1
				;;
			*)
				echo "
Please restart this script whenever you're ready."
				exit 1
				;;
		esac
	else
		InstallDir=$1
		CreateDir=false
	fi
else
	echo "The installation directory will be
	$InstallDir"
	echo -n "Is this ok [y/n](y)? "
	read ans
	case $ans in
		y*|Y*|"")
			CreateDir=false
			;;
		*)
			echo "
Please restart this script whenever you're ready."
			exit 1
			;;
	esac
fi
#
# Make sure that we have the correct tape
#
echo "The following is the tape device selected.
	$TapeDevice"
echo -n "Is this ok [y/n/q](y)? "
read ans
case $ans in
	y*|Y*|"")
		;;

	n*|N*)
		while
			echo "Please enter the path to your tape device.
It must be a non-rewinding device."
			echo -n "= "
			read TapeDevice
		do
			if [ -f $TapeDevice ] ; then
				break
			fi
			echo "$TapeDevice does not exist."
			echo "Please enter a valid path name."
		done
		;;

	*)
		echo "
Please restart this script whenever you're ready."
		exit 1
		;;
esac

df
echo "You'll need approximately $FreeBlocks blocks available on the file
system that $InstallDir resides."
echo -n "Do you have enough room [y/n](y)? "
read ans
case $ans in
	y*|Y*|"")
		;;
	*)
		echo "
Please restart this script whenever you're ready."
		exit 1
		;;
esac


echo "Get a cup of coffee or a coke.  This installation will take about $InstallTime
to complete."

#
# Move the tape over the first file which is the installation script.
#
mt -f $TapeDevice fsf 1


if [ "$CreateDir" = "true" ] ; then
	mkdir $InstallDir
	if [ $? -ne 0 ] ; then
		echo "mkdir of $InstallDir failed!"
		exit 1
	fi
fi

cd $InstallDir
tar xf $TapeDevice

echo "Extraction of System V sources complete."

#
# Rewind tape.
#
echo -n "Rewinding tape ... "
mt -f $TapeDevice rew > /dev/null 2>&1
mt -f $TapeDevice status > /dev/null 2>&1
echo "Done."

echo "
The installation is now complete."
exit 0
