#!/bin/bash
# 
# Get current swami cvs code
#
# nando, Feb 27 2003
#
STAMP=`date +"%Y%m%d.%H%M%S"`

# BRANCH=swami-1-0

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

echo "NOTE: press <enter> when prompted for password"
echo
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/swami login 

echo "  getting swami..."
if [ "${BRANCH}x" = "x" ] ; then
  cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/swami co swami
else
  cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/swami co -r ${BRANCH} swami
fi
echo "  creating swami tarball..."
if [ -d swami ] ; then
   # gtk swami version
   if [ -e swami/configure.in ] ; then
      SWAMI_MAJOR=`grep _VERSION_MAJOR= swami/configure.in | head -1 | awk -F= '{print $2}'`
      SWAMI_MINOR=`grep _VERSION_MINOR= swami/configure.in | head -1 | awk -F= '{print $2}'`
      SWAMI_MICRO=`grep _VERSION_MICRO= swami/configure.in | head -1 | awk -F= '{print $2}'`
   else
      SWAMI_MAJOR=`grep _VERSION_MAJOR= swami/configure.ac | head -1 | awk -F= '{print $2}'`
      SWAMI_MINOR=`grep _VERSION_MINOR= swami/configure.ac | head -1 | awk -F= '{print $2}'`
      SWAMI_MICRO=`grep _VERSION_MICRO= swami/configure.ac | head -1 | awk -F= '{print $2}'`
   fi
   VERSION=${SWAMI_MAJOR}.${SWAMI_MINOR}.${SWAMI_MICRO}
   touch swami/CVS-${STAMP}
   mv swami swami-${VERSION}
   if [ "${BRANCH}x" = "x" ] ; then
      tar czf ../swami-${VERSION}-cvs.tar.gz swami-${VERSION}
   else
      tar czf ../swami-${VERSION}-cvs-${BRANCH}.tar.gz swami-${VERSION}
   fi
fi
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/swami logout
cd ../
if [ -d swami-${STAMP} ] ; then
   echo "  removing download directory..."
   rm -r swami-${STAMP}
fi
# print current version numbers for spec file
echo
echo "Current swami version numbers:"
echo
echo "%define ver      ${VERSION}"
echo "%define cvs_date ${STAMP}"
echo
exit
