#!/bin/bash -e

export DIST=dapper
export DIR=`pwd | sed 's!.*/!!g'`
export PACKAGE=`head -n1 debian/changelog | sed 's/^\([^ ]*\).*/\1/g'`
export VERSION=`head -n1 debian/changelog | sed 's/.*(\(.*\)).*/\1/g'`
export UPSTREAM=`echo -n "$VERSION" | sed 's/-[^-]*$//g'`
export DEBIAN=`echo -n "$VERSION" | sed 's/^.*-\([^-]*\)$/\1/g'`
export UBUNTU=$UPSTREAM-$(($DEBIAN-1))ubuntu1
rm -rf ../tmp/
mkdir ../tmp/
cd ..
cp -r $DIR "$PACKAGE"_"$VERSION"* "$PACKAGE"_"$UPSTREAM".orig.tar.gz tmp/
cd tmp/$DIR
dch -b -D $DIST -v $UBUNTU "Upload to Ubuntu $DIST"
debuild -S -sa
debsign -S
debrelease -S -t revu
cd ../..
rm -rf tmp
cd $DIR
