#!/bin/sh
if [ ! -e getAdditional.sh ] ; then
    echo "You must run this script from the bundle directory:"
    echo "./`basename $0`"
    exit 2
fi

if [ "$1" = "-h" ] ; then
    echo "Usage: ./`basename $0`"
    echo "Creates a tarball of this bundle checkout."
    exit
fi

DATE_STAMP="`date '+%Y%m%d'`"

svn st | grep "^M"
if [ $? -eq  0 ]; then
	echo WARNING, you have uncommitted local changes, see above.
	echo You should really commit or revert those.
	echo Cowardly refusing to proceed.
	exit 1
fi

echo "Updating the bundle, if anything updates here you probably were "
echo "not up to date..."

svn up | grep "^U" 

echo "tarball created on `date '+%Y-%m-%d %H:%M:%S'` by $USER on `hostname`" > tarball-info.txt
cat tarball-info.txt

SVN_URL="`svn info | awk '/^URL:/ {print $2}'`"
echo "Bundle svn location: $SVN_URL"
NAME="`basename $SVN_URL`"
echo "$NAME:$DATE_STAMP" > tarball-id.txt
echo "Bundle name: $NAME  Bundle id: $NAME-$DATE_STAMP"

tar cj . --exclude="*.pyc" --exclude="*.pyo" --exclude="*~"  > /tmp/bundle.tar.bz2
echo "done."
