2976N/A#!/bin/sh
2976N/A#
2976N/A# CDDL HEADER START
2976N/A#
2976N/A# The contents of this file are subject to the terms of the
2976N/A# Common Development and Distribution License, Version 1.0 only
2976N/A# (the "License"). You may not use this file except in compliance
2976N/A# with the License.
2976N/A#
2976N/A# You can obtain a copy of the license at
2976N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE
2976N/A# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2976N/A# See the License for the specific language governing permissions
2976N/A# and limitations under the License.
2976N/A#
2976N/A# When distributing Covered Code, include this CDDL HEADER in each
2976N/A# file and include the License file at
2976N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2976N/A# add the following below this CDDL HEADER, with the fields enclosed
2976N/A# by brackets "[]" replaced with your own identifying information:
2976N/A# Portions Copyright [yyyy] [name of copyright owner]
2976N/A#
2976N/A# CDDL HEADER END
2976N/A#
2976N/A#
5022N/A# Copyright 2008-2010 Sun Microsystems, Inc.
6238N/A# Portions Copyright 2010-2013 ForgeRock AS
2976N/A
2976N/A#
4915N/A# Display an error message
4915N/A#
4915N/Adisplay_java_not_found_error() {
5636N/A echo "Please set OPENDJ_JAVA_HOME to the root of a Java 6 update 10 (or higher) installation"
4915N/A echo "or edit the java.properties file and then run the dsjavaproperties script to"
4915N/A echo "specify the Java version to be used"
4915N/A}
4915N/A
4915N/A#
4915N/A# function that tests the JAVA_HOME env variable.
4915N/A#
4915N/Atest_java_home() {
4915N/A if test -z "${JAVA_HOME}"
4915N/A then
4915N/A display_java_not_found_error
4915N/A exit 1
4915N/A else
5636N/A OPENDJ_JAVA_BIN="${JAVA_HOME}/bin/java"
5636N/A if test -f "${OPENDJ_JAVA_BIN}"
4915N/A then
5636N/A export OPENDJ_JAVA_BIN
4915N/A else
4915N/A display_java_not_found_error
4915N/A exit 1
4915N/A fi
4915N/A fi
4915N/A}
4915N/A
4915N/A#
4915N/A# function that tests the JAVA_BIN env variable.
4915N/A#
4915N/Atest_java_bin() {
4915N/A if test -z "${JAVA_BIN}"
4915N/A then
4915N/A test_java_home
4915N/A else
5636N/A OPENDJ_JAVA_BIN="${JAVA_BIN}"
5636N/A if test -f "${OPENDJ_JAVA_BIN}"
4915N/A then
5636N/A export OPENDJ_JAVA_BIN
4915N/A else
4915N/A test_java_home
4915N/A fi
4915N/A fi
4915N/A}
4915N/A
4915N/A#
4915N/A# function that tests the java executable in the PATH env variable.
4915N/A#
4915N/Atest_java_path() {
5636N/A OPENDJ_JAVA_BIN=`which java 2> /dev/null`
5636N/A if test -f "${OPENDJ_JAVA_BIN}"
4915N/A then
5636N/A export OPENDJ_JAVA_BIN
4915N/A else
4915N/A test_java_bin
4915N/A fi
4915N/A}
4915N/A
4915N/A#
5636N/A# function that tests legacy OPENDS_JAVA_HOME env variable.
4915N/A#
4915N/Atest_opends_java_home() {
4915N/A if test -z "${OPENDS_JAVA_HOME}"
4915N/A then
4915N/A test_java_path
4915N/A else
5636N/A OPENDJ_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
5636N/A if test -f "${OPENDJ_JAVA_BIN}"
4915N/A then
5636N/A export OPENDJ_JAVA_BIN
4915N/A else
4915N/A test_java_path
4915N/A fi
4915N/A fi
4915N/A}
4915N/A
4915N/A#
5636N/A# function that tests the OPENDJ_JAVA_HOME env variable.
4915N/A#
5636N/Atest_opendj_java_home() {
5636N/A if test -z "${OPENDJ_JAVA_HOME}"
4915N/A then
4915N/A test_opends_java_home
4915N/A else
5636N/A OPENDJ_JAVA_BIN="${OPENDJ_JAVA_HOME}/bin/java"
5636N/A if test -f "${OPENDJ_JAVA_BIN}"
4915N/A then
5636N/A export OPENDJ_JAVA_BIN
5636N/A else
5636N/A test_java_path
5636N/A fi
5636N/A fi
5636N/A}
5636N/A
5636N/A#
5636N/A# function that tests the OPENDJ_JAVA_BIN env variable.
5636N/A#
5636N/Atest_opendj_java_bin() {
5636N/A if test -z "${OPENDJ_JAVA_BIN}"
5636N/A then
5636N/A # Check for legacy OPENDS_JAVA_BIN
5636N/A if test -z "${OPENDS_JAVA_BIN}"
5636N/A then
5636N/A test_opendj_java_home
5636N/A else
5636N/A if test -f "${OPENDS_JAVA_BIN}"
5636N/A then
5636N/A OPENDJ_JAVA_BIN="${OPENDS_JAVA_BIN}"
5636N/A export OPENDJ_JAVA_BIN
5636N/A else
5636N/A test_opendj_java_home
5636N/A fi
5636N/A fi
5636N/A else
5636N/A if test -f "${OPENDJ_JAVA_BIN}"
5636N/A then
5636N/A export OPENDJ_JAVA_BIN
4915N/A else
4915N/A test_opends_java_home
4915N/A fi
4915N/A fi
4915N/A}
4915N/A
4915N/A#
2976N/A# function that sets the java home
2976N/A#
2976N/Aset_java_home_and_args() {
2976N/A if test -f "${INSTANCE_ROOT}/lib/set-java-home"
2976N/A then
2976N/A . "${INSTANCE_ROOT}/lib/set-java-home"
3009N/A fi
5636N/A test_opendj_java_bin
2976N/A}
2976N/A
5636N/A# Function that sets OPENDJ_JAVA_ARGS if not yet set but OPENDS_JAVA_ARGS is.
5636N/Atest_java_args() {
5636N/A if test -z "${OPENDJ_JAVA_ARGS}"
5636N/A then
5636N/A if test -n "${OPENDS_JAVA_ARGS}"
5636N/A then
5636N/A OPENDJ_JAVA_ARGS="${OPENDS_JAVA_ARGS}"
5636N/A export OPENDJ_JAVA_ARGS
5636N/A fi
5636N/A fi
5636N/A}
4915N/A
4243N/A# Determine whether the detected Java environment is acceptable for use.
2976N/Atest_java() {
5636N/A if test -z "${OPENDJ_JAVA_ARGS}"
2976N/A then
5636N/A "${OPENDJ_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
3449N/A RESULT_CODE=${?}
3449N/A if test ${RESULT_CODE} -eq 13
3449N/A then
5218N/A # This is a particular error code that means that the Java version is 6
3449N/A # but not supported. Let InstallDS to display the localized error message
5636N/A "${OPENDJ_JAVA_BIN}" org.opends.server.tools.InstallDS -t
3449N/A exit 1
3449N/A elif test ${RESULT_CODE} -ne 0
2976N/A then
2976N/A echo "ERROR: The detected Java version could not be used. The detected"
4261N/A echo "Java binary is:"
5636N/A echo "${OPENDJ_JAVA_BIN}"
5224N/A echo "You must specify the path to a valid Java 6.0 update 10 or higher version."
2976N/A echo "The procedure to follow is:"
2976N/A echo "1. Delete the file ${INSTANCE_ROOT}/lib/set-java-home" if it exists.
5636N/A echo "2. Set the environment variable OPENDJ_JAVA_HOME to the root of a valid "
5218N/A echo "Java 6.0 installation."
4261N/A echo "If you want to have specific Java settings for each command line you must"
2976N/A echo "follow the steps 3 and 4."
4261N/A echo "3. Edit the properties file specifying the Java binary and the Java arguments"
4261N/A echo "for each command line. The Java properties file is located in:"
2976N/A echo "${INSTANCE_ROOT}/config/java.properties."
2976N/A echo "4. Run the command-line ${INSTANCE_ROOT}/bin/dsjavaproperties"
2976N/A exit 1
2976N/A fi
2976N/A else
5636N/A "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
3449N/A RESULT_CODE=${?}
3449N/A if test ${RESULT_CODE} -eq 13
3449N/A then
5218N/A # This is a particular error code that means that the Java version is 6
3449N/A # but not supported. Let InstallDS to display the localized error message
5636N/A "${OPENDJ_JAVA_BIN}" org.opends.server.tools.InstallDS -t
3449N/A exit 1
3449N/A elif test ${RESULT_CODE} -ne 0
2976N/A then
4261N/A echo "ERROR: The detected Java version could not be used with the set of Java"
5636N/A echo "arguments ${OPENDJ_JAVA_ARGS}."
4261N/A echo "The detected Java binary is:"
5636N/A echo "${OPENDJ_JAVA_BIN}"
5224N/A echo "You must specify the path to a valid Java 6.0 update 10 or higher version."
2976N/A echo "The procedure to follow is:"
2976N/A echo "1. Delete the file ${INSTANCE_ROOT}/lib/set-java-home" if it exists.
5636N/A echo "2. Set the environment variable OPENDJ_JAVA_HOME to the root of a valid "
5218N/A echo "Java 6.0 installation."
4261N/A echo "If you want to have specific Java settings for each command line you must"
2976N/A echo "follow the steps 3 and 4."
4261N/A echo "3. Edit the properties file specifying the Java binary and the Java arguments"
4261N/A echo "for each command line. The Java properties file is located in:"
2976N/A echo "${INSTANCE_ROOT}/config/java.properties."
2976N/A echo "4. Run the command-line ${INSTANCE_ROOT}/bin/dsjavaproperties"
2976N/A exit 1
2976N/A fi
2976N/A fi
2976N/A}
2976N/A
2976N/A# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
2976N/A# system environment variables for security and compatibility reasons.
2976N/Aset_environment_vars() {
2976N/A PATH=/bin:/usr/bin
2976N/A LD_LIBRARY_PATH=
2976N/A LD_LIBRARY_PATH_32=
2976N/A LD_LIBRARY_PATH_64=
2976N/A LD_PRELOAD=
2976N/A LD_PRELOAD_32=
2976N/A LD_PRELOAD_64=
2976N/A export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
4243N/A LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
2976N/A SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=${SCRIPT_NAME}
2976N/A export SCRIPT_NAME_ARG
2976N/A}
2976N/A
2976N/A# Configure the appropriate CLASSPATH.
2976N/Aset_classpath() {
4883N/A CLASSPATH="${INSTANCE_ROOT}/classes"
4883N/A for JAR in "${INSTALL_ROOT}/resources/"*.jar
4108N/A do
4108N/A CLASSPATH=${CLASSPATH}:${JAR}
4108N/A done
6256N/A CLASSPATH="${CLASSPATH}:${INSTALL_ROOT}/lib/bootstrap.jar"
4392N/A if [ "${INSTALL_ROOT}" != "${INSTANCE_ROOT}" ]
3824N/A then
4883N/A for JAR in "${INSTANCE_ROOT}/lib/"*.jar
3824N/A do
3824N/A CLASSPATH=${CLASSPATH}:${JAR}
3824N/A done
3824N/A fi
2976N/A export CLASSPATH
2976N/A}
2976N/A
3885N/AisVersionOrHelp() {
3885N/A for opt in `echo $*`
3885N/A do
4243N/A if [ $opt = "-V" ] || [ $opt = "--version" ] ||
3885N/A [ $opt = "-H" ] || [ $opt = "--help" ] ||
3885N/A [ $opt = "-F" ] || [ $opt = "--fullversion" ]
3885N/A then
3885N/A return 0
3885N/A fi
3885N/A done
4243N/A return 1
3885N/A}
3885N/A
3824N/Aif test "${INSTALL_ROOT}" = ""
2976N/Athen
2976N/A # Capture the current working directory so that we can change to it later.
2976N/A # Then capture the location of this script and the Directory Server instance
2976N/A # root so that we can use them to create appropriate paths.
2976N/A WORKING_DIR=`pwd`
2976N/A
3488N/A cd "`dirname "${0}"`"
2976N/A cd ..
3824N/A INSTALL_ROOT=`pwd`
3860N/A cd "${WORKING_DIR}"
3860N/Afi
3860N/A
3860N/Aif test "${INSTANCE_ROOT}" = ""
3860N/Athen
4883N/A if [ -f "${INSTALL_ROOT}/configure" ]
3824N/A then
5306N/A if [ -f /etc/opendj/instance.loc ]
4243N/A then
3860N/A if [ "${SCRIPT_NAME}" = "configure" ]
3860N/A then
4103N/A isVersionOrHelp $*
4103N/A if [ $? -eq 1 ]
4103N/A then
4103N/A echo "${INSTALL_ROOT}/configure has already been run. Exiting."
4103N/A exit 0
4103N/A fi
4243N/A fi
5306N/A read INSTANCE_ROOT < /etc/opendj/instance.loc
3860N/A else
3860N/A if [ "${SCRIPT_NAME}" != "configure" ]
3860N/A then
3885N/A isVersionOrHelp $*
3885N/A if [ $? -eq 1 ]
3885N/A then
3885N/A echo "No instance found. Run ${INSTALL_ROOT}/configure to create it."
3885N/A exit 1
3885N/A fi
3860N/A fi
3860N/A fi
3824N/A else
4883N/A if [ -f "${INSTALL_ROOT}/instance.loc" ]
3860N/A then
4282N/A read location < ${INSTALL_ROOT}/instance.loc
4282N/A case `echo ${location}` in
4282N/A /*)
4282N/A INSTANCE_ROOT=${location}
4282N/A ;;
4282N/A *)
4282N/A INSTANCE_ROOT=${INSTALL_ROOT}/${location}
4282N/A ;;
4282N/A esac
3860N/A else
3860N/A INSTANCE_ROOT=${INSTALL_ROOT}
3860N/A fi
3824N/A fi
3860N/A if [ -d "${INSTANCE_ROOT}" ]
3860N/A then
3932N/A CURRENT_DIR=`pwd`
3932N/A cd "${INSTANCE_ROOT}"
3860N/A INSTANCE_ROOT=`pwd`
3860N/A export INSTANCE_ROOT
3932N/A cd "${CURRENT_DIR}"
3860N/A fi
2976N/Afi
2976N/A
2976N/Aif test "${SCRIPT_UTIL_CMD}" = "set-full-environment-and-test-java"
2976N/Athen
2976N/A set_java_home_and_args
2976N/A set_environment_vars
2976N/A set_classpath
5636N/A test_java_args
2976N/A test_java
2976N/Aelif test "${SCRIPT_UTIL_CMD}" = "set-full-environment"
2976N/Athen
2976N/A set_java_home_and_args
2976N/A set_environment_vars
2976N/A set_classpath
4883N/A elif test "${SCRIPT_UTIL_CMD}" = "set-java-home-and-args"
2976N/Athen
2976N/A set_java_home_and_args
2976N/Aelif test "${SCRIPT_UTIL_CMD}" = "set-environment-vars"
2976N/Athen
2976N/A set_environment_vars
2976N/Aelif test "${SCRIPT_UTIL_CMD}" = "set-classpath"
2976N/Athen
2976N/A set_classpath
2976N/Aelif test "${SCRIPT_UTIL_CMD}" = "test-java"
2976N/Athen
2976N/A test_java
2976N/Afi
3860N/A