#!/bin/sh
# Generate and upload backports for Ubuntu PPA
# Author: Martin Pitt <mpitt@debian.org>

set -e

if [ -n "`bzr modified`" ]; then
    echo "Modified files, aborting" >&2
    exit 1
fi

RELEASES='lucid maverick natty'

CUR_VERSION=`dpkg-parsechangelog | grep ^Version | cut -f2 -d' '`
SINCE_VERSION=`dpkg-parsechangelog -n2 | grep urgency=| tail -n1 | awk '{print $2}' | tr -d '()'`


export DEBEMAIL=martin.pitt@ubuntu.com

for release in $RELEASES; do
    dch -D$release -v"$CUR_VERSION~$release" -b 'Backport'
    bzr bd -S -- -v$SINCE_VERSION
    bzr revert --no-backup debian/changelog
    dput ppa:pitti/postgresql ../postgresql-common_$CUR_VERSION~${release}_source.changes
done
