#! /bin/sh

if [ -z "$MULE_HOME" ] ; then
  # find the name of the real MULE_HOME which is two levels up
  MULE_HOME=`pwd`
  MULE_HOME=`dirname "$MULE_HOME"`
  MULE_HOME=`dirname "$MULE_HOME"`
  export MULE_HOME
fi

# If MULE_BASE is not set, make it MULE_HOME
if [ -z "$MULE_BASE" ] ; then
  MULE_BASE="$MULE_HOME"
  export MULE_BASE
fi

if [ ! -d "$MULE_BASE/apps/mule-example-scripting" ]
then
    echo "This example requires you to build it before running it.  Please follow the instructions in the README.txt file."
    exit 1
fi         

echo "The Scripting example is available in two flavors:"
echo "  1. Groovy"
echo "  2. Python"
echo "Select the one you wish to execute and press Enter..."
read i
if [ 1 = $i ]
then
    scriptfile="greedy.groovy"
elif [ 2 = $i ]
then
    scriptfile="greedy.py"
else
    break;
fi

echo "Welcome to the JSR 223-powered Change Machine.  This machine will give you" 
echo "change for the amount you request.  The amount of change is cumulative, so you" 
echo "can keep asking for more and more change until you've had enough."
echo "To get started, select a currency:"
echo "  1. U.S. Dollars"
echo "  2. U.K. Pounds Sterling"
read i
if [ 1 = $i ]; then
    currency="USD"
elif [ 2 = $i ]; then
    currency="GBP"
else
    break;
fi

exec "$MULE_BASE/bin/mule" -config "$MULE_BASE/apps/mule-example-scripting/change-machine.xml" -M-Dscriptfile=$scriptfile -M-Dcurrency=$currency
    