#! /bin/csh

# PREPDIR -- Convert a large distribution file into a directory containing
# the split file and a CHECKSUMS file.
#
# Usage:	prepdir file[.gz|Z] [file[.gz|Z] ...]

while ($1 != "")
	cp ../$1 $1

	# Compress file if not already compressed.
	if ($1:e == "Z" || $1:e == "gz") then
	    set file = $1
	else
	    echo "compress $1"
	    compress -f $1
	    set file = $1.Z
	endif

	# Split the distribution file.
	set dir = $file:r
	mkdir $dir
	echo -n "${file}: "
	cat $file | (cd $dir; bsplit -v -b 512000 -p ${file}.)

	# Make the CHECKSUMS file.
	set olddir = $cwd; cd $dir

	echo ${file}: > CHECKSUMS
	echo "compute the BSD checksums"
	echo "	------ BSD checksums ------" >> CHECKSUMS
	foreach i (*.[0-9][0-9])
	    echo -n "	$i	" >> CHECKSUMS
	    sum $i >> CHECKSUMS
	end

	echo "compute the SYSV checksums"
	echo "	------ SYSV checksums ------" >> CHECKSUMS
	foreach i (*.[0-9][0-9])
	    echo -n "	" >> CHECKSUMS
	    /usr/5bin/sum $i >> CHECKSUMS
	end
	echo "" >> CHECKSUMS

	# Compute the FILES.Z file if we have a tar file.
	echo "compute the FILES.Z file"
	cat *.[0-9][0-9] | zcat | tar -tvf - |& compress > FILES.Z
	if ($status) then
	    rm FILES.Z
	endif

	cd $olddir

	# Advance to next argument.
	rm -f $file
	shift
end
