Skip to content

Commit

Permalink
Fixes java path configuration to pick up bundled jdk when java home i…
Browse files Browse the repository at this point in the history
…s not set

Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 1, 2023
1 parent c91394b commit 1333181
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
21 changes: 14 additions & 7 deletions tools/install_demo_configuration.bat
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
@echo off
set DIR=%~dp0

if defined OPENSEARCH_JAVA_HOME (
set BIN_PATH="%OPENSEARCH_JAVA_HOME%\bin\java.exe"
) else if defined JAVA_HOME (
set BIN_PATH="%JAVA_HOME%\bin\java.exe"
if not "%OPENSEARCH_JAVA_HOME%" == "" (
set "JAVA=%OPENSEARCH_JAVA_HOME%\bin\java.exe"
set JAVA_TYPE=OPENSEARCH_JAVA_HOME
) else if not "%JAVA_HOME%" == "" (
set "JAVA=%JAVA_HOME%\bin\java.exe"
set JAVA_TYPE=JAVA_HOME
) else (
echo Unable to find java runtime
echo OPENSEARCH_JAVA_HOME or JAVA_HOME must be defined
set "JAVA=%OPENSEARCH_HOME%\jdk\bin\java.exe"
set "JAVA_HOME=%OPENSEARCH_HOME%\jdk"
set JAVA_TYPE=bundled jdk
)

if not exist !JAVA! (
echo "could not find java in !JAVA_TYPE! at !JAVA!" >&2
exit /b 1
)

%BIN_PATH% -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=OFF -cp "%DIR%\..\*;%DIR%\..\..\..\lib\*;%DIR%\..\deps\*" org.opensearch.security.tools.democonfig.Installer %DIR% %* 2> nul
%JAVA% -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=OFF -cp "%DIR%\..\*;%DIR%\..\..\..\lib\*;%DIR%\..\deps\*" org.opensearch.security.tools.democonfig.Installer %DIR% %* 2> nul
42 changes: 34 additions & 8 deletions tools/install_demo_configuration.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#!/bin/bash
#install_demo_configuration.sh [-y]

UNAME=$(uname -s)
if [ "$UNAME" = "FreeBSD" ]; then
OS="freebsd"
elif [ "$UNAME" = "Darwin" ]; then
OS="darwin"
else
OS="other"
fi

SCRIPT_PATH="${BASH_SOURCE[0]}"
if ! [ -x "$(command -v realpath)" ]; then
if [ -L "$SCRIPT_PATH" ]; then
Expand All @@ -16,17 +25,34 @@ else
DIR="$( cd "$( dirname "$(realpath "$SCRIPT_PATH")" )" && pwd -P)"
fi

BIN_PATH="java"

# now set the path to java: first OPENSEARCH_JAVA_HOME, then JAVA_HOME
# now set the path to java: OPENSEARCH_JAVA_HOME -> JAVA_HOME -> bundled JRE -> bundled JDK
if [ -n "$OPENSEARCH_JAVA_HOME" ]; then
BIN_PATH="$OPENSEARCH_JAVA_HOME/bin/java"
JAVA="$OPENSEARCH_JAVA_HOME/bin/java"
JAVA_TYPE="OPENSEARCH_JAVA_HOME"
elif [ -n "$JAVA_HOME" ]; then
BIN_PATH="$JAVA_HOME/bin/java"
JAVA="$JAVA_HOME/bin/java"
JAVA_TYPE="JAVA_HOME"
else
echo "Unable to find java runtime"
echo "OPENSEARCH_JAVA_HOME or JAVA_HOME must be defined"
if [ "$OS" = "darwin" ]; then
# macOS bundled Java
JAVA="$OPENSEARCH_HOME/jdk.app/Contents/Home/bin/java"
JAVA_TYPE="bundled jdk"
elif [ "$OS" = "freebsd" ]; then
# using FreeBSD default java from ports if JAVA_HOME is not set
JAVA="/usr/local/bin/java"
JAVA_TYPE="bundled jdk"
elif [ -d "$OPENSEARCH_HOME/jre" ]; then
JAVA="$OPENSEARCH_HOME/jre/bin/java"
JAVA_TYPE="bundled jre"
else
JAVA="$OPENSEARCH_HOME/jdk/bin/java"
JAVA_TYPE="bundled jdk"
fi
fi

if [ ! -x "$JAVA" ]; then
echo "could not find java in $JAVA_TYPE at $JAVA" >&2
exit 1
fi

"$BIN_PATH" $JAVA_OPTS -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=OFF -cp "$DIR/../*:$DIR/../../../lib/*:$DIR/../deps/*" org.opensearch.security.tools.democonfig.Installer "$DIR" "$@" 2>/dev/null
"$JAVA" "$JAVA_OPTS" -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=OFF -cp "$DIR/../*:$DIR/../../../lib/*:$DIR/../deps/*" org.opensearch.security.tools.democonfig.Installer "$DIR" "$@" 2>/dev/null

0 comments on commit 1333181

Please sign in to comment.