#!/bin/bash

if [ "x$PREPARE_SDCARD_GSDL3HOME" = "x" ] ; then
  echo "Environment variable PREPARE_SDCARD_GSDL3HOME undefined" 1>&2
  echo "Have you source setup.bash?" 1>&2
  exit -1
fi

if [ $# = "0" ] ; then
  within_webapps="greenstone3"
elif [ $# = "1" ] ; then
  within_webapps=${1#webapps/}
else
  echo "Error: too many arguments" 1>&2
  echo "Usage: $0 webapps-dir" 1>&2
  exit -1
fi

# remove any trailing slash, as 'adb' does not appear to like this
within_webapps=${within_webapps%/}

echo "Running: adb push \"webapps/$within_webapps\" \"$WITHIN_SDCARD_WEBAPPS/$within_webapps\""

adb push "webapps/$within_webapps" "$WITHIN_SDCARD_WEBAPPS/$within_webapps"

echo ""
echo "####"
echo "# Start up i-jetty on the Android device, and in a web browser visit:"
echo "#   http://localhost:8080/greenstone3/"
echo "####"
echo ""