#!/bin/sh

DEBSOURCE="$(dpkg-parsechangelog | sed -ne '/^Source:/{s/Source:[[:space:]][[:space:]]*//p;q}')"
DEBVERSION="$(dpkg-parsechangelog | sed -ne '/^Version:/{s/Version:[[:space:]][[:space:]]*//p;q}')"
DEBDIST="$(dpkg-parsechangelog | sed -ne '/^Distribution:/{s/Distribution:[[:space:]][[:space:]]*//p;q}')"
DEBURGENCY="$(dpkg-parsechangelog | sed -ne '/^Urgency:/{s/Urgency:[[:space:]][[:space:]]*//p;q}')"

if [ -z "$DEBSOURCE" ] || [ -z "$DEBVERSION" ] || \
   [ -z "$DEBDIST" ] || [ -z "$DEBURGENCY" ]; then
    echo "Error parsing source, version, distribution and urgency from debian/changelog"
    exit 1
fi

echo "Tagging ${DEBSOURCE}-${DEBVERSION} (dist=${DEBDIST}, urgency=${DEBURGENCY}) as 'debian/${DEBSOURCE}-${DEBVERSION}'"

git tag -s "debian/${DEBSOURCE}-${DEBVERSION}" -m "${DEBSOURCE}-${DEBVERSION} (dist=${DEBDIST}, urgency=${DEBURGENCY})"

