#!/bin/sh
. debian/scripts/vars
[ ! -d upstream/patches ] && exit
mkdir -p $STAMP_DIR/upstream/patches/ $SOURCE_TREE
for f in `find upstream/patches -type f|sort`;do
	stampfile=$STAMP_DIR/upstream/patches/`basename $f`
	if [ ! -e $stampfile ];then
		echo -n "Applying upstream patch $f"
		case "$f" in
			*.gz)         cmd=zcat;;
			*.bz)         cmd=bzcat;;
			*.bz2)        cmd=bz2cat;;
			*)            cmd=cat;;
		esac
		if $cmd $f | (cd $SOURCE_DIR/$TAR_DIR;patch -p1) > $stampfile.log;then
			echo " successful."
			touch $stampfile
		else
			echo " failed!"
			exit 1
		fi
	else
		echo "upstream patch $f already applied!"
	fi
done

