GP-2301: Each launch script can now specify if they require a JDK or JRE

to run.  Allows svrAdmin to run with just a JRE, like the GhidraServer.
This commit is contained in:
Ryan Kurtz 2022-08-11 05:27:06 -04:00
parent aad60ecdd3
commit 4491a0fd6e
18 changed files with 57 additions and 45 deletions

View file

@ -16,4 +16,4 @@ SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo
SCRIPT_DIR="${SCRIPT_FILE%/*}" SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch Ghidra # Launch Ghidra
"${SCRIPT_DIR}"/support/launch.sh bg Ghidra "${MAXMEM}" "" ghidra.GhidraRun "$@" "${SCRIPT_DIR}"/support/launch.sh bg jdk Ghidra "${MAXMEM}" "" ghidra.GhidraRun "$@"

View file

@ -46,7 +46,7 @@ OWNER="$(grep '^wrapper.app.account=' "${CONFIG}" | sed -e 's/^.*=\(.*\)\s*.*$/\
if [ -z "${OWNER}" -o "${OWNER}" = "$(whoami)" ]; then if [ -z "${OWNER}" -o "${OWNER}" = "$(whoami)" ]; then
VMARGS="-DUserAdmin.invocation=$(basename "${SCRIPT_FILE}")" VMARGS="-DUserAdmin.invocation=$(basename "${SCRIPT_FILE}")"
"${SCRIPT_DIR}"/../support/launch.sh fg svrAdmin "${MAXMEM}" "$VMARGS" ghidra.server.ServerAdmin "${CONFIG}" "$@" "${SCRIPT_DIR}"/../support/launch.sh fg jre svrAdmin "${MAXMEM}" "$VMARGS" ghidra.server.ServerAdmin "${CONFIG}" "$@"
else else
echo "Running svrAdmin with $SUDO as ${OWNER} ..." echo "Running svrAdmin with $SUDO as ${OWNER} ..."
$SUDO -u $OWNER "$0" "$@" $SUDO -u $OWNER "$0" "$@"

View file

@ -33,4 +33,4 @@ SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch HeadlessAnalyzer. # Launch HeadlessAnalyzer.
# DEBUG_ADDRESS set via environment for launch.sh # DEBUG_ADDRESS set via environment for launch.sh
DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" Ghidra-Headless "${MAXMEM}" "${VMARG_LIST}" ghidra.app.util.headless.AnalyzeHeadless "$@" DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" jdk Ghidra-Headless "${MAXMEM}" "${VMARG_LIST}" ghidra.app.util.headless.AnalyzeHeadless "$@"

View file

@ -28,4 +28,4 @@ fi
APP_VMARGS="-DGhidraJarBuilder.Name=$(basename "${SCRIPT_FILE}")" APP_VMARGS="-DGhidraJarBuilder.Name=$(basename "${SCRIPT_FILE}")"
# Launch jar builder # Launch jar builder
"${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" Ghidra "${MAXMEM}" "${APP_VMARGS}" ghidra.util.GhidraJarBuilder -main ghidra.JarRun "$@" "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" jdk Ghidra "${MAXMEM}" "${APP_VMARGS}" ghidra.util.GhidraJarBuilder -main ghidra.JarRun "$@"

View file

@ -16,4 +16,4 @@ SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo
SCRIPT_DIR="${SCRIPT_FILE%/*}" SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch Filesystem Conversion # Launch Filesystem Conversion
"${SCRIPT_DIR}"/launch.sh fg ConvertStorage "${MAXMEM}" "" ghidra.framework.data.ConvertFileSystem "$@" "${SCRIPT_DIR}"/launch.sh fg jdk ConvertStorage "${MAXMEM}" "" ghidra.framework.data.ConvertFileSystem "$@"

View file

@ -24,4 +24,4 @@ SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch Ghidra in debug mode # Launch Ghidra in debug mode
# DEBUG_ADDRESS set via environment for launch.sh # DEBUG_ADDRESS set via environment for launch.sh
DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" Ghidra "${MAXMEM}" "" ghidra.GhidraRun "$@" DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" jdk Ghidra "${MAXMEM}" "" ghidra.GhidraRun "$@"

View file

@ -19,24 +19,26 @@ umask 027
function showUsage() { function showUsage() {
echo "Usage: $0 <mode> <name> <max-memory> \"<vmarg-list>\" <app-classname> <app-args>... " echo "Usage: $0 <mode> <java-type> <name> <max-memory> \"<vmarg-list>\" <app-classname> <app-args>... "
echo " <mode>: fg run as foreground process in current shell" echo " <mode>: fg run as foreground process in current shell"
echo " bg run as background process in new shell" echo " bg run as background process in new shell"
echo " debug run as foreground process in current shell in debug mode (suspend=n)" echo " debug run as foreground process in current shell in debug mode (suspend=n)"
echo " debug-suspend run as foreground process in current shell in debug mode (suspend=y)" echo " debug-suspend run as foreground process in current shell in debug mode (suspend=y)"
echo " NOTE: for all debug modes environment variable DEBUG_ADDRESS may be set to " echo " NOTE: for all debug modes environment variable DEBUG_ADDRESS may be set to "
echo " override default debug address of 127.0.0.1:18001" echo " override default debug address of 127.0.0.1:18001"
echo " <java-type>: jdk requires JDK to run"
echo " jre JRE is sufficient to run (JDK works too)"
echo " <name>: application name used for naming console window" echo " <name>: application name used for naming console window"
echo " <max-memory>: maximum memory heap size in MB (e.g., 768M or 2G). Use empty \"\" if default" echo " <max-memory>: maximum memory heap size in MB (e.g., 768M or 2G). Use empty \"\" if default"
echo " should be used. This will generally be upto 1/4 of the physical memory available" echo " should be used. This will generally be upto 1/4 of the physical memory available"
echo " to the OS." echo " to the OS."
echo " <vmarg-list>: pass-thru args (e.g., \"-Xmx512M -Dmyvar=1 -DanotherVar=2\") - use" echo " <vmarg-list>: pass-thru args (e.g., \"-Xmx512M -Dmyvar=1 -DanotherVar=2\") - use"
echo " empty \"\" if vmargs not needed" echo " empty \"\" if vmargs not needed"
echo " <app-classname>: application classname (e.g., ghidra.GhidraRun )" echo " <app-classname>: application classname (e.g., ghidra.GhidraRun )"
echo " <app-args>...: arguments to be passed to the application" echo " <app-args>...: arguments to be passed to the application"
echo " " echo " "
echo " Example:" echo " Example:"
echo " $0 debug Ghidra 768M \"\" ghidra.GhidraRun" echo " \"$0\" debug jdk Ghidra 4G \"\" ghidra.GhidraRun"
exit 1 exit 1
} }
@ -56,17 +58,24 @@ do
MODE=$AA MODE=$AA
;; ;;
2) 2)
APPNAME=$AA if [ "$AA" = "jre" ]; then
JAVA_TYPE_ARG="-java_home"
else
JAVA_TYPE_ARG="-jdk_home"
fi
;; ;;
3) 3)
MAXMEM=$AA APPNAME=$AA
;; ;;
4) 4)
MAXMEM=$AA
;;
5)
if [ "$AA" != "" ]; then if [ "$AA" != "" ]; then
VMARG_LIST=$AA VMARG_LIST=$AA
fi fi
;; ;;
5) 6)
CLASSNAME=$AA CLASSNAME=$AA
;; ;;
*) *)
@ -80,7 +89,7 @@ do
done done
# Verify that required number of args were provided # Verify that required number of args were provided
if [[ ${INDEX} -lt 5 ]]; then if [[ ${INDEX} -lt 6 ]]; then
echo "Incorrect launch usage - missing argument(s)" echo "Incorrect launch usage - missing argument(s)"
showUsage showUsage
exit 1 exit 1
@ -122,13 +131,13 @@ if ! [ -x "$(command -v java)" ] ; then
fi fi
# Get the JDK that will be used to launch Ghidra # Get the JDK that will be used to launch Ghidra
JAVA_HOME="$(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -jdk_home -save)" JAVA_HOME="$(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -save)"
if [ ! $? -eq 0 ]; then if [ ! $? -eq 0 ]; then
# No JDK has been setup yet. Let the user choose one. # No JDK has been setup yet. Let the user choose one.
java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -jdk_home -ask java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -ask
# Now that the user chose one, try again to get the JDK that will be used to launch Ghidra # Now that the user chose one, try again to get the JDK that will be used to launch Ghidra
JAVA_HOME="$(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -jdk_home -save)" JAVA_HOME="$(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -save)"
if [ ! $? -eq 0 ]; then if [ ! $? -eq 0 ]; then
echo echo
echo "Failed to find a supported JDK. Please refer to the Ghidra Installation Guide's Troubleshooting section." echo "Failed to find a supported JDK. Please refer to the Ghidra Installation Guide's Troubleshooting section."

View file

@ -33,4 +33,4 @@ SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch Ghidra Python # Launch Ghidra Python
# DEBUG_ADDRESS set via environment for launch.sh # DEBUG_ADDRESS set via environment for launch.sh
DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" "Ghidra-Python" "${MAXMEM}" "${VMARG_LIST}" ghidra.python.PythonRun "$@" DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" jdk "Ghidra-Python" "${MAXMEM}" "${VMARG_LIST}" ghidra.python.PythonRun "$@"

View file

@ -15,4 +15,4 @@
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")" SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}" SCRIPT_DIR="${SCRIPT_FILE%/*}"
"${SCRIPT_DIR}"/launch.sh fg Sleigh "$MAXMEM" "" ghidra.pcodeCPort.slgh_compile.SleighCompileLauncher "$@" "${SCRIPT_DIR}"/launch.sh fg jdk Sleigh "$MAXMEM" "" ghidra.pcodeCPort.slgh_compile.SleighCompileLauncher "$@"

View file

@ -7,5 +7,5 @@ setlocal
:: the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed. :: the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
::set MAXMEM=2G ::set MAXMEM=2G
call "%~dp0support\launch.bat" bg Ghidra "%MAXMEM%" "" ghidra.GhidraRun %* call "%~dp0support\launch.bat" bg jdk Ghidra "%MAXMEM%" "" ghidra.GhidraRun %*

View file

@ -45,4 +45,4 @@ set "CONFIG=%SCRIPT_DIR%..\..\Common\server\server.conf"
set VMARGS=-DUserAdmin.invocation=%~n0 set VMARGS=-DUserAdmin.invocation=%~n0
call "%~dp0\..\support\launch.bat" fg svrAdmin "%MAXMEM%" "%VMARGS%" ghidra.server.ServerAdmin "%CONFIG%" %* call "%~dp0\..\support\launch.bat" fg jre svrAdmin "%MAXMEM%" "%VMARGS%" ghidra.server.ServerAdmin "%CONFIG%" %*

View file

@ -56,4 +56,4 @@ goto Loop
setlocal DisableDelayedExpansion setlocal DisableDelayedExpansion
call "%SCRIPT_DIR%launch.bat" %LAUNCH_MODE% Ghidra-Headless "%MAXMEM%" "%VMARG_LIST%" ghidra.app.util.headless.AnalyzeHeadless %params% call "%SCRIPT_DIR%launch.bat" %LAUNCH_MODE% jdk Ghidra-Headless "%MAXMEM%" "%VMARG_LIST%" ghidra.app.util.headless.AnalyzeHeadless %params%

View file

@ -27,4 +27,4 @@ exit /B 1
set APP_VMARGS=-DGhidraJarBuilder.Name=%~n0 set APP_VMARGS=-DGhidraJarBuilder.Name=%~n0
call "%SUPPORT_DIR%\launch.bat" %LAUNCH_MODE% Ghidra "" "%APP_VMARGS%" ghidra.util.GhidraJarBuilder -main ghidra.JarRun %* call "%SUPPORT_DIR%\launch.bat" %LAUNCH_MODE% jdk Ghidra "" "%APP_VMARGS%" ghidra.util.GhidraJarBuilder -main ghidra.JarRun %*

View file

@ -6,4 +6,4 @@ setlocal
:: maximum heap memory may be change if inadequate :: maximum heap memory may be change if inadequate
set MAXMEM=128M set MAXMEM=128M
call "%~dp0launch.bat" fg ConvertStorage "%MAXMEM%" "" ghidra.framework.data.ConvertFileSystem %* call "%~dp0launch.bat" fg jdk ConvertStorage "%MAXMEM%" "" ghidra.framework.data.ConvertFileSystem %*

View file

@ -15,4 +15,4 @@ set LAUNCH_MODE=debug
:: NOTE: This variable is ignored if not launching in a debugging mode. :: NOTE: This variable is ignored if not launching in a debugging mode.
set DEBUG_ADDRESS=127.0.0.1:18001 set DEBUG_ADDRESS=127.0.0.1:18001
call "%~dp0launch.bat" %LAUNCH_MODE% Ghidra "%MAXMEM%" "" ghidra.GhidraRun %* call "%~dp0launch.bat" %LAUNCH_MODE% jdk Ghidra "%MAXMEM%" "" ghidra.GhidraRun %*

View file

@ -2,24 +2,26 @@
goto continue goto continue
:showUsage :showUsage
echo Usage: %0 ^<mode^> ^<name^> ^<max-memory^> "<vmarg-list>" ^<app-classname^> ^<app-args^>... echo Usage: %0 ^<mode^> ^<java-type^> ^<name^> ^<max-memory^> "<vmarg-list>" ^<app-classname^> ^<app-args^>...
echo ^<mode^>: fg run as foreground process in current shell echo ^<mode^>: fg run as foreground process in current shell
echo bg run as background process in new shell echo bg run as background process in new shell
echo debug run as foreground process in current shell in debug mode ^(suspend=n^) echo debug run as foreground process in current shell in debug mode ^(suspend=n^)
echo debug-suspend run as foreground process in current shell in debug mode ^(suspend=y^) echo debug-suspend run as foreground process in current shell in debug mode ^(suspend=y^)
echo NOTE: for all debug modes environment variable DEBUG_ADDRESS may be set to echo NOTE: for all debug modes environment variable DEBUG_ADDRESS may be set to
echo override default debug address of 127.0.0.1:18001 echo override default debug address of 127.0.0.1:18001
echo ^<java-type^>: jdk requires JDK to run
echo jre JRE is sufficient to run (JDK works too)
echo ^<name^>: application name used for naming console window echo ^<name^>: application name used for naming console window
echo ^<max-memory^>: maximum memory heap size in MB ^(e.g., 768M or 2G^). Use "" if default should be used. echo ^<max-memory^>: maximum memory heap size in MB ^(e.g., 768M or 2G^). Use "" if default should be used.
echo This will generally be upto 1/4 of the physical memory available to the OS. On echo This will generally be upto 1/4 of the physical memory available to the OS. On
echo some systems the default could be much less (particularly for 32-bit OS). echo some systems the default could be much less (particularly for 32-bit OS).
echo ^<vmarg-list^>: pass-thru args ^(e.g., "-Xmx512M -Dmyvar=1 -DanotherVar=2"^) - use echo ^<vmarg-list^>: pass-thru args ^(e.g., "-Xmx512M -Dmyvar=1 -DanotherVar=2"^) - use
echo empty "" if vmargs not needed echo empty "" if vmargs not needed
echo ^<app-classname^>: application classname ^(e.g., ghidra.GhidraRun ^) echo ^<app-classame^>: application classname ^(e.g., ghidra.GhidraRun ^)
echo ^<app-args^>...: arguments to be passed to the application echo ^<app-args^>...: arguments to be passed to the application
echo. echo.
echo Example: echo Example:
echo %0 debug Ghidra 768M "" ghidra.GhidraRun echo %0 debug jdk Ghidra 4G "" ghidra.GhidraRun
exit /B 1 exit /B 1
:continue :continue
@ -57,14 +59,15 @@ set INDEX=0
for %%A in (%*) do ( for %%A in (%*) do (
set /A INDEX=!INDEX!+1 set /A INDEX=!INDEX!+1
if "!INDEX!"=="1" ( set MODE=%%A if "!INDEX!"=="1" ( set MODE=%%A
) else if "!INDEX!"=="2" ( set APPNAME=%%A ) else if "!INDEX!"=="2" ( if %%~A == jre (set JAVA_TYPE_ARG=-java_home) else (set JAVA_TYPE_ARG=-jdk_home)
) else if "!INDEX!"=="3" ( set MAXMEM=%%~A ) else if "!INDEX!"=="3" ( set APPNAME=%%A
) else if "!INDEX!"=="4" ( if not "%%~A"=="" set VMARG_LIST=%%~A ) else if "!INDEX!"=="4" ( set MAXMEM=%%~A
) else if "!INDEX!"=="5" ( set CLASSNAME=%%~A ) else if "!INDEX!"=="5" ( if not "%%~A"=="" set VMARG_LIST=%%~A
) else if "!INDEX!"=="6" ( set CLASSNAME=%%~A
) else set ARGS=!ARGS! %%A ) else set ARGS=!ARGS! %%A
) )
if %INDEX% geq 5 goto continue1 if %INDEX% geq 6 goto continue1
echo Incorrect launch usage - missing argument^(s^) echo Incorrect launch usage - missing argument^(s^)
goto showUsage goto showUsage
@ -109,13 +112,13 @@ if not %ERRORLEVEL% == 0 (
:: Get the JDK that will be used to launch Ghidra :: Get the JDK that will be used to launch Ghidra
set JAVA_HOME= set JAVA_HOME=
for /f "delims=*" %%i in ('java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -jdk_home -save') do set JAVA_HOME=%%i for /f "delims=*" %%i in ('java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -save') do set JAVA_HOME=%%i
if "%JAVA_HOME%" == "" ( if "%JAVA_HOME%" == "" (
:: No JDK has been setup yet. Let the user choose one. :: No JDK has been setup yet. Let the user choose one.
java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -jdk_home -ask java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -ask
:: Now that the user chose one, try again to get the JDK that will be used to launch Ghidra :: Now that the user chose one, try again to get the JDK that will be used to launch Ghidra
for /f "delims=*" %%i in ('java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -jdk_home -save') do set JAVA_HOME=%%i for /f "delims=*" %%i in ('java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -save') do set JAVA_HOME=%%i
if "!JAVA_HOME!" == "" ( if "!JAVA_HOME!" == "" (
echo. echo.
echo Failed to find a supported JDK. Please refer to the Ghidra Installation Guide's Troubleshooting section. echo Failed to find a supported JDK. Please refer to the Ghidra Installation Guide's Troubleshooting section.

View file

@ -24,4 +24,4 @@ set DEBUG_ADDRESS=127.0.0.1:13002
set VMARG_LIST=-XX:ParallelGCThreads=2 set VMARG_LIST=-XX:ParallelGCThreads=2
set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2 set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2
call "%~dp0launch.bat" %LAUNCH_MODE% Ghidra-Python "%MAXMEM%" "%VMARG_LIST%" ghidra.python.PythonRun %params% call "%~dp0launch.bat" %LAUNCH_MODE% jdk Ghidra-Python "%MAXMEM%" "%VMARG_LIST%" ghidra.python.PythonRun %params%

View file

@ -6,4 +6,4 @@ setlocal
:: maximum heap memory may be change if inadequate :: maximum heap memory may be change if inadequate
set MAXMEM=256M set MAXMEM=256M
call "%~dp0launch.bat" fg Sleigh "%MAXMEM%" "" ghidra.pcodeCPort.slgh_compile.SleighCompileLauncher %* call "%~dp0launch.bat" fg jdk Sleigh "%MAXMEM%" "" ghidra.pcodeCPort.slgh_compile.SleighCompileLauncher %*