#!/bin/sh

# They didn't want sample data
if test -z "__MVC_SAMPDATATYPE__" -o \
	Xnone = "X`echo '__MVC_SAMPDATATYPE__' | tr A-Z a-z`"
then
	exit
fi

if test "x__MVC_PERMTYPE__" = x -o "x__MVC_PERMTYPE__" = xM -o "x__MVC_PERMTYPE__" = xG
then
	DMODE=775
	FMODE=664
else
	DMODE=755
	FMODE=644
fi

# Copy the sample data
catroot="__MVC_RELOCATE____MVC_CATROOT__"
sourcedir=$catroot/templates/sampledata/__MVC_SAMPDATATYPE__
if test -d $sourcedir
then
	returndir="`pwd`" || exit 1
	cd $sourcedir
	if test -d $sourcedir/images
	then
		cd $sourcedir/images || exit 1
		find . -type d -exec chmod $DMODE \{\} \;
		find . -type f -exec chmod $FMODE \{\} \;
		tar cf - . | (cd __MVC_RELOCATE____MVC_IMAGEDIR__ && tar xf -)
		cd .. || exit 1
	fi
	find . -print | grep -v '^\.\(/images\|$\)' | xargs tar cf - \
		| (cd $catroot && tar xf -)
	cd $returndir
else 
	echo "Sample data directory does not exist:"
	echo ""
	echo "    $sourcedir"
	echo ""
	exit 1
fi
