#!/bin/bash
#
# Copyright (C) Anders Logg 2004-2008
# Licensed under the GNU GPL version 3 or any later version
#
# This script creates a new release of UFL

# Make sure we have the current version
echo '--- Synchronizing repository'
sleep 1
hg commit
hg pull http://www.fenics.org/hg/ufl
hg merge
hg commit
hg update
hg push ssh://ufl@fenics.org/hg/ufl

# Make sure UFL is installed (so we may run unit tests)
echo '--- Installing UFL'
sudo python setup.py install

# Update version numbers
echo '--- Update version number in ChangeLog'
sleep 1
$EDITOR ChangeLog
echo '--- Update version number in __init__.py'
sleep 1
$EDITOR ufl/__init__.py
echo '--- Update version number in setup.py'
sleep 1
$EDITOR setup.py

# Get the version number
SVERSION=`grep '__version__' ufl/__init__.py | cut -d'"' -f2`
VERSION=$SVERSION
echo "--- Version number is $VERSION"

# Run tests
echo '--- Running tests'
cd test
python test.py
echo '--- Have all tests passed? Press return to continue or Ctrl+C to abort.'
read
#echo '--- Only version numbers should differ, press return to continue'
#read
#cd ..
#cp demo/*.h test/regression/reference

# Run benchmark problem
#echo '--- Running benchmark problem'
#cd bench
#echo "UFL version $VERSION" >> bench.log
#date >> bench.log
#echo "" >> bench.log
#./bench >> bench.log
#cd ../

# Tag repository
hg tag $VERSION

# Commit changes to hg
echo '--- Pushing changes to parent repository'
sleep 1
hg commit
hg push ssh://ufl@fenics.org/hg/ufl

# Create archive
hg archive -t tgz ufl-$VERSION.tar.gz

# Copy files to web page
echo '--- Copying files to web server'
scp ufl-$VERSION.tar.gz fenics@fenics.org:www.fenics.org/pub/software/ufl/v$SVERSION
scp ChangeLog fenics@fenics.org:www.fenics.org/pub/software/ufl/
scp TODO fenics@fenics.org:www.fenics.org/pub/software/ufl/

# Notify ufl-dev of the new version
echo '--- Notifying mailing list'
SUBJECT="Version "$VERSION" of UFL released"
#cat ChangeLog | mail -s "$SUBJECT" ufl-dev@fenics.org
echo Please send the following email:
echo Subject: $SUBJECT
echo To: ufl-dev@fenics.org
echo Contents:
cat ChangeLog
echo End of email.

# Edit web pages
echo '--- Edit web pages'
ssh -t fenics@fenics.org '/home/fenics/local/bin/news'
firefox http://www.fenics.org/wiki/Download

# Notify pypi
python setup.py register
