#!/bin/bash

set -ex

# assume that upstream/master has already been updated, since the package
# goes into unstable first.
date=${1:-$(date -u -d $(git log -1 --date=short --pretty=format:%cI upstream/master) +%Y%m%d.%H%M)}
git merge -m "merge upstream changes to ${date}" "publicsuffix/${date}"
git log -n30 "publicsuffix/${date}" > debian/upstream-changes.txt
git add debian/upstream-changes.txt
newver="${date}-0+deb9u1"
dch --distribution stretch -v "$newver" 'new upstream publicsuffix data'
git add debian/changelog
git commit -m "new upstream version ${date}"
gbp buildpackage --git-tag --changes-option=-S
debian/rules clean
git push salsa --follow-tags debian/stretch
prevver="$(dpkg-parsechangelog -o 1 -c 1 -S Version)"
debdiff="publicsuffix_${prevver}_${newver}.debdiff"
debdiff  "../publicsuffix_${prevver}.dsc" "../publicsuffix_${newver}.dsc" | gzip -n -9 > ../"$debdiff".gz
mailx --mime --attach=../"$debdiff".gz --return-address="$DEBEMAIL" --subject="stretch-pu: package publicsuffix/$newver" submit@bugs.debian.org <<EOF
Package: release.debian.org
Severity: normal
Tags: stretch
User: release.debian.org@packages.debian.org
Usertags: pu
Control: affects -1 src:publicsuffix

Please consider an update to publicsuffix in debian stretch.

This package reflects the state of the network, and keeping it current
is useful for all the packages that depend on it.

The debdiff from the previous version in stretch is attached.

This proposed release is also available at the
"publicsuffix_debian/$newver" tag on the "debian/stretch" branch at
the git repo for publicsuffix packaging:

    https://salsa.debian.org/debian/publicsuffix

Please followup on this ticket to confirm whether I should upload this
revision to stretch.

EOF
