#!/bin/bash function tempfile { if [ -x /bin/tempfile ] ; then /bin/tempfile else echo "/tmp/$1" fi } function upload { TCX=$1 MIME=$TCX.mime MIMESEP="mime-part-boundary" cat << _EOF > $MIME --$MIMESEP Content-Disposition: form-data; name="data"; filename="activity.tcx" Content-Type: application/octet-stream $(cat $TCX) --$MIMESEP Content-Disposition: form-data; name="responseContentType" text/html --$MIMESEP-- _EOF COOKIES=`tempfile garmin-cookies.txt` wget \ --save-cookies $COOKIES \ --keep-session-cookies \ -O /dev/null \ "http://connect.garmin.com/signin" && \ wget \ --load-cookies $COOKIES \ --save-cookies $COOKIES \ --keep-session-cookies \ --header "Content-Type: application/x-www-form-urlencoded" \ --post-data "login=login&login%3AloginUsernameField=$USER&login%3Apassword=$PASSWORD&login%3AsignInButton=Sign+In&javax.faces.ViewState=j_id1" \ -O /dev/null \ "https://connect.garmin.com/signin" && \ wget \ --load-cookies $COOKIES \ --header "Content-Type: multipart/form-data; boundary=$MIMESEP" \ --post-file "$MIME" \ -O - \ "http://connect.garmin.com/proxy/upload-service-1.1/json/upload" && \ rm -f $COOKIES $MIME } if [ -z "$GARMIN_SAVE_RUNS" ] ; then GARMIN_SAVE_RUNS=`pwd` fi if [ -d "$GARMIN_SAVE_RUNS/pending" ] ; then PENDING=`ls "$GARMIN_SAVE_RUNS"/pending/*.gmn 2>/dev/null` fi if [ ! -z "$PENDING" ] ; then cd "$GARMIN_SAVE_RUNS" TCX=`tempfile garmin-data.tcx` `dirname $0`/gmn2tcx $PENDING > $TCX upload $TCX && rm -f $PENDING rm -f $TCX cd - >/dev/null fi