#!/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, and uploads it to flow.openplans.org"
    exit
fi

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

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"
SSH_HOST="flow.openplans.org"
SSH_DIR="/www/svn.openplans.org/eggs"
SSH_FILE="openplans-bundle-$NAME-$DATE_STAMP.tar.bz2"
CURRENT_FILE="openplans-bundle-$NAME.txt"
echo "Writing to $SSH_HOST:$SSH_DIR/$SSH_FILE"
echo "Uploading..."
tar cj . | ssh $SSH_HOST "cat > $SSH_DIR/$SSH_FILE ; echo $DATE_STAMP > $SSH_DIR/$CURRENT_FILE ; ls -l $SSH_DIR/$SSH_FILE $SSH_DIR/$CURRENT_FILE"
echo "done."
