#!/bin/sh
# script to download and repack source package of mothur because it is provided as zip

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

UPSTREAMNAME=Mothur

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

UPSTREAMDIR="${PKG}-${VERSION}"
unzip -q ../${UPSTREAMNAME}.${VERSION}.zip
mv Mothur.source ${UPSTREAMDIR}

find ${UPSTREAMDIR} -name ".*"  | xargs rm -f
find ${UPSTREAMDIR} -name "*.o" | xargs rm -f

XZ_OPT="-6v" tar --owner=root --group=root --mode=a+rX -caf "$PKG"_"$VERSION".orig.tar.xz "${UPSTREAMDIR}"
rm -rf "${UPSTREAMDIR}" __MACOSX
