#! /bin/sh

##  $Id: mksnapshot 8189 2008-11-23 20:15:19Z eagle $
##
##  Build a snapshot of the current tree.
##
##  Meant to be run on a fresh Subversion checkout, this script does the
##  necessary work to generate a snapshot.  It expects to be invoked from the
##  top level of the source tree and leaves the generated snapshot in that
##  same directory as a .tar.gz file.
##
##  Snapshot generation will fail if the tree will not compile or if make test
##  fails.  In either case, the output is left in snapshot.log.
##
##  This script takes one argument, a string representing what tree the
##  snapshot is being taken from.  Generally this string is either CURRENT or
##  STABLE.
##  If this argument is BETA, a second argument is needed:  the number of the
##  beta version (for instance b1 or b2).
##
##  Examples of use:
##
##    support/mksnapshot CURRENT
##    support/mksnapshot BETA b1

set -e

date=`date -u +%Y%m%d`
tree="$1"

if [ -z "$tree" ] ; then
    echo "$0: no tree name specified" >&2
    exit 1
fi

if [ "$tree" = "BETA" ] ; then
    number="$2"
    if [ -z "$number" ] ; then
        echo "$0: no version specified for $tree" >&2
        exit 1
    fi
fi

exec > snapshot.log 2>&1

./autogen
./configure
make warnings
make test
make check-manifest

if [ "$tree" = "BETA" ] ; then

    cat > README.beta <<EOF
This is a beta release of the current development version of INN.
It was made on:

    `date -u +"%B %e, %Y @ %I:%M %p %Z"`

Although it should work fine, this code should still be considered
experimental.  If you find any bugs, we'd like to know at
<inn-bugs@isc.org>.

Your feedback is also more than welcome on the <inn-workers@isc.org>
mailing list.  See README for more information.
EOF

else

    cat > README.snapshot <<EOF
This is a snapshot of the current development version of INN, pulled
automatically from the Subversion repository.  It was made on:

    `date -u +"%B %e, %Y @ %I:%M %p %Z"`

This code should be considered experimental.  Only a default compile and
automated testing is done before it is made available.  If it breaks, we'd
like to know at <inn-bugs@isc.org>, but if it causes your system to explode,
don't blame us.

If you are using this code, it's highly recommended that you be on the
<inn-workers@isc.org> mailing list.  See README for more information.
EOF

fi

if [ "$tree" = "BETA" ] ; then
    make release RELEASENUMBER="$number"
else
    make snapshot SNAPSHOT="$tree" SNAPDATE="$date"
fi
