#!/bin/sh
# Find purged files from the website and the reason they were purged

LOCATION=/home/org/cvs.debian.org/cvs/webwml/webwml
ORIGLANG=english
CHECKLANG=spanish                # Default language to check
[ -n "$1" ] && CHECKLANG=$1      # Can be overrided in the command line


if [ ! -d $LOCATION/$CHECKLANG ] ; then
	echo "ERROR: $LOCATION/$CHECKLANG does not exist or is not a directory"
	exit 1
fi

find  $LOCATION/$CHECKLANG -type f  |
grep Attic  |
grep -v transignore |
while read file 
do
	origfile=`echo $file | sed -e "s/$CHECKLANG/$ORIGLANG/" | sed -e 's/Attic\///'`
	if [ -e "$origfile" ] ; then
		name=`echo "$file" | sed -e "s|$LOCATION||;s|Attic/||"`
		echo -n $name
		date=`stat -c %z "$file" | cut -c 1-11`
		echo " removed $date"
		reason=`cat "$file" | perl -ne 'if ( $log == 1 && /^@/ ) { print; $log=2;}; $log=1 if /^log/ && $log != 2 ;'`
		echo -e "\t$reason"
# TODO: extract file to determine its revision
	fi
done

exit 0
