#! /usr/bin/sh

set -e

package=optgeo
thisdir=$(pwd)
cd ..
zipfile=$(ls *.zip| sort| tail -1)
subdir=$(echo $zipfile| sed -e 's/\.zip//' -e 's/_/-/')
version=$(echo $zipfile| sed 's/.*_\(.*\)\.zip/\1/')
[ ! -e $subdir ] || rm -rf $subdir
mkdir $subdir
cd $subdir
unzip ../$zipfile > /dev/null 2>&1 || true # important because of "local" names 
cd ..
archive=${package}_$version.orig.tar.xz
echo -n "making ../$archive ... "
[ ! -e $archive ] || rm $archive
tar cJf $archive $subdir
echo "[Done]"
cd $thisdir
gbp import-orig ../$archive --pristine-tar
