#!/bin/bash

set -e

PKG=`dpkg-parsechangelog | awk '/^Source/ { print $2 }'`
VERSION=`uscan --verbose --force-download --no-symlink |
    grep "Newest version on remote site is .* local version is .*" |
    head -n 1 |
    sed "s/Newest version on remote site is \([a-z0-9.]\+\),.*/\1/"`

mkdir -p ../tarballs

cd ../tarballs
#biojava-3.0.4-all.tar.gz
UTAR="biojava-${VERSION}-all.tar.gz"
mv ../${UTAR} .
tar -xzf ${UTAR}

mv bj${VERSION} $PKG-${VERSION}.orig # .orig is requested by Developers Reference 3.4.4 §6.7.8.2

cd $PKG-${VERSION}.orig
	rm -rf target
	rm -rf biojava3*/target

mkdir -p biojava3-forester/src/main/java
cd biojava3-forester/src/main/java
 wget http://www.biojava.org/download/maven/org/forester/0.955/forester-0.955-sources.jar
 jar xf forester-0.955-sources.jar
 find . -name *.class | xargs rm -f
cd ../../../..
cd ..

BZIP2="--best" tar -cjf ${PKG}_${VERSION}.orig.tar.bz2 ${PKG}-${VERSION}.orig
rm -rf ${PKG}-${VERSION}.orig

rm ${UTAR}

