#! /bin/sh
#
# Build System V binary installation tape.
#
# $Header: :mktape,v 1.4 87/12/14 10:21:56 root Exp $
#
if [ "$TapeList" = "" ] ; then
	TapeList=$ROOT/usr/src/install/Tape*
else
	TapeList=$ROOT/usr/src/install/$TapeList
fi

TapeDevice=${TapeDevice-/dev/nrmt0}
if [ "$ROOT" = "" ] ; then
	echo -n "Do you really want to dump / [y/n](n)? "
	read ans
	case $ans in
		n*|N*|"")
			exit 1
			;;
		*)
			;;
	esac
fi

if [ ! -d $ROOT/usr/src/install ] ; then
	echo "Can't find the directory where the installation script lives."
	exit 1
fi

#
# Now build the tapes.
#
for TapeN in $TapeList ; do
	echo -n "
Insert "`basename $TapeN`" and press return "
	read ans

	#
	# Rewind tape
	#
	mt -f $TapeDevice rew

	echo "Creating "`basename $TapeN`" ... "
	(
		cd $ROOT
		#
		# First file will be the installation script itself.
		#
		echo "	Adding INSTALL script"
		(cd usr/src/install/`basename $TapeN` ; tar cf $TapeDevice INSTALL)

		if [ -f $TapeN/pre_tar ] ; then
			sh $TapeN/pre_tar $ROOT
		fi
		for FileList in $TapeN/ListOfFile* ; do
			echo "	Taring contents of "`echo $FileList | sed -n -e 's;.*/\(.*\);\1;p'`
			tar cf $TapeDevice `cat $FileList`
		done
		if [ -f $TapeN/post_tar ] ; then
			sh $TapeN/post_tar $ROOT
		fi
		mt -f $TapeDevice rew
		mt -f $TapeDevice status > /dev/null 2>&1
	)
	echo "	Complete."
done
