#!/bin/sh

if [ "$1" = "--version" ]; then
  echo "Operaton: ${project.version} (Wildfly ${version.wildfly})"
else
  export JBOSS_HOME="$(dirname "$0")/server/wildfly-${version.wildfly}"

  UNAME=`which uname`
  if [ -n "$UNAME" -a "`$UNAME`" = "Darwin" ]
  then
    BROWSERS="open"
  else
    BROWSERS="xdg-open gnome-www-browser x-www-browser firefox chromium chromium-browser google-chrome"
  fi

  echo "starting Operaton ${project.version} on Wildfly Application Server ${version.wildfly}";

  if [ -z "$BROWSER" ]; then
    for executable in $BROWSERS; do
      BROWSER=`which $executable 2> /dev/null`
      if [ -n "$BROWSER" ]; then
        break;
      fi
    done
  fi

  /bin/sh "$(dirname "$0")/server/wildfly-${version.wildfly}/bin/standalone.sh"

  if [ -z "$BROWSER" ]; then
    (sleep 15; echo -e "We are sorry... We tried all we could do but we couldn't locate your default browser... \nIf you want to see our default website please open your browser and insert this URL:\nhttp://localhost:8080/operaton-welcome/index.html";) &
  else
    (sleep 15; $BROWSER "http://localhost:8080/operaton-welcome/index.html";) &
  fi
fi
