_script-util.bat revision eda9271a828f0d377d046417a788830fd74d7ab3
1229N/A@echo off
2362N/Arem CDDL HEADER START
1229N/Arem
1229N/Arem The contents of this file are subject to the terms of the
1229N/Arem Common Development and Distribution License, Version 1.0 only
1229N/Arem (the "License"). You may not use this file except in compliance
1229N/Arem with the License.
1229N/Arem
1229N/Arem You can obtain a copy of the license at
1229N/Arem trunk/opends/resource/legal-notices/OpenDS.LICENSE
1229N/Arem or https://OpenDS.dev.java.net/OpenDS.LICENSE.
1229N/Arem See the License for the specific language governing permissions
1229N/Arem and limitations under the License.
1229N/Arem
1229N/Arem When distributing Covered Code, include this CDDL HEADER in each
1229N/Arem file and include the License file at
1229N/Arem trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
1229N/Arem add the following below this CDDL HEADER, with the fields enclosed
2362N/Arem by brackets "[]" replaced with your own identifying information:
2362N/Arem Portions Copyright [yyyy] [name of copyright owner]
2362N/Arem
1229N/Arem CDDL HEADER END
1229N/Arem
1229N/Arem
1229N/Arem Copyright 2008-2010 Sun Microsystems, Inc.
1229N/Arem Portions Copyright 2011-2012 ForgeRock AS
1229N/A
1229N/Aset SET_JAVA_HOME_AND_ARGS_DONE=false
1229N/Aset SET_ENVIRONMENT_VARS_DONE=false
1229N/Aset SET_CLASSPATH_DONE=false
1229N/A
1229N/Aif "%INSTALL_ROOT%" == "" goto setInstanceRoot
1229N/A
1229N/A:scriptBegin
1229N/Aif "%SCRIPT_UTIL_CMD%" == "set-full-environment-and-test-java" goto setFullEnvironmentAndTestJava
1229N/Aif "%SCRIPT_UTIL_CMD%" == "set-full-environment" goto setFullEnvironment
1229N/Aif "%SCRIPT_UTIL_CMD%" == "set-java-home-and-args" goto setJavaHomeAndArgs
1229N/Aif "%SCRIPT_UTIL_CMD%" == "set_environment_vars" goto setEnvironmentVars
1229N/Aif "%SCRIPT_UTIL_CMD%" == "test-java" goto testJava
1229N/Aif "%SCRIPT_UTIL_CMD%" == "set-classpath" goto setClassPath
1229N/Agoto prepareCheck
1229N/A
1229N/A:setInstanceRoot
1229N/Asetlocal
1229N/Afor %%i in (%~sf0) do set DIR_HOME=%%~dPsi..
1229N/Aset INSTALL_ROOT=%DIR_HOME%
1229N/Aset INSTANCE_DIR=
1229N/Afor /f "delims=" %%a in (%INSTALL_ROOT%\instance.loc) do (
1229N/A set INSTANCE_DIR=%%a
1229N/A)
1229N/Aset CUR_DIR=%CD%
1229N/Acd /d %INSTALL_ROOT%
1229N/Acd /d %INSTANCE_DIR%
1229N/Aset INSTANCE_ROOT=%CD%
1229N/Acd /d %CUR_DIR%
goto scriptBegin
:setClassPath
if "%SET_CLASSPATH_DONE%" == "true" goto prepareCheck
FOR %%x in ("%INSTALL_ROOT%\lib\*.jar") DO call "%INSTALL_ROOT%\lib\setcp.bat" %%x
if "%INSTALL_ROOT%" == "%INSTANCE_ROOT%"goto setClassPathDone
FOR %%x in ("%INSTANCE_ROOT%\lib\*.jar") DO call "%INSTANCE_ROOT%\lib\setcp.bat" %%x
FOR %%x in ("%INSTALL_ROOT%\resources\*.jar") DO call "%INSTALL_ROOT%\lib\setcp.bat" %%x
set CLASSPATH=%INSTANCE_ROOT%\classes;%CLASSPATH%
:setClassPathDone
set SET_CLASSPATH_DONE=true
goto scriptBegin
:setFullEnvironment
if "%SET_JAVA_HOME_AND_ARGS_DONE%" == "false" goto setJavaHomeAndArgs
if "%SET_CLASSPATH_DONE%" == "false" goto setClassPath
if "%SET_ENVIRONMENT_VARS_DONE%" == "false" goto setEnvironmentVars
goto prepareCheck
:setFullEnvironmentAndTestJava
if "%SET_JAVA_HOME_AND_ARGS_DONE%" == "false" goto setJavaHomeAndArgs
if "%SET_CLASSPATH_DONE%" == "false" goto setClassPath
if "%SET_ENVIRONMENT_VARS_DONE%" == "false" goto setEnvironmentVars
goto testJava
:setJavaHomeAndArgs
if "%SET_JAVA_HOME_AND_ARGS_DONE%" == "true" goto prepareCheck
if not exist "%INSTANCE_ROOT%\lib\set-java-home.bat" goto checkEnvJavaHome
call "%INSTANCE_ROOT%\lib\set-java-home.bat"
if "%OPENDJ_JAVA_BIN%" == "" goto checkEnvJavaHome
:endJavaHomeAndArgs
set SET_JAVA_HOME_AND_ARGS_DONE=true
goto scriptBegin
:checkEnvJavaHome
if "%OPENDJ_JAVA_BIN%" == "" goto checkEnvLegacyJavaHome
if not exist "%OPENDJ_JAVA_BIN%" goto checkEnvLegacyJavaHome
goto endJavaHomeAndArgs
:checkEnvLegacyJavaHome
if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDJJavaHome
if not exist "%OPENDS_JAVA_BIN%" goto checkOpenDJJavaHome
set OPENDJ_JAVA_BIN=%OPENDS_JAVA_BIN%
goto endJavaHomeAndArgs
:checkOpenDJJavaHome
if "%OPENDJ_JAVA_HOME%" == "" goto checkLegacyOpenDSJavaHome
if not exist "%OPENDJ_JAVA_HOME%\bin\java.exe" goto checkLegacyOpenDSJavaHome
set OPENDJ_JAVA_BIN=%OPENDJ_JAVA_HOME%\bin\java.exe
goto endJavaHomeAndArgs
:checkLegacyOpenDSJavaHome
if "%OPENDS_JAVA_HOME%" == "" goto checkJavaPath
if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaPath
set OPENDJ_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
goto endJavaHomeAndArgs
:checkJavaPath
java.exe -version > NUL 2>&1
if not %errorlevel% == 0 goto checkJavaBin
set OPENDJ_JAVA_BIN=java.exe
goto endJavaHomeAndArgs
:checkJavaBin
if "%JAVA_BIN%" == "" goto checkJavaHome
if not exist "%JAVA_BIN%" goto checkJavaHome
set OPENDJ_JAVA_BIN=%JAVA_BIN%
goto endJavaHomeAndArgs
:checkJavaHome
if "%JAVA_HOME%" == "" goto noJavaFound
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaFound
set OPENDJ_JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto endJavaHomeAndArgs
:noJavaFound
echo ERROR: Could not find a valid Java binary to be used.
echo You must specify the path to a valid Java 6.0 update 10 or higher version.
echo The procedure to follow is:
echo 1. Delete the file %INSTANCE_ROOT%\lib\set-java-home.bat if it exists.
echo 2. Set the environment variable OPENDJ_JAVA_HOME to the root of a valid
echo Java 6.0 installation.
echo If you want to have specific Java settings for each command line you must
echo follow the steps 3 and 4.
echo 3. Edit the properties file specifying the Java binary and the Java arguments
echo for each command line. The Java properties file is located in:
echo %INSTANCE_ROOT%\config\java.properties.
echo 4. Run the command-line %INSTALL_ROOT%\bat\dsjavaproperties.bat
pause
exit /B 1
:setEnvironmentVars
if %SET_ENVIRONMENT_VARS_DONE% == "true" goto prepareCheck
set PATH=%SystemRoot%;%PATH%
set SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=%SCRIPT_NAME%
set SET_ENVIRONMENT_VARS_DONE=true
goto scriptBegin
:testJava
if "%OPENDJ_JAVA_ARGS%" == "" goto checkLegacyArgs
:continueTestJava
"%OPENDJ_JAVA_BIN%" %OPENDJ_JAVA_ARGS% org.opends.server.tools.InstallDS -t > NUL 2>&1
set RESULT_CODE=%errorlevel%
if %RESULT_CODE% == 13 goto notSupportedJavaHome
if not %RESULT_CODE% == 0 goto noValidJavaHome
goto prepareCheck
:checkLegacyArgs
if "%OPENDS_JAVA_ARGS%" == "" goto continueTestJava
set OPENDJ_JAVA_ARGS=%OPENDS_JAVA_ARGS%
goto continueTestJava
:noValidJavaHome
if NOT "%OPENDJ_JAVA_ARGS%" == "" goto noValidHomeWithArgs
echo ERROR: The detected Java version could not be used. The detected
echo Java binary is:
echo %OPENDJ_JAVA_BIN%
echo You must specify the path to a valid Java 6.0 update 10 or higher version.
echo The procedure to follow is:
echo 1. Delete the file %INSTANCE_ROOT%\lib\set-java-home.bat if it exists.
echo 2. Set the environment variable OPENDJ_JAVA_HOME to the root of a valid
echo Java 6.0 installation.
echo If you want to have specific Java settings for each command line you must
echo follow the steps 3 and 4.
echo 3. Edit the properties file specifying the Java binary and the Java arguments
echo for each command line. The Java properties file is located in:
echo %INSTANCE_ROOT%\config\java.properties.
echo 4. Run the command-line %INSTALL_ROOT%\bat\dsjavaproperties.bat
pause
exit /B 1
:notSupportedJavaHome
rem We get here when the java version is 6 (or up) but not supported. We run
rem InstallDS again to see a localized message.
"%OPENDJ_JAVA_BIN%" %OPENDJ_JAVA_ARGS% org.opends.server.tools.InstallDS -t
pause
exit /B 1
:noValidHomeWithArgs
echo ERROR: The detected Java version could not be used with the set of Java
echo arguments %OPENDJ_JAVA_ARGS%.
echo The detected Java binary is:
echo %OPENDJ_JAVA_BIN%
echo You must specify the path to a valid Java 6.0 update 10 or higher version.
echo The procedure to follow is:
echo 1. Delete the file %INSTANCE_ROOT%\lib\set-java-home.bat if it exists.
echo 2. Set the environment variable OPENDJ_JAVA_HOME to the root of a valid
echo Java 6.0 installation.
echo If you want to have specific Java settings for each command line you must
echo follow the steps 3 and 4.
echo 3. Edit the properties file specifying the Java binary and the Java arguments
echo for each command line. The Java properties file is located in:
echo %INSTANCE_ROOT%\config\java.properties.
echo 4. Run the command-line %INSTALL_ROOT%\bat\dsjavaproperties.bat
pause
exit /B 1
:isVersionOrHelp
if [%1] == [] goto check
if [%1] == [--help] goto end
if [%1] == [-H] goto end
if [%1] == [--version] goto end
if [%1] == [-V] goto end
if [%1] == [--fullversion] goto end
if [%1] == [-F] goto end
shift
goto isVersionOrHelp
:prepareCheck
rem Perform check unless it is specified not to do it
if "%NO_CHECK%" == "" set NO_CHECK=false
goto isVersionOrHelp
:check
if "%NO_CHECK%" == "true" goto end
if "%CHECK_VERSION%" == "true" set OPT_CHECK_VERSION=--checkVersion
"%OPENDJ_JAVA_BIN%" %SCRIPT_NAME_ARG% -DINSTALL_ROOT="%INSTALL_ROOT%" -DINSTANCE_ROOT="%INSTANCE_ROOT%" org.opends.server.tools.configurator.CheckInstance %OPT_CHECK_VERSION%
set RESULT_CODE=%errorlevel%
if "%RESULT_CODE%" == "0" goto end
exit /B 1
:end
exit /B 0