_script-util.sh revision 62da52c144e8d6ba69f611c45deeeb4f985ea24c
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#!/bin/sh
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# CDDL HEADER START
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# The contents of this file are subject to the terms of the
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Common Development and Distribution License, Version 1.0 only
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# (the "License"). You may not use this file except in compliance
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# with the License.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# or http://forgerock.org/license/CDDLv1.0.html.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# See the License for the specific language governing permissions
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# and limitations under the License.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
923784d59ac065eee98b208dfacda6fbc24c71d6Jake Feasel# When distributing Covered Code, include this CDDL HEADER in each
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# file and include the License file at legal-notices/CDDLv1_0.txt.
4eb529f0471672590d77cf89ef23987ba2c95ff4Laszlo Hordos# If applicable, add the following below this CDDL HEADER, with the
4eb529f0471672590d77cf89ef23987ba2c95ff4Laszlo Hordos# fields enclosed by brackets "[]" replaced with your own identifying
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# information:
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Portions Copyright [yyyy] [name of copyright owner]
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# CDDL HEADER END
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Copyright 2008-2009 Sun Microsystems, Inc.
54f30b716553d88ea9ebb010037f4c74eb1d69acPaul Bryan
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos# function that sets the java home
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos#
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordosset_java_home_and_args() {
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos if test -f "${INSTANCE_ROOT}/lib/set-java-home"
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos then
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos . "${INSTANCE_ROOT}/lib/set-java-home"
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos fi
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos if test -z "${OPENDJ_JAVA_BIN}"
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos then
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos if test -z "${OPENDJ_JAVA_HOME}"
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos then
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos if test -z "${JAVA_BIN}"
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos then
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos if test -z "${JAVA_HOME}"
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos then
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos OPENDJ_JAVA_BIN=`which java 2> /dev/null`
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos if test ${?} -eq 0
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos then
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos export OPENDJ_JAVA_BIN
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos else
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos echo "Please set OPENDJ_JAVA_HOME to the root of a Java 5 (or later) installation"
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos echo "or edit the java.properties file and then run the dsjavaproperties script to"
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos echo "specify the Java version to be used"
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos exit 1
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos fi
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos else
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan OPENDJ_JAVA_BIN="${JAVA_HOME}/bin/java"
a14db14686bf9f6817c47e5c14e887d74dd615f0Laszlo Hordos export OPENDJ_JAVA_BIN
113939c1056403ed7d3bf33dd1b5d404e6838645Andi Egloff fi
f85a185a657def022f6d8896cc755403f7d40694Andi Egloff else
a14db14686bf9f6817c47e5c14e887d74dd615f0Laszlo Hordos OPENDJ_JAVA_BIN="${JAVA_BIN}"
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin export OPENDJ_JAVA_BIN
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin fi
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin else
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin OPENDJ_JAVA_BIN="${OPENDJ_JAVA_HOME}/bin/java"
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin export OPENDJ_JAVA_BIN
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin fi
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin fi
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin}
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos# system environment variables for security and compatibility reasons.
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordosset_environment_vars() {
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos PATH=/bin:/usr/bin
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos LD_LIBRARY_PATH=
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos LD_LIBRARY_PATH_32=
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos LD_LIBRARY_PATH_64=
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl LD_PRELOAD=
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos LD_PRELOAD_32=
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos LD_PRELOAD_64=
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos SCRIPT_NAME_ARG=-Dcom.forgerock.opendj.ldap.tools.scriptName=${SCRIPT_NAME}
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos export SCRIPT_NAME_ARG
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos}
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos# Configure the appropriate CLASSPATH.
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordosset_classpath() {
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos CLASSPATH=${INSTANCE_ROOT}/classes
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos for JAR in ${INSTALL_ROOT}/lib/*.jar
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos do
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos CLASSPATH=${CLASSPATH}:${JAR}
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos done
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos if [ "${INSTALL_ROOT}" != "${INSTANCE_ROOT}" ]
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos then
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos for JAR in ${INSTANCE_ROOT}/lib/*.jar
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos do
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos CLASSPATH=${CLASSPATH}:${JAR}
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos done
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos fi
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos export CLASSPATH
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos}
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlif test "${INSTALL_ROOT}" = ""
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlthen
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl # Capture the current working directory so that we can change to it later.
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl # Then capture the location of this script and the Directory Server instance
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos # root so that we can use them to create appropriate paths.
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos WORKING_DIR=`pwd`
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl cd "`dirname "${0}"`"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl cd ..
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl INSTALL_ROOT=`pwd`
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl cd "${WORKING_DIR}"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlfi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlif test "${SCRIPT_UTIL_CMD}" = "set-full-environment"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlthen
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl set_java_home_and_args
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl set_environment_vars
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl set_classpath
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlelif test "${SCRIPT_UTIL_CMD}" = "set-java-home-and-args"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlthen
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl set_java_home_and_args
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlelif test "${SCRIPT_UTIL_CMD}" = "set-environment-vars"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlthen
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl set_environment_vars
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlelif test "${SCRIPT_UTIL_CMD}" = "set-classpath"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlthen
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl set_classpath
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlfi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl