:
#	@(#) xinstall.sh 22.1 90/04/04 
#
#	Copyright (C) The Santa Cruz Operation, 1985.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, Microsoft Corporation
#	and AT&T, and should be treated as Confidential.
#
#
#  Xenix System V installation program 
#

PATH=/bin:/usr/bin:/etc

# Return values for /etc/firsttime or anyone who cares
: ${OK=0} ${FAIL=1} ${STOP=10} ${HALT=11}

# Prompt for yes or no answer - returns non-zero for no
getyn='(while	read yn
	do	case "$yn" in
		[yY])	exit 0 				;;
		[nN])	exit 1				;;
		*)	echo "Please answer y or n" >&2	;;
		esac
	done)'

cd /
umask 0

# If we have a no valid device argument, default to /dev/install 
DEVICE=/dev/install

case $1 in
/dev/*)	if [ -b $1 -o -c $1 ]
	then
		DEVICE=$1
		shift
	else
		echo "$0: invalid device argument $1" >&2
		exit $FAIL
	fi
esac

echo "
For each volume in the distribution set, insert the
floppy into the drive, enter 'y', and press <RETURN>.
Enter the letter 'n' after the last volume.

Should you see the message 'tar: please mount new volume.',
insert the next floppy, and press <RETURN>.\n"

# Remove initialization scripts before we start,
#    and on shell interruption.

[ -x /bin/rm ] && rm -f ./once/init.* ./tmp/init.*
trap 'rm -f ./once/init.* ./tmp/init.*; exit $FAIL' 1 2 3 15

WHICH=First
while	echo "\n$WHICH Floppy? (y/n) \c" >&2
	read x
do	case $x in
	n|N)	case $WHICH in
		First)	echo "\nAborting installation procedure.\n" >&2
			exit $FAIL
			;;
		Next)	break
			;;
		esac
		;;

	y|Y)	echo "Extracting files ..." >&2
		until	tar xf $DEVICE
		do	echo "Extraction error: try again? (y/n) \c" >&2
			eval "$getyn" && continue
			echo "Continue with the installation? (y/n) \c" >&2
			eval "$getyn" && break
			exit $FAIL
		done
		for script in ./once/init.* ./tmp/init.*
		do	[ -x $script ] || continue
			$script
			case $? in
			$OK)	: All is well			;;
			$STOP)	rm -f $script; exit $STOP	;;
			$HALT)	rm -f $script; /etc/haltsys	;;
			$FAIL)	echo "Error: $script failed" >&2;;
			esac
			rm -f $script
		done
		WHICH=Next
		;;

	*)	echo "\nEnter either 'y' or 'n'." >&2
		;;
	esac
done
echo \\n${*:+"$* "}"Installation Complete.\n" >&2
exit $OK
