#! /bin/sh

goal="test existing archive with plain files"
bru=${BRU:-bru}
compress=${COMPRESS:-compress}

# Parse our args.  Options include:
#
#	-s	Print our one line test goal and quit
#

while true
do
	case $1 in
		-d)	dflag="on"
			shift
			;;
		-g)	echo $goal
			exit 0
			;;
		*bru*)	bru=$1
			shift
			;;
		*)	break
			;;
	esac
done

if [ "$dflag" != "on" ]
then
	trap "rm -rf emptyfile smallfile biggerfile junk.bru files.bru ; exit 1" 1 2 13 15
fi

# First clean up any stuff that may be left from a previous test.

rm -rf emptyfile smallfile biggerfile junk.bru files.bru

# Begin running tests

echo "Do not be disturbed by the strange permissions, uid, gid, and"
echo "dates on the archived files.  They have deliberately been manipulated"
echo "to test ranges.  For example, emptyfile has been touched to be"
echo "Jan 1, 1970 GMT and smallfile has been touched to be Jan 1, 2000 GMT."
echo "The permissions test all combinations {---, --x, -w-, ..., rwx}."
echo ""

# Note that we have to ensure that TZ is GMT for the duration, to get
# the right dates.

TZ=GMT ; export TZ

echo "Decompressing the reference archive..."
echo ""

$compress -d <files.bru.Z >files.bru

echo "Check that a listing of the contents is correct."

echo ""
$bru -tvf files.bru
echo ""

echo "Check that we can extract the files without problems."

echo ""
$bru -xvf files.bru
echo ""

echo "Check that we can rearchive them again."

echo ""
$bru -cvf junk.bru emptyfile smallfile biggerfile
echo ""

echo "Check that the dates, permissions, etc are still ok."

echo ""
$bru -tvf junk.bru
echo ""

# Now do any cleanup required

if [ "$dflag" != "on" ]
then
	rm -rf emptyfile smallfile biggerfile junk.bru files.bru
fi

exit 0
