#!/bin/bash
#
# patches the jar version in some kind of applet tag
# the version file is that file where the current version is stored
# the target file is that file where the version is applied to
# 
# versions have the format: <jar ID>.<magic No>.<major ver>.<minor ver>
#     <jar ID>    - values: 1 for "rc.jar", 10 for "rcsoftkbd.jar"
#     <magic No>  - 8371, for uniquely identifying version strings
#     <major ver> - changed manually in CVS (when minor is close to 9999)
#     <minor ver> - incremented automatically in CVS
#
#

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

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

verpath="versions/eric_admin/versions"
verfile="$verpath/$1"
targfile="$2"
magicNo=8371

# get <jar ID> this verfile applies to
jarID=`awk -F. '{print $1}' < $verfile`
# get new version (<major>.<minor>) for this <jar ID>
newversion=$jarID.$magicNo.`awk -F. '{print $3 "." $4}' < $verfile`
echo "$0: new version of jarID $jarID is $newversion"

# apply to target file
sedexpr="s/$jarID\.$magicNo\.[0-9]\+\.[0-9]\+/$newversion/g"
sed -e "$sedexpr" < $targfile > $targfile.new || exit 1
mv $targfile.new $targfile

echo "patched $targfile with $newversion"
