#!/bin/bash

set -e

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

VERSION=`dpkg-parsechangelog | awk '/^Version:/ { print $2 }' | sed 's/\([0-9\.]\+\)-[0-9]\+$/\1/'`

cd ..
mkdir -p tarballs
cd tarballs

rm -rf ${PKG}-${VERSION} ; mkdir ${PKG}-${VERSION} ; cd ${PKG}-${VERSION}
svn export http://svncisd.ethz.ch/repos/cisd/jhdf5/tags/release/14.12.x/14.12.1/jhdf5/source
svn export http://svncisd.ethz.ch/repos/cisd/jhdf5/tags/release/14.12.x/14.12.1/jhdf5/sourceTest
cd ..

tar --owner=root --group=root --mode=a+rX --exclude-vcs -caf "$PKG"_"$VERSION".orig.tar.xz "$PKG"-"$VERSION"
rm -rf "$PKG"-"$VERSION"

