#!/usr/bin/sh

# shellcheck disable=SC1019
# shellcheck disable=SC1073
# shellcheck disable=SC1072
if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME"]; then
  JAVA_PATH=`which java 2>/dev/null`
  if [ "x$JAVA_PATH" != "x" ]; then
     JAVA_PATH=`dirname "$JAVA_PATH" 2>/dev/null`
     JRE_HOME=`dirname "$JAVA_PATH" 2>/dev/null`
  fi
  if [ "x$JRE_HOME" = "x" ]; then
     if [ -x /usr/bin/java ]; then
        JRE_HOME=/usr
     fi
  fi
  if [ -z "$JAVA_HOME" ] && [ -z "JRE_HOME" ]; then
     echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
     echo "At least one of these environment variable is needed to run this program"
     exit 1
  fi
fi
if [ -z "$JRE_HOME" ]; then
   JRE_HOME="$JAVA_HOME"
   #echo "$JRE_HOME"
fi

if [ -z "$_RUNJAVA" ]; then
  _RUNJAVA="$JRE_HOME"/bin/java
  echo "$_RUNJAVA"
fi
