#!/bin/sh -e
# Upstream source contains outdated BioJava code and is lacking java source
# files which need to be obtained from CVS

set -x
UNAME=alien_hunter
PKG=`dpkg-parsechangelog | awk '/^Source/ { print $2 }'`
DVERSION=`dpkg-parsechangelog | awk '/^Version/ { print $2 }' | cut -d- -f1`

mkdir -p ../tarballs
cd ../tarballs
wget -q http://www.sanger.ac.uk/Software/analysis/${UNAME}/${UNAME}-${DVERSION}.tar.gz

if [ ! -d alien_hunter -o ! -d alien_hunter/alien_hunter -o ! -f alien_hunter/alien_hunter/ChangepointLeft.java ] ; then
    cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/pathsoft co alien_hunter
fi

tar -xzf ${UNAME}-${DVERSION}.tar.gz
cd ${UNAME}-${DVERSION}
find . -type d -name CVS -exec rm -rf \{\} \;
rm -rf biojava *.class
cp -a ../alien_hunter/alien_hunter/Changepoint*.java .
cd ..

GZIP="--best --no-name" tar -czf "$PKG"_"$DVERSION".orig.tar.gz ${UNAME}-${DVERSION}
rm -rf  ${UNAME}-${DVERSION}
