#!/bin/sh

PRG="$0"

# resolve symlinks
while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
    else
    PRG=`dirname "$PRG"`"/$link"
    fi
done

dir=`dirname "$PRG"`
dir=`cd "$dir" && pwd`

. "$dir"/../configuration.sh

JAVACLASSPATH="$CLASSPATH:$IBIS_ROOT/build:"

usage() {
  echo "Usage: $0 [-port <port>]"
  echo "Start an Ibis control hub for \"RoutedMessages\" protocol."
  echo "  -port <port>       start the hub on port number <port>"
  echo "                     (default is 9828)"
  echo "  -h, --help         display this help and exit"
}

if [ $# -ge 1 ]; then
  case $1 in
    -h|-help|--help)
      usage
      exit 0
    ;;
    -port)
      if [ -z "$2" ]; then
        usage
	exit 1
      fi
      IBIS_HUB_PORT="$2"
    ;;
    *)
      usage
      exit 1
    ;;
  esac
fi

if [ ! -z "${IBIS_HUB_PORT}" ]; then
  Dhub="-Dibis.connect.hub.port=${IBIS_HUB_PORT}"
fi

"$JAVA_ROOT"/bin/java -classpath "$JAVACLASSPATH" $Dhub ibis.connect.controlHub.ControlHub
