#!/bin/sh
. debian/scripts/vars
if [ ! -e debian/fixpatch ]; then
	exit 0
fi
mkdir -p $STAMP_DIR/upstream/fixpatch upstream
for f in $(find debian/fixpatch -type f | sort); do
	stampfile=$STAMP_DIR/upstream/fixpatch/$(basename $f)
	if [ -e $stampfile ];then
		echo -n "Unfixing upstream patch $f..."
		case "$f" in
			*.gz)         cmd=zcat;;
			*.bz)         cmd=bzcat;;
			*.bz2)        cmd=bz2cat;;
			*)            cmd=cat;;
		esac
		if $cmd $f | (cd upstream;patch -p1 -R ) > $stampfile.log;then
			echo "done."
			rm $stampfile
		else
			echo "failed!"
			exit 1
		fi
	else
		echo "upstream patch fixup $f already reversed!"
	fi
done
