#!/bin/sh
# script to download and repack source package of velvet
# this is needed to remove a copy of zlib

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/"`

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

UPSTREAMDIR="${PKG}_${VERSION}"
mv ../${UPSTREAMDIR}.tgz .
tar -xzf ${UPSTREAMDIR}.tgz
rm -rf ${UPSTREAMDIR}/third-party

## Delete useless binaries once we are changing the original tarball anyway
# delete precompiled object files
# rm -f ${UPSTREAMDIR}/obj/*.o
find ${UPSTREAMDIR} -name "*.o" -exec rm -f \{\} \;
# delete .DS_Store files
find ${UPSTREAMDIR} -name .DS_Store -exec rm -f \{\} \;

# remove separate project which is basically a duplication of velvet code
# this should be packaged separately with an up to date version
rm -rf ${UPSTREAMDIR}/contrib/MetaVelvet*

mv ${UPSTREAMDIR} ${UPSTREAMDIR}~nozlibcopy

GZIP="--best --no-name" tar -czf "$PKG"_"$VERSION~nozlibcopy".orig.tar.gz "${UPSTREAMDIR}~nozlibcopy"
rm -rf "${UPSTREAMDIR}~nozlibcopy"

