#! /bin/sh

##  $Id: mksnapshot 10290 2018-06-03 18:33:00Z 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 or RC, a second argument is needed: the
##  number of the beta version (for instance b1 or b2) or the release
##  candidate.
##
##  Examples of use:
##
##    support/mksnapshot CURRENT
##    support/mksnapshot STABLE
##    support/mksnapshot BETA b1
##    support/mksnapshot RC rc2

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"
    extension=beta
    releasename="beta release"
    if [ -z "$number" ] ; then
        echo "$0: no version specified for $tree" >&2
        exit 1
    fi
elif [ "$tree" = "RC" ] ; then
    number="$2"
    extension=release-candidate
    releasename="release candidate"
    if [ -z "$number" ] ; then
        echo "$0: no version specified for $tree" >&2
        exit 1
    fi
else
    exec > snapshot.log 2>&1

    ./autogen
    ./configure --with-perl --with-python
    make warnings
    make test
    make check-manifest
fi

if [ "$tree" = "BETA" -o "$tree" = "RC" ] ; then

    cat > README.$extension <<EOF
This is a $releasename based on 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-workers@lists.isc.org>.

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

fi

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