echo Downloading latest from cvs repository...
set -e

DEB_SOURCE_PACKAGE=`egrep '^Source: ' debian/control | cut -f 2 -d ' '`
VERSION_UPSTREAM=`dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2 | cut -d- -f1 | sed -r 's/(.*)\+cvs.*/\1/'`
VERSION_DATE=`/bin/date --utc +%0Y%0m%0d`
VERSION_FULL="${VERSION_UPSTREAM}+cvs${VERSION_DATE}"

cvs -z3 -d:pserver:anonymous@xineliboutput.cvs.sourceforge.net:/cvsroot/xineliboutput export -DNOW -d ${DEB_SOURCE_PACKAGE} vdr-xineliboutput

tar cvfz "../${DEB_SOURCE_PACKAGE}_$VERSION_FULL.orig.tar.gz" ${DEB_SOURCE_PACKAGE}

dch -v "$VERSION_FULL-1" "New Upstream Snapshot"

rm -rf ${DEB_SOURCE_PACKAGE}
