_script-util.sh revision 4915
0N/A#!/bin/sh
3909N/A#
0N/A# CDDL HEADER START
0N/A#
0N/A# The contents of this file are subject to the terms of the
0N/A# Common Development and Distribution License, Version 1.0 only
0N/A# (the "License"). You may not use this file except in compliance
0N/A# with the License.
0N/A#
0N/A# You can obtain a copy of the license at
0N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE
0N/A# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
0N/A# See the License for the specific language governing permissions
0N/A# and limitations under the License.
0N/A#
0N/A# When distributing Covered Code, include this CDDL HEADER in each
0N/A# file and include the License file at
0N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2362N/A# add the following below this CDDL HEADER, with the fields enclosed
2362N/A# by brackets "[]" replaced with your own identifying information:
2362N/A# Portions Copyright [yyyy] [name of copyright owner]
0N/A#
0N/A# CDDL HEADER END
0N/A#
0N/A#
0N/A# Copyright 2008-2009 Sun Microsystems, Inc.
0N/A
0N/A#
0N/A# Display an error message
0N/A#
0N/Adisplay_java_not_found_error() {
0N/A echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation"
0N/A echo "or edit the java.properties file and then run the dsjavaproperties script to"
0N/A echo "specify the Java version to be used"
0N/A}
0N/A
0N/A#
0N/A# function that tests the JAVA_HOME env variable.
0N/A#
0N/Atest_java_home() {
0N/A if test -z "${JAVA_HOME}"
0N/A then
0N/A display_java_not_found_error
0N/A exit 1
0N/A else
0N/A OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
0N/A if test -f "${OPENDS_JAVA_BIN}"
0N/A then
0N/A export OPENDS_JAVA_BIN
0N/A else
0N/A display_java_not_found_error
0N/A exit 1
0N/A fi
0N/A fi
0N/A}
0N/A
0N/A#
0N/A# function that tests the JAVA_BIN env variable.
0N/A#
0N/Atest_java_bin() {
0N/A if test -z "${JAVA_BIN}"
0N/A then
0N/A test_java_home
0N/A else
0N/A OPENDS_JAVA_BIN="${JAVA_BIN}"
0N/A if test -f "${OPENDS_JAVA_BIN}"
0N/A then
0N/A export OPENDS_JAVA_BIN
0N/A else
0N/A test_java_home
0N/A fi
0N/A fi
0N/A}
0N/A
0N/A#
0N/A# function that tests the java executable in the PATH env variable.
0N/A#
0N/Atest_java_path() {
0N/A OPENDS_JAVA_BIN=`which java 2> /dev/null`
0N/A if test ${?} -eq 0
0N/A then
0N/A export OPENDS_JAVA_BIN
0N/A else
0N/A test_java_bin
0N/A fi
0N/A}
0N/A
0N/A#
0N/A# function that tests the OPENDS_JAVA_HOME env variable.
0N/A#
0N/Atest_opends_java_home() {
0N/A if test -z "${OPENDS_JAVA_HOME}"
0N/A then
0N/A test_java_path
0N/A else
0N/A OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
0N/A if test -f "${OPENDS_JAVA_BIN}"
0N/A then
0N/A export OPENDS_JAVA_BIN
0N/A else
0N/A test_java_path
0N/A fi
0N/A fi
0N/A}
0N/A
0N/A#
0N/A# function that tests the OPENDS_JAVA_BIN env variable.
0N/A#
0N/Atest_opends_java_bin() {
3323N/A if test -z "${OPENDS_JAVA_BIN}"
0N/A then
0N/A test_opends_java_home
0N/A else
0N/A if test -f "${OPENDS_JAVA_BIN}"
0N/A then
0N/A export OPENDS_JAVA_BIN
0N/A else
0N/A test_opends_java_home
0N/A fi
0N/A fi
3646N/A}
3646N/A
3646N/A#
3646N/A# function that sets the java home
3646N/A#
0N/Aset_java_home_and_args() {
3646N/A if test -f "${INSTANCE_ROOT}/lib/set-java-home"
3646N/A then
3646N/A . "${INSTANCE_ROOT}/lib/set-java-home"
3646N/A fi
3646N/A test_opends_java_bin
3646N/A}
3646N/A
3646N/A
3646N/A# Determine whether the detected Java environment is acceptable for use.
3646N/Atest_java() {
0N/A if test -z "${OPENDS_JAVA_ARGS}"
0N/A then
0N/A "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
0N/A RESULT_CODE=${?}
0N/A if test ${RESULT_CODE} -eq 13
0N/A then
0N/A # This is a particular error code that means that the Java version is 5
0N/A # but not supported. Let InstallDS to display the localized error message
0N/A "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t
0N/A exit 1
0N/A elif test ${RESULT_CODE} -ne 0
0N/A then
0N/A echo "ERROR: The detected Java version could not be used. The detected"
0N/A echo "Java binary is:"
0N/A echo "${OPENDS_JAVA_BIN}"
0N/A echo "You must specify the path to a valid Java 5.0 or higher version."
0N/A echo "The procedure to follow is:"
0N/A echo "1. Delete the file ${INSTANCE_ROOT}/lib/set-java-home" if it exists.
0N/A echo "2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid "
0N/A echo "Java 5.0 installation."
0N/A echo "If you want to have specific Java settings for each command line you must"
0N/A echo "follow the steps 3 and 4."
0N/A echo "3. Edit the properties file specifying the Java binary and the Java arguments"
0N/A echo "for each command line. The Java properties file is located in:"
0N/A echo "${INSTANCE_ROOT}/config/java.properties."
0N/A echo "4. Run the command-line ${INSTANCE_ROOT}/bin/dsjavaproperties"
0N/A exit 1
0N/A fi
0N/A else
0N/A "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
0N/A RESULT_CODE=${?}
0N/A if test ${RESULT_CODE} -eq 13
0N/A then
0N/A # This is a particular error code that means that the Java version is 5
0N/A # but not supported. Let InstallDS to display the localized error message
0N/A "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t
0N/A exit 1
0N/A elif test ${RESULT_CODE} -ne 0
0N/A then
0N/A echo "ERROR: The detected Java version could not be used with the set of Java"
0N/A echo "arguments ${OPENDS_JAVA_ARGS}."
0N/A echo "The detected Java binary is:"
0N/A echo "${OPENDS_JAVA_BIN}"
0N/A echo "You must specify the path to a valid Java 5.0 or higher version."
0N/A echo "The procedure to follow is:"
0N/A echo "1. Delete the file ${INSTANCE_ROOT}/lib/set-java-home" if it exists.
0N/A echo "2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid "
0N/A echo "Java 5.0 installation."
0N/A echo "If you want to have specific Java settings for each command line you must"
0N/A echo "follow the steps 3 and 4."
0N/A echo "3. Edit the properties file specifying the Java binary and the Java arguments"
0N/A echo "for each command line. The Java properties file is located in:"
0N/A echo "${INSTANCE_ROOT}/config/java.properties."
0N/A echo "4. Run the command-line ${INSTANCE_ROOT}/bin/dsjavaproperties"
0N/A exit 1
0N/A fi
0N/A fi
0N/A}
0N/A
0N/A# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
0N/A# system environment variables for security and compatibility reasons.
0N/Aset_environment_vars() {
0N/A PATH=/bin:/usr/bin
0N/A LD_LIBRARY_PATH=
0N/A LD_LIBRARY_PATH_32=
0N/A LD_LIBRARY_PATH_64=
0N/A LD_PRELOAD=
0N/A LD_PRELOAD_32=
0N/A LD_PRELOAD_64=
0N/A export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
0N/A LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
0N/A SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=${SCRIPT_NAME}
0N/A export SCRIPT_NAME_ARG
0N/A}
0N/A
0N/A# Configure the appropriate CLASSPATH.
0N/Aset_classpath() {
0N/A CLASSPATH="${INSTANCE_ROOT}/classes"
0N/A for JAR in "${INSTALL_ROOT}/resources/"*.jar
0N/A do
0N/A CLASSPATH=${CLASSPATH}:${JAR}
0N/A done
0N/A for JAR in "${INSTALL_ROOT}/lib/"*.jar
0N/A do
0N/A CLASSPATH=${CLASSPATH}:${JAR}
0N/A done
0N/A if [ "${INSTALL_ROOT}" != "${INSTANCE_ROOT}" ]
0N/A then
0N/A for JAR in "${INSTANCE_ROOT}/lib/"*.jar
0N/A do
0N/A CLASSPATH=${CLASSPATH}:${JAR}
0N/A done
0N/A fi
0N/A export CLASSPATH
0N/A}
0N/A
0N/AisVersionOrHelp() {
0N/A for opt in `echo $*`
0N/A do
0N/A if [ $opt = "-V" ] || [ $opt = "--version" ] ||
0N/A [ $opt = "-H" ] || [ $opt = "--help" ] ||
0N/A [ $opt = "-F" ] || [ $opt = "--fullversion" ]
0N/A then
0N/A return 0
0N/A fi
0N/A done
0N/A return 1
0N/A}
0N/A
0N/Aif test "${INSTALL_ROOT}" = ""
0N/Athen
0N/A # Capture the current working directory so that we can change to it later.
0N/A # Then capture the location of this script and the Directory Server instance
0N/A # root so that we can use them to create appropriate paths.
0N/A WORKING_DIR=`pwd`
0N/A
0N/A cd "`dirname "${0}"`"
0N/A cd ..
0N/A INSTALL_ROOT=`pwd`
0N/A cd "${WORKING_DIR}"
0N/Afi
0N/A
0N/Aif test "${INSTANCE_ROOT}" = ""
0N/Athen
0N/A if [ -f "${INSTALL_ROOT}/configure" ]
0N/A then
0N/A if [ -f /etc/opends/instance.loc ]
0N/A then
0N/A if [ "${SCRIPT_NAME}" = "configure" ]
0N/A then
0N/A isVersionOrHelp $*
0N/A if [ $? -eq 1 ]
0N/A then
0N/A echo "${INSTALL_ROOT}/configure has already been run. Exiting."
0N/A exit 0
0N/A fi
0N/A fi
0N/A read INSTANCE_ROOT < /etc/opends/instance.loc
0N/A else
0N/A if [ "${SCRIPT_NAME}" != "configure" ]
0N/A then
0N/A isVersionOrHelp $*
0N/A if [ $? -eq 1 ]
0N/A then
0N/A echo "No instance found. Run ${INSTALL_ROOT}/configure to create it."
0N/A exit 1
0N/A fi
0N/A fi
0N/A fi
0N/A else
0N/A if [ -f "${INSTALL_ROOT}/instance.loc" ]
0N/A then
0N/A read location < ${INSTALL_ROOT}/instance.loc
0N/A case `echo ${location}` in
0N/A /*)
0N/A INSTANCE_ROOT=${location}
0N/A break
0N/A ;;
0N/A *)
0N/A INSTANCE_ROOT=${INSTALL_ROOT}/${location}
0N/A break
0N/A ;;
0N/A esac
0N/A else
0N/A INSTANCE_ROOT=${INSTALL_ROOT}
0N/A fi
0N/A fi
0N/A if [ -d "${INSTANCE_ROOT}" ]
0N/A then
0N/A CURRENT_DIR=`pwd`
0N/A cd "${INSTANCE_ROOT}"
0N/A INSTANCE_ROOT=`pwd`
0N/A export INSTANCE_ROOT
0N/A cd "${CURRENT_DIR}"
0N/A fi
0N/Afi
0N/A
0N/Aif test "${SCRIPT_UTIL_CMD}" = "set-full-environment-and-test-java"
0N/Athen
0N/A set_java_home_and_args
0N/A set_environment_vars
0N/A set_classpath
0N/A test_java
0N/Aelif test "${SCRIPT_UTIL_CMD}" = "set-full-environment"
0N/Athen
0N/A set_java_home_and_args
0N/A set_environment_vars
0N/A set_classpath
0N/A elif test "${SCRIPT_UTIL_CMD}" = "set-java-home-and-args"
0N/Athen
0N/A set_java_home_and_args
0N/Aelif test "${SCRIPT_UTIL_CMD}" = "set-environment-vars"
0N/Athen
0N/A set_environment_vars
0N/Aelif test "${SCRIPT_UTIL_CMD}" = "set-classpath"
0N/Athen
0N/A set_classpath
0N/Aelif test "${SCRIPT_UTIL_CMD}" = "test-java"
0N/Athen
0N/A test_java
0N/Afi
0N/A
0N/Acurrent_user()
0N/A{
0N/AUSER=`id`
0N/ACURRENT_IFS=${IFS}
0N/AIFS="()"
0N/Aset -- ${USER}
0N/Aecho $2
0N/AIFS=${CURRENT_IFS}
0N/A}
0N/A
0N/Aif [ "${SCRIPT_NAME}" != "configure" ] && [ "${SCRIPT_NAME}" != "unconfigure" ]
0N/Athen
0N/A # Perform check unless it is specified not to do it
0N/A if [ -z "$NO_CHECK" ]
0N/A then
0N/A NO_CHECK=0
0N/A fi
0N/A if [ ${NO_CHECK} -eq 0 ]
0N/A then
0N/A # No check for --version or --help option
0N/A isVersionOrHelp $*
0N/A if [ $? -eq 0 ]
0N/A then
0N/A NO_CHECK=1
0N/A fi
0N/A fi
0N/A if [ ${NO_CHECK} -eq 0 ]
0N/A then
0N/A set_classpath
0N/A # Check instance
0N/A CURRENT_USER="`current_user`"
0N/A if [ "${CHECK_VERSION}" = "yes" ]
0N/A then
0N/A OPT_CHECK_VERSION="--checkVersion"
0N/A else
0N/A OPT_CHECK_VERSION=""
0N/A fi
0N/A # Launch the CheckInstance process.
0N/A "${OPENDS_JAVA_BIN}" ${SCRIPT_NAME_ARG} "-DINSTALL_ROOT=${INSTALL_ROOT}" "-DINSTANCE_ROOT=${INSTANCE_ROOT}" org.opends.server.tools.configurator.CheckInstance --currentUser ${CURRENT_USER} ${OPT_CHECK_VERSION}
0N/A # return part
0N/A RETURN_CODE=$?
0N/A if [ ${RETURN_CODE} -ne 0 ]
0N/A then
0N/A exit 1
0N/A fi
0N/A fi
0N/Afi
0N/A