#!/bin/bash
#
# counts up the jar version file in the Repository
# the version file is that file where the current version is stored
# 
# $Id: countJarVersion,v 1.6 2006-08-30 11:51:52 inva Exp $
#

usage () {
	echo "usage $0 <version file>"
	exit 1;
}

if test $# -ne 1 ; then usage; fi

verpath="eric_admin/versions"
verfile="$verpath/$1"
cvsroot=`cat CVS/Root`
retries=5
count=0

mkdir versions >/dev/null 2>&1
cd versions || exit 1

while [ $count -lt $retries ]; do
    count=$((count+1))

    #checkout version file
    rm -f $verfile
    cvs -d $cvsroot -Q co $verfile || continue
    
    #calculate new version
    versionbase=`awk -F. '{print $1 "." $2 "." $3 "."}' < $verfile`
    newversion=`awk -F. '{print $1 "." $2 "." $3 "." $4+1}' < $verfile`
    echo $newversion > $verfile;
    
    #checkin version file
    cvs -d $cvsroot -Q commit -m "by countJarVersion" $verfile > /dev/null || continue
    echo $0: new version of versionbase $versionbase is $newversion
    exit 0
done

echo "$0: Giving up on file $1 after $retries failed attempts"
exit 1

