#!/bin/sh

PATH=/usr/bin:/bin
export PATH

# For each Manifest.rdf in a subdirectory, drag it in, top and tail it
# and slap it out into the central Manifest.rdf file.

# NOTE: we expect the files to begin and end with manifestHead.rdf and
# manifestTail.rdf; if they don't, things will get truncated!

toplines=`wc -l < skeleton/manifestHead.rdf`
taillines=`wc -l < skeleton/manifestTail.rdf`

echo "Dropping $toplines lines off the top of every manifest, and $taillines lines off the bottom."

(
	cat skeleton/manifestHead.rdf

	for i in */Manifest.rdf
	do
		echo "<!-- $i -->"

		nlines=`wc -l < "$i"`

		sed -n \
			-e `expr $toplines + 1`,`expr $nlines - $taillines`p "$i"

	done

	cat skeleton/manifestTail.rdf
) > Manifest.rdf
