#!/bin/bash
### check argument count ###
if [ $# -eq 0 ]
then
   echo "Error: Argument missing. Use '-h' for help."
   exit
fi

### find location of script file ###
pushd . > /dev/null
SCRIPT_PATH="${BASH_SOURCE[0]}";
    while([ -h "${SCRIPT_PATH}" ]) do
        cd "`dirname "${SCRIPT_PATH}"`"
        SCRIPT_PATH="$(readlink "`basename "${SCRIPT_PATH}"`")";
    done
cd "`dirname "${SCRIPT_PATH}"`" > /dev/null
SCRIPT_PATH="`pwd`";
popd > /dev/null
#echo "script=[${SCRIPT_PATH}]"
###

em_path=`echo "${SCRIPT_PATH}/em-cli.jar"`
#echo "em_path=[${em_path}]"

current_path=`pwd`
current_emulmgr="$current_path/em-cli.jar"

export COLUMNS="$[$(tput cols)]"

if [ -f "$current_emulmgr" ]
then
java -jar "$current_emulmgr" "$@"
else
java -jar "$em_path" "$@"
fi
