#!/bin/sh

if [ -z "$1" -o -z "$2" ]; then
    echo ""
    echo " Usage: updateSVN <src-root> <target-resources-dir>"
    echo ""
    exit 1
fi

OWD=`pwd`
cd "$1"
SVNREV=`sed -n 's/.*revision="\(.*\)".*/\1/p' .svn/entries|head -n 1`
if [ -z "$SVNREV" ]; then
    # SVN 1.4 changed the format - this is a pure guess!! (line 4 = revision)
    SVNREV=`sed -n -e '4 p' .svn/entries`
fi
echo "Revision: $SVNREV"

if [ -z "$SVNREV" ]; then
    echo "Cannot determine SVN revision."
    exit 2
fi

if [ ! -e "$1/English.lproj/InfoPlist.strings" ]; then
    echo "Cannot find $1/English.lproj/InfoPlist.strings"
    exit 2;
fi
if [ ! -e "$1/Info.plist" ]; then
    echo "Cannot find Info.plist"
    exit 3;
fi

sed "s/%SVN%/$SVNREV/g" "$1/English.lproj/InfoPlist.strings" > "$2/English.lproj/InfoPlist.strings"
# Info.plist is actually one level below resources
sed "s/%SVN%/$SVNREV/g" "$1/Info.plist" > "$2/../Info.plist"

exit 0