#!/bin/sh
set -e

PACKAGE=pylibtiff

VERSION=${VERSION:-$2}
TARFILE=${TARFILE:-$3}

if [ -z ${VERSION}]; then
VERSION=`dpkg-parsechangelog | sed -n -e 's/^Version: \(.*\)-[^-]*$/\1/p'`
fi

if [ -z ${TARFILE}]; then
TARFILE=${PACKAGE}_${VERSION}.orig.tar.xz
fi

FOLDER=pylibtiff-master

mkdir -p ../tarballs
cd ../tarballs
# need to clean up the tarballs dir first because upstream tarball might
# contain a directory with unpredictable name
rm -rf *

wget -q https://github.com/pearu/pylibtiff/archive/master.zip
unzip -q master.zip

# remove convenient copy:
rm -rf ${FOLDER}/libtiff/bitarray-0.3.5-numpy/

tar --owner=root --group=root --mode=a+rX --create --auto-compress --file ${TARFILE} ${FOLDER}

rm -rf ${FOLDER}
