#!/bin/bash -v

svn_url=file:///home/ben88/svn/frogatto/trunk
rev=`perl -e 'print (\`svn info $ARGV[0]\` =~ /Revision: (\\d+)/);' $svn_url`
bp="mac_builds" #builds path
local=""
while getopts ":r:v:l" flag
do
	case $flag in
		r) rev=$OPTARG;;
		v) version=$OPTARG;;
		l) local=1;;
	esac
done
if [ -z $version ];
then
	version=r$rev
fi

#echo "version = $version, rev = $rev"; exit;

cp -R -p 'mac_template' "$bp/Frogatto $version"
if [ -z $local ]
then
	rsync -avzP ben@64.201.60.211:~/projects/frogatto/MacOSX/build/Release/Frogatto.app/Contents/MacOS/Frogatto "$bp/Frogatto $version/Frogatto.app/Contents/MacOS/"
else
	cp Frogatto "$bp/Frogatto $version/Frogatto.app/Contents/MacOS/"
fi

for dir in data images music sounds locale FreeMono.ttf DejaVuSans.ttf
do
	svn export -r $rev $svn_url/$dir "$bp/Frogatto $version/Frogatto.app/Contents/Resources/$dir"
done;
sed -i "s/{revision}/$rev/g" "$bp/Frogatto $version/Frogatto.app/Contents/Info.plist"
sed -i "s/{version}/$version/g" "$bp/Frogatto $version/Frogatto.app/Contents/Info.plist"
cd "$bp"; zip -r "../../files/Frogatto_${version}_Mac.zip" "Frogatto $version/Frogatto.app"
rm -rf ../mac_builds/*

