:
#	@(#) xinstall.sh 23.2 91/08/29 
#
#	Copyright (C) 1986-1991 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
#	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
