#!/bin/bash
# 
# Get a fresh copy of MathLib svn source code
# Fernando Lopez-Lezcano (C) 2007

STAMP=`date +"%Y%m%d.%H%M%S"`

REVISION=$1

if [ ! -d MathLib-${STAMP} ] ; then
   echo
   echo "Creating download directory: MathLib-${STAMP}"
   mkdir MathLib-${STAMP}
else
   echo "Error: download directory MathLib-${STAMP} already exists!"
   exit 1
fi
cd MathLib-${STAMP}
echo

echo "  getting MathLib ${REVISION}..."
if [ "${REVISION}" != "" ] ; then
    REVOPT="-r ${REVISION}"
else
    REVOPT=""
fi
svn co ${REVOPT} https://quarks.svn.sourceforge.net/svnroot/quarks MathLib
echo "  creating MathLib tarball..."
if [ -d MathLib ] ; then
    REVISION=`svn info MathLib|grep Revision:|awk '{print $2}'`
    SVNDATE=`svn info MathLib|grep "Last Changed Date:"|awk '{print $4}'|sed 's|-||g'`
    mv MathLib MathLib-${REVISION}
    tar czf ../MathLib-${REVISION}-svn.tar.gz MathLib-${REVISION}
fi
cd ../
if [ -d MathLib-${STAMP} ] ; then
   echo "  removing download directory..."
   rm -r MathLib-${STAMP}
fi
# print current version numbers for spec file
echo
echo "Current MathLib version numbers:"
echo
echo "%define revision ${REVISION}"
echo "%define svndate ${SVNDATE}"
echo
exit
