#!/bin/sh

TWDIR=%%TWDIR%%
WWWDIR=%%WWWDIR%%

case $2 in
	DEINSTALL)
		cd ${TWDIR}/
		find -s * -not -type d | while read file; do
			if [ -e ${WWWDIR}/$file ]; then
				if cmp -s ${WWWDIR}/$file $file; then
					rm -f ${WWWDIR}/$file
				else
					echo "${WWWDIR}/$file changed, skipping"
				fi
			else
				echo "${WWWDIR}/$file lost"
			fi
		done
		find -ds * -type d | while read dir; do
			rmdir ${WWWDIR}/$dir/ 2>/dev/null || true
		done
		rmdir ${WWWDIR}/ 2>/dev/null || true
		rmdir %%PREFIX%%/www 2>/dev/null || true
		;;
	POST-DEINSTALL)
		;;
	*)
		echo "Unexpected Argument $2!"
		exit 1
		;;
esac
exit 0
