#!/bin/sh
set -e
version=$(dpkg-parsechangelog --show-field Version)
tag=$(echo "ubuntu/$version" | tr '~' '_')
dtag="debian/${tag#*/}"
if git tag -l | grep -q "^$dtag$"; then
git tag --delete "$dtag"
fi
if git tag -l | grep -q "^$tag$"; then
curhash=$(git rev-parse HEAD)
taghash=$(git rev-parse $tag)
if [ "$curhash" != "$tag" ]; then
echo "$tag already exists and is different than HEAD"
exit 1
fi
fi
dsc="../out/cloud-init_${version}.dsc"
changes="${dsc%.dsc}_source.changes"
build-package
sbuild-it "$changes"
git tag "$tag"
dput ubuntu "$changes" ||
{ r=$?; git tag --delete "$tag"; exit $r; }
git push upstream HEAD "$tag"