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