_script-util.sh revision 4108
0N/A#!/bin/sh
5266N/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# function that sets the java home
0N/A#
0N/Aset_java_home_and_args() {
0N/A if test -f "${INSTANCE_ROOT}/lib/set-java-home"
0N/A then
0N/A . "${INSTANCE_ROOT}/lib/set-java-home"
0N/A fi
0N/A if test -z "${OPENDS_JAVA_BIN}"
0N/A then
0N/A if test -z "${OPENDS_JAVA_HOME}"
0N/A then
0N/A if test -z "${JAVA_BIN}"
0N/A then
0N/A if test -z "${JAVA_HOME}"
0N/A then
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 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 exit 1
0N/A fi
0N/A else
0N/A OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
0N/A export OPENDS_JAVA_BIN
0N/A fi
0N/A else
0N/A OPENDS_JAVA_BIN="${JAVA_BIN}"
0N/A export OPENDS_JAVA_BIN
0N/A fi
0N/A else
0N/A OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
0N/A export OPENDS_JAVA_BIN
0N/A fi
5325N/A fi
5325N/A}
5325N/A
5325N/A# Determine whether the detected Java environment is acceptable for use.
0N/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=${?}
5325N/A if test ${RESULT_CODE} -eq 13
5325N/A then
5325N/A # This is a particular error code that means that the Java version is 5
5325N/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
5325N/A elif test ${RESULT_CODE} -ne 0
5325N/A then
5325N/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."
5325N/A echo "The procedure to follow is:"
5325N/A echo "1. Delete the file ${INSTANCE_ROOT}/lib/set-java-home" if it exists.
5325N/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:"
5325N/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:"
5325N/A echo "1. Delete the file ${INSTANCE_ROOT}/lib/set-java-home" if it exists.
5325N/A echo "2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid "
5325N/A echo "Java 5.0 installation."
5325N/A echo "If you want to have specific java settings for each command line you must"
5325N/A echo "follow the steps 3 and 4."
5325N/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"
5325N/A exit 1
5325N/A fi
0N/A fi
0N/A}
0N/A
5325N/A# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
5325N/A# system environment variables for security and compatibility reasons.
5325N/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=
5325N/A LD_PRELOAD_32=
5325N/A LD_PRELOAD_64=
5325N/A export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
5325N/A LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
5325N/A SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=${SCRIPT_NAME}
5325N/A export SCRIPT_NAME_ARG
5325N/A}
5325N/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
5325N/A do
5325N/A CLASSPATH=${CLASSPATH}:${JAR}
5325N/A done
5325N/A for JAR in ${INSTALL_ROOT}/lib/*.jar
0N/A do
0N/A CLASSPATH=${CLASSPATH}:${JAR}
0N/A done
0N/A if [ "${INSTANCE_ROOT}" != "${INSTANCE_ROOT}" ]
0N/A then
5325N/A for JAR in ${INSTANCE_ROOT}/lib/*.jar
5325N/A do
5325N/A CLASSPATH=${CLASSPATH}:${JAR}
5325N/A done
5325N/A fi
5325N/A export CLASSPATH
5325N/A}
5325N/A
5325N/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
5266N/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}"
5266N/Afi
5266N/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 INSTANCE_ROOT=`cat /etc/opends/instance.loc`
0N/A else
0N/A if [ "${SCRIPT_NAME}" != "configure" ]
0N/A then
5266N/A isVersionOrHelp $*
0N/A if [ $? -eq 1 ]
5266N/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 if cat ${INSTALL_ROOT}/instance.loc | grep '^/' > /dev/null
0N/A then
0N/A INSTANCE_ROOT=`cat ${INSTALL_ROOT}/instance.loc`
0N/A else
0N/A INSTANCE_ROOT=${INSTALL_ROOT}/`cat ${INSTALL_ROOT}/instance.loc`
0N/A fi
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`
cd "${INSTANCE_ROOT}"
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${CURRENT_DIR}"
fi
fi
if test "${SCRIPT_UTIL_CMD}" = "set-full-environment-and-test-java"
then
set_java_home_and_args
set_environment_vars
set_classpath
test_java
elif test "${SCRIPT_UTIL_CMD}" = "set-full-environment"
then
set_java_home_and_args
set_environment_vars
set_classpath
elif test "${SCRIPT_UTIL_CMD}" = "set-java-home-and-args"
then
set_java_home_and_args
elif test "${SCRIPT_UTIL_CMD}" = "set-environment-vars"
then
set_environment_vars
elif test "${SCRIPT_UTIL_CMD}" = "set-classpath"
then
set_classpath
elif test "${SCRIPT_UTIL_CMD}" = "test-java"
then
test_java
fi
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}" ${OPENDS_JAVA_ARGS} ${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 ${RETURN_CODE}
fi
fi
fi