_script-util.sh revision 2976
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#
2976N/A# Portions Copyright 2007 Sun Microsystems, Inc.
2976N/A
2976N/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"
2976N/A elif test -z "${OPENDS_JAVA_BIN}"
2976N/A then
2976N/A if test -z "${OPENDS_JAVA_HOME}"
2976N/A then
2976N/A if test -z "${JAVA_BIN}"
2976N/A then
2976N/A if test -z "${JAVA_HOME}"
2976N/A then
2976N/A OPENDS_JAVA_BIN=`which java 2> /dev/null`
2976N/A if test ${?} -eq 0
2976N/A then
2976N/A export OPENDS_JAVA_BIN
2976N/A else
2976N/A echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation"
2976N/A echo "or edit the java.properties file and then run the dsjavaproperties script to"
2976N/A echo "specify the java version to be used"
2976N/A exit 1
2976N/A fi
2976N/A else
2976N/A OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
2976N/A export OPENDS_JAVA_BIN
2976N/A fi
2976N/A else
2976N/A OPENDS_JAVA_BIN="${JAVA_BIN}"
2976N/A export OPENDS_JAVA_BIN
2976N/A fi
2976N/A else
2976N/A OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
2976N/A export OPENDS_JAVA_BIN
2976N/A fi
2976N/A fi
2976N/A}
2976N/A
2976N/A# Determine whether the detected Java environment is acceptable for use.
2976N/Atest_java() {
2976N/A if test -z "${OPENDS_JAVA_ARGS}"
2976N/A then
2976N/A "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
2976N/A if test ${?} -ne 0
2976N/A then
2976N/A echo "ERROR: The detected Java version could not be used. The detected"
2976N/A echo "java binary is:"
2976N/A echo "${OPENDS_JAVA_BIN}"
2976N/A echo "You must specify the path to a valid Java 5.0 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.
2976N/A echo "2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid "
2976N/A echo "Java 5.0 installation."
2976N/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."
2976N/A echo "3. Edit the properties file specifying the java binary and the java arguments"
2976N/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
2976N/A "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
2976N/A if test ${?} -ne 0
2976N/A then
2976N/A echo "ERROR: The detected Java version could not be used with the set of java"
2976N/A echo "arguments ${OPENDS_JAVA_ARGS}."
2976N/A echo "The detected java binary is:"
2976N/A echo "${OPENDS_JAVA_BIN}"
2976N/A echo "You must specify the path to a valid Java 5.0 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.
2976N/A echo "2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid "
2976N/A echo "Java 5.0 installation."
2976N/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."
2976N/A echo "3. Edit the properties file specifying the java binary and the java arguments"
2976N/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 \
2976N/A LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
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() {
2976N/A CLASSPATH=${INSTANCE_ROOT}/classes
2976N/A for JAR in ${INSTANCE_ROOT}/lib/*.jar
2976N/A do
2976N/A CLASSPATH=${CLASSPATH}:${JAR}
2976N/A done
2976N/A export CLASSPATH
2976N/A}
2976N/A
2976N/Aif test "${INSTANCE_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
2976N/A cd `dirname "${0}"`
2976N/A cd ..
2976N/A INSTANCE_ROOT=`pwd`
2976N/A cd "${WORKING_DIR}"
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
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
2976N/Aelif 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