#!/bin/sh
# Test-Data needs to be fetched separately from Git

set -e

PKG=`dpkg-parsechangelog | awk '/^Source/ { print $2 }'`

if ! echo $@ | grep -q upstream-version ; then
    VERSION=`dpkg-parsechangelog | awk '/^Version:/ { print $2 }' | sed 's/\([0-9\.]\+\)-[0-9]\+$/\1/'`
    uscan --verbose --force-download
else
    VERSION=`echo $@ | sed 's?^.*--upstream-version \([0-9.]\+\).*?\1?'`
    if echo "$VERSION" | grep -q "upstream-version" ; then
	echo "Unable to parse version number"
        exit
    fi
fi

TARDIR="$PKG"-"$VERSION"
cd ..
mkdir -p tarballs
cd tarballs

tar xaf ../PyVCF-${VERSION}.tar.gz
mv PyVCF-${VERSION} ${TARDIR}
find . -name "*.egg-info" -type d | xargs rm -rf
git clone https://github.com/jamescasbon/PyVCF.git
rsync -a --exclude '*.py' PyVCF/vcf/test ${TARDIR}/vcf

GZIP="--best --no-name" tar --owner=root --group=root --mode=a+rX --exclude-vcs -caf "$PKG"_"$VERSION".orig.tar.xz ${TARDIR}
rm -rf ${TARDIR} PyVCF
