#! /bin/sh

# Build an hlfl release.
# extensively borrowed from mutt build-release
# thanks to Thomas Roessler <roessler@guug.de> for it

# update the source

cvs update

# bump the version number, and calculate the tags

rm -f VERSION
cvs update VERSION
OVERSION="`cat VERSION`"
OTAG="hlfl-`echo $OVERSION | tr . -`-rel"

echo $OVERSION | awk -F . '{printf("%d.%d.%d\n", $1, $2, $3 + 1);}' > VERSION
${EDITOR} VERSION

VERSION="`cat VERSION`"
TAG="hlfl-`echo $VERSION | tr . -`-rel"

rcs2log -v -u "asl:Arnaud Launay:launay@hlfl.org" -u "renaud:Renaud Deraison:deraison@hlfl.org" | cat - ChangeLog > ChangeLog.$$ && mv ChangeLog.$$ ChangeLog
#${EDITOR} ChangeLog

# now, tag the release

cvs commit -m "automatic post-release commit for hlfl-${VERSION}"
cvs tag ${TAG}

# prepare the tarballs

cvs export -r ${TAG} -d /tmp/hlfl-${VERSION} hlfl
( cd /tmp && tar cvf hlfl-${VERSION}.tar hlfl-${VERSION} && bzip2 -k9 hlfl-${VERSION}.tar && gzip -9 hlfl-${VERSION}.tar )

# build the diffs

cvs rdiff -u -r ${OTAG} -r ${TAG} hlfl | gzip -9 \
	> /tmp/diff-${OVERSION}-${VERSION}.gz
cvs rdiff -u -r ${OTAG} -r ${TAG} hlfl | bzip2 -9 \
	> /tmp/diff-${OVERSION}-${VERSION}.bz2

# upload the release to the net
DISTFILES="hlfl-${VERSION}.tar.bz2 hlfl-${VERSION}.tar.gz diff-${OVERSION}-${VERSION}.bz2 diff-${OVERSION}-${VERSION}.gz"

for i in $DISTFILES; do
	scp /tmp/$i atlantis.hlfl.org:/home/ftp/pub/hlfl
done

# Announce it to people

mutt -s "[Announce] HLFL-${VERSION} is out" hlfl-announce@hlfl.org
