#! /bin/bash

if [ x$1 = x ]; then
	SVNREV="-r 1824"
	SVNREVSHORT="1824"
else
	SVNREV="-r $1"
	SVNREVSHORT="$1"
fi

# First, this will check out the data until the given revision or 1824 if not given.
# Then it will prepare it to be packed, with the inclusion of this script and a symlink.
# And finnaly it will pack excluding every ".svn" directory.

# If widelands was already checked out, this will just update to the chosen revision.
echo "svn co https://svn.sourceforge.net/svnroot/widelands/trunk $SVNREV widelands" &&
svn co https://svn.sourceforge.net/svnroot/widelands/trunk $SVNREV widelands || exit $?

echo "mv widelands widelands-$SVNREVSHORT" &&
mv widelands widelands-$SVNREVSHORT &&
echo "ln -s widelands-$SVNREVSHORT widelands" &&
ln -s widelands-$SVNREVSHORT widelands &&
echo "tar cvjf widelands-svn-$SVNREVSHORT.tar.bz2 --exclude='.svn' $0 widelands widelands-$SVNREVSHORT" &&
tar cvjf widelands-svn-$SVNREVSHORT.tar.bz2 --exclude='.svn' $0 widelands widelands-$SVNREVSHORT

rm -f widelands
mv -f widelands-$SVNREVSHORT widelands
