#!/bin/sh

JAVA=@JAVA@
LAUNCHER_BOOTCLASSPATH=@LAUNCHER_BOOTCLASSPATH@
LAUNCHER_FLAGS=-Xms8m
CLASSNAME=net.sourceforge.jnlp.controlpanel.CommandLine
BINARY_LOCATION=@ITWEB_SETTINGS_BIN_LOCATION@
PROGRAM_NAME=itweb-settings

PROPERTY_NAME=deployment.jre.dir
CUSTOM_JRE_REGEX="^$PROPERTY_NAME *= *"
CUSTOM_JRE=`grep "$CUSTOM_JRE_REGEX" ~/.icedtea/deployment.properties 2>/dev/null |  sed "s/$CUSTOM_JRE_REGEX//g"`
if [ "x$CUSTOM_JRE" = "x" ] ; then
  CUSTOM_JRE=`grep "$CUSTOM_JRE_REGEX" /etc/.java/.deploy/deployment.properties 2>/dev/null |  sed "s/$CUSTOM_JRE_REGEX//g"`
fi;
if [ "x$CUSTOM_JRE" != "x" ] ; then
  if [ -e  "$CUSTOM_JRE" -a -e "$CUSTOM_JRE/bin/java" ] ; then
    JAVA=$CUSTOM_JRE/bin/java
  else
    echo "Your custom JRE $CUSTOM_JRE read from deployment.properties under key $PROPERTY_NAME as $CUSTOM_JRE is not valid. Using default ($JAVA) in attempt to start. Please fix this."
  fi
fi;

${JAVA} ${LAUNCHER_BOOTCLASSPATH} ${LAUNCHER_FLAGS} \
  -Dicedtea-web.bin.name=${PROGRAM_NAME} \
  -Dicedtea-web.bin.location=${BINARY_LOCATION} \
  ${CLASSNAME} \
  $@

