#!/bin/sh
NAME=`dpkg-parsechangelog | awk '/^Source/ { print $2 }'`
MAINVERSION=`dpkg-parsechangelog | awk '/^Version:/ { print $2 }' | sed 's/\([0-9\.]\+\)\.[-0-9]\+$/\1/'`
ZIPFILE=`echo ${NAME} | sed  's/fonts-//'`.zip
if [ ! ../tarballs/$ZIPFILE ] ; then
  cat <<EOT
  You need to point your browser to
     http://www.myfontfree.com/download-franklin-gothic-book-zip37122.htm
  and download the file $ZIPFILE.
  Move this to `pwd`/tarballs and restart this script.
EOT
  exit 1
fi
cd ../tarballs
find . -name "$NAME*" -type d | xargs rm -rf
mkdir $NAME
cd $NAME
unzip ../$ZIPFILE
# see https://stackoverflow.com/questions/5566310/how-to-recursively-find-and-list-the-latest-modified-files-in-a-directory-with-s
VERSION=0.0.`find . -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2 | head -n1 | sed -e 's/ .*//' -e 's/-//g'`
cd ..
mv $NAME $NAME-$VERSION
GZIP="--best --no-name" tar --owner=root --group=root --mode=a+rX -caf "$NAME"_"$VERSION".orig.tar.xz $NAME-$VERSION
rm -rf $NAME-$VERSION
