#!/bin/sh -e
# upstream does not provide versioned tarballs
# since we do repack *.Z compressed tarballs anyway some useless
# files are removed via Files-Excluded in debian/copyright

NAME=fastlink
UPSTREAMTAR="$NAME".tar.Z
MAINVERSION="4.1P"
curdir=`pwd`

mkdir -p ../tarballs
cd ../tarballs

rm -f "$UPSTREAMTAR"
wget https://ftp.ncbi.nih.gov/pub/fastlink/$UPSTREAMTAR
tar -xzf "$UPSTREAMTAR"

PATCHVERSION=`grep -v "^ " fastlink/README.updates | tail -n 1 | sed 's/^\([0-9a-z]\+\)\..*/\1/'`
UPSTREAMVERSION="${MAINVERSION}-fix${PATCHVERSION}+dfsg"
UPSTREAMDIR="${NAME}-${UPSTREAMVERSION}"

mv "$NAME" "$UPSTREAMDIR"
cd $UPSTREAMDIR
mkdir debian
ln -s $curdir/debian/changelog debian/changelog
ln -s $curdir/debian/copyright debian/copyright
mk-origtargz --repack --compress xz --version $UPSTREAMVERSION ../$UPSTREAMTAR

cd ..
rm -rf "$UPSTREAMDIR"
