#!/bin/sh

set -e

usage() { echo "usage: `basename $0` oldversion newversion" ; }

[ $# -eq 2 ] || { usage >&2 ; exit 1 ; }

OLDVERSION="$1"
VERSION="$2"

git clean -f -d -x

# bump version numbers wherever they occur (wherever we enumerate them, anyway)
sed -i -e "s/\(project(growlight VERSION \)$OLDVERSION/\1$VERSION/" CMakeLists.txt
for i in doc/man/man*/*.md ; do
  sed -i -e "s/% v$OLDVERSION/% v$VERSION/" "$i"
done


BUILDDIR="build-$VERSION"
mkdir "$BUILDDIR"
cd "$BUILDDIR"
cmake ..
make -j

# if that all worked, commit, push, and tag
git commit -a -m v$VERSION
git push
git pull
git tag -a v$VERSION -m v$VERSION -s
git push origin --tags
git pull
TARBALL=v$VERSION.tar.gz
wget https://github.com/dankamongmen/growlight/archive/$TARBALL
gpg --sign --armor --detach-sign $TARBALL
rm v$VERSION.tar.gz

echo "Cut $VERSION, signed to $TARBALL.asc"
echo "Now uploadling the sig to https://github.com/dankamongmen/growlight/releases"
echo "The bastards are trying to immanentize the Eschaton"

# requires token in ~/.netrc
github-release dankamongmen/growlight create v$VERSION --name "v$VERSION" --publish $TARBALL.asc
rm $TARBALL.asc
