#!/bin/bash
# $Id: art-bag 240 2010-05-04 01:13:12Z jack.oquin $

if [ "$2" == "" ]
then
	echo "usage: `basename $0` [get|put] subtree [-n]"
        echo ""
        echo "copy bag files to or from www.landrobot.com"
        echo "do not actually perform the copy if -n specified"
	exit 9
fi

CMD=$1
SUBTREE=$2
SITE=www.landrobot.com
BAGS=${ROS_HOME:-~/.ros}/bags
DRY_RUN=$3

if [ $CMD == "put" ]
then
        FROM=$BAGS/$SUBTREE
        TO=$SITE:/pub/bags
        cd $FROM
        echo "compressing all .bag files"
        gzip --rsyncable -v *.bag */*.bag 2>/dev/null

elif [ $CMD == "get" ]
then
        FROM=$SITE:/pub/bags/$SUBTREE
        TO=$BAGS
        mkdir -p $BAGS    # make sure target exists
else
        echo "invalid command:" $CMD
        exit 8
fi

echo rsync $DRY_RUN -Phrvc $FROM $TO
exec rsync $DRY_RUN -Phrvc $FROM $TO
