OpenGrok revision 1338
1056N/A#!/bin/sh
1056N/A#
1056N/A# OpenGrok Wrapper (initial setup and cron job updating)
1056N/A#
1276N/A# Supported Operating Systems:
1056N/A# - Solaris 10 (SunOS 5.10)
1056N/A# - Solaris 11 (SunOS 5.11)
1056N/A# - Debian (Linux)
1056N/A#
1056N/A# Supported Deployment Engines:
1056N/A# - Tomcat 6
1056N/A# - Tomcat 5.5
1056N/A# - Glassfish
1056N/A#
1056N/A# Supported Environment Variables:
1056N/A# - OPENGROK_NON_INTERACTIVE Suppress Progress and Warnings Messages (*)
1276N/A# - OPENGROK_STANDARD_ENV Run Time Shell Environment (Shell Script)
1056N/A# - OPENGROK_CONFIGURATION User Configuration (Shell Script)
1056N/A#
1056N/A# Supported Environment Variables for configuring the default setup:
1056N/A# - OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution
1056N/A# - OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area
1056N/A# - EXUBERANT_CTAGS Full Path to Exuberant CTags
1056N/A# - JAVA_HOME Full Path to Java Installation Root
1056N/A# - OPENGROK_APP_SERVER Application Server ("Tomcat" or "Glassfish")
1056N/A# - OPENGROK_WAR_TARGET_TOMCAT Tomcat Specific WAR Target Directory
1056N/A# - OPENGROK_WAR_TARGET_GLASSFISH Glassfish Specific WAR Target Directory
1056N/A# - OPENGROK_WAR_TARGET Fallback WAR Target Directory
1056N/A# - OPENGROK_TOMCAT_BASE Base Directory for Tomcat (contains webapps)
1056N/A# - OPENGROK_GLASSFISH_BASE Base Directory for Glassfish
1056N/A# (contains domains)
1056N/A# - OPENGROK_GLASSFISH_DOMAIN Preferred Glassfish Domain Name
1056N/A# - OPENGROK_VERBOSE Enable Verbose Mode in opengrok.jar (*)
1056N/A# - OPENGROK_PROGRESS Shows progress in %(percentage) of working
1056N/A# through project, it's good to have Verbose
1056N/A# Mode enabled too, cost of this is one more
1056N/A# traversal of the project before indexing it(*)
1056N/A# - OPENGROK_REMOTE_REPOS Disable History Cache for (remote)
1056N/A# Repositories (*)
1056N/A# - OPENGROK_SCAN_REPOS Disable Scan for repositories (*)
1056N/A# - OPENGROK_SCAN_DEPTH how deep should scanning for repos go
1056N/A# (by default 3 directories from SRC_ROOT)
1056N/A# - OPENGROK_WEBAPP_CFGADDR Web app address to send configuration to
1056N/A# (use "none" to avoid sending it to web app)
1056N/A# - OPENGROK_WPREFIX Disable wildcard prefix search query
1056N/A# support (*)
1056N/A# - OPENGROK_DERBY if set, then indexer tries to use derby as
1056N/A# historycache (see derby command of this
1056N/A# script)
1056N/A# - READ_XML_CONFIGURATION file with read only configuration
1056N/A# - temporary workaround for bug # 327
1056N/A#
1056N/A# Notes:
1056N/A# (*) Any Non-Empty String will enable these options
1056N/A#
1056N/A
1056N/A#
1056N/A# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
1056N/A#
1056N/A
1056N/A#
1056N/A# Print usage to stderr and exit.
1056N/A#
1056N/AUsage()
1056N/A{
1056N/A progname=`basename $0`
1056N/A
1056N/A exec >&2
1056N/A echo ""
1056N/A echo "Usage: ${progname} <deploy|derby|update|updateQuietly|usage>"
1056N/A echo " ${progname} index [<directory>]"
1056N/A echo ""
1056N/A echo " Optional environment variables:"
1056N/A echo " OPENGROK_CONFIGURATION - location of your configuration"
1056N/A echo " e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf ${0} ... "
1056N/A echo ""
1056N/A echo " See the code for more information on configuration options /" \
1056N/A "variables"
1056N/A echo ""
1056N/A
1056N/A exit 1
1056N/A}
1056N/A
1056N/A#
1056N/A# Runtime Configuration
1056N/A#
1056N/Aif [ -f "/bin/uname" ]
1056N/Athen
1056N/A OS_NAME="`/bin/uname -s`"
1056N/A OS_VERSION="`/bin/uname -r`"
1056N/Aelse
1056N/A OS_NAME="`/usr/bin/uname -s`"
1056N/A OS_VERSION="`/usr/bin/uname -r`"
1056N/Afi
1056N/A
1056N/A# TODO: Handle symlinks correctly (especially in ${0})
1056N/ASCRIPT_DIRECTORY="`dirname ${0}`"
1056N/ASCRIPT_DIRECTORY="`cd ${SCRIPT_DIRECTORY}; pwd`"
1056N/A
1056N/A#
1056N/A# Default Instance Configuration
1056N/A#
1056N/A
1056N/ADefaultInstanceConfiguration()
1056N/A{
1056N/A # Use the built-in defaults. This section can be copied to its own
1056N/A # file and tailored to your local requirements. Then simply set
1056N/A # OPENGROK_CONFIGURATION=/path/to/your/configuration, before using
1056N/A # this wrapper. It will save you hand editing in your settings
1056N/A # on each new release. A sample cron(1M) entry might look like:
1056N/A # 15 0 * * * OPENGROK_CONFIGURATION=/pkgs/etc/OpenGrok.sh /pkgs/sbin/OpenGrok updateQuietly
1056N/A
1056N/A # Note: It is not really possible to ever provided defaults for
1056N/A # these values which will run in every UNIX-like environment.
1056N/A # So I have provided a set which are functional for a given
1056N/A # environment on which you can based you own configuration.
1056N/A
1056N/A # This has been updated to support more environment variables and
1056N/A # operating systems, if you have any reasonably generic
1056N/A # improvements please feel free to submit a patch.
1056N/A
1056N/A OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/var/opengrok}"
1056N/A
1056N/A LOGGER_CONFIG_FILE="logging.properties"
1056N/A
1056N/A if [ -z "${OPENGROK_DISTRIBUTION_BASE}" ]
1056N/A then
1056N/A if [ -d "${SCRIPT_DIRECTORY}/dist" -a \
1056N/A -f "${SCRIPT_DIRECTORY}/dist/opengrok.jar" -a \
1056N/A -f "${SCRIPT_DIRECTORY}/dist/source.war" \
1056N/A ]
1056N/A then
1056N/A # Handle Developer Build Environments
1056N/A OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/dist"
1056N/A LOGGER_CONF_SOURCE="${SCRIPT_DIRECTORY}/${LOGGER_CONFIG_FILE}"
1056N/A else
1056N/A # Handle Binary Distributions
1056N/A OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/../lib"
1056N/A LOGGER_CONF_SOURCE="${OPENGROK_DISTRIBUTION_BASE}/../doc/${LOGGER_CONFIG_FILE}"
1056N/A fi
1056N/A fi
1056N/A
1056N/A # REQUIRED: Source Code/Repository Root
1056N/A # (your source code or the root of all repositories)
1056N/A SRC_ROOT="${OPENGROK_INSTANCE_BASE}/src"
1056N/A
1056N/A # REQUIRED: OpenGrok Generate Data Root
1056N/A # (for Lucene index and hypertext cross-references)
1056N/A # This area is rebuilt by "update" / "updateQuietly"
1056N/A DATA_ROOT="${OPENGROK_INSTANCE_BASE}/data"
1056N/A
1056N/A # OPTIONAL: User Provided Source Path to Description Mapping (Tab Separated Value)
1056N/A # (The user maintained source of the generated EftarFile file)
1056N/A PATH_DESC="${OPENGROK_INSTANCE_BASE}/etc/paths.tsv"
1056N/A
1056N/A # REQUIRED: XML Configuration
1056N/A # (the configuration used by Web/GUI interfaces)
1056N/A XML_CONFIGURATION="${OPENGROK_INSTANCE_BASE}/etc/configuration.xml"
1056N/A
1056N/A # OPTIONAL: read only XML config, if it exists, it will be read
1056N/A READ_XML_CONFIGURATION="${READ_XML_CONFIGURATION:-}"
1056N/A
1276N/A if [ -f "${READ_XML_CONFIGURATION}" ] ; then
1056N/A READ_XML_CONF="-R ${READ_XML_CONFIGURATION}"
1056N/A fi
1056N/A
1056N/A # REQUIRED: Logger Configuration
1056N/A LOGGER_CONFIG_PATH="${OPENGROK_INSTANCE_BASE}/${LOGGER_CONFIG_FILE}"
1056N/A LOGGER_PROPERTIES="-Djava.util.logging.config.file=${LOGGER_CONFIG_PATH}"
1056N/A
1056N/A # REQUIRED: Java Archive of OpenGrok (Installation Location)
1056N/A OPENGROK_JAR="${OPENGROK_DISTRIBUTION_BASE}/opengrok.jar"
1056N/A
1056N/A # REQUIRED(deploy): Web Archive of OpenGrok (Distribution Location)
1056N/A # (user building from source code will find this and other key
1056N/A # files in the "dist" directory after the build is completed)
1056N/A OPENGROK_DIST_WAR="${OPENGROK_DISTRIBUTION_BASE}/source.war"
1056N/A
1056N/A # REQUIRED: Exuberant CTags (http://ctags.sf.net)
1276N/A EXUBERANT_CTAGS="${EXUBERANT_CTAGS:-`FindExuberantCTags`}"
1056N/A
1056N/A # REQUIRED: Java Home
1056N/A JAVA_HOME="${JAVA_HOME:-`FindJavaHome`}"
1056N/A export JAVA_HOME
1056N/A
1056N/A # REQUIRED: Java Virtual Machine
1056N/A JAVA="${JAVA:-$JAVA_HOME/bin/java}"
1056N/A
1056N/A # DEVELOPMENT: Debug option, if enabled current indexer will listen on the port 8010 until a debugger connects
1056N/A #JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,address=8010,suspend=y"
1056N/A
1056N/A # OPTIONAL: Ignore these patterns as names of files or directories
1056N/A #IGNORE_PATTERNS="-i dummy"
1056N/A
1056N/A # OPTIONAL: Enable Projects
1056N/A # (Every directory in SRC_ROOT is considered a separate project)
1056N/A ENABLE_PROJECTS="-P"
1056N/A
1056N/A # OPTIONAL: Scanning Options (for Mercurial repositories)
1056N/A SCAN_FOR_REPOSITORY="-S"
1056N/A if [ -n "${OPENGROK_SCAN_REPOS}" ]
1056N/A then
1056N/A SCAN_FOR_REPOSITORY=""
1056N/A fi
1056N/A
1056N/A # OPTIONAL: Remote Repository Support (CVS or SVN)
1056N/A # (Can be very time demanding, uncomment if needed)
1056N/A REMOTE_REPOSITORIES="-r on"
1056N/A if [ -n "${OPENGROK_REMOTE_REPOS}" ]
1056N/A then
1056N/A REMOTE_REPOSITORIES=""
1056N/A fi
1056N/A
1056N/A # OPTIONAL: override depth of scanning for repositories
1056N/A if [ -n "${OPENGROK_SCAN_DEPTH}" ]
1056N/A then
1056N/A SCAN_DEPTH="-z${OPENGROK_SCAN_DEPTH}"
1056N/A fi
1056N/A
1056N/A # OPTIONAL: Allow Leading Wildcard Searches
1056N/A # (default: on)
1276N/A LEADING_WILDCARD="-a on"
1056N/A if [ -n "${OPENGROK_WPREFIX}" ]
1056N/A then
1056N/A LEADING_WILDCARD=""
1056N/A fi
1056N/A
1056N/A # OPTIONAL: Web Site Look & Feel
1056N/A # (Options: default, offwhite and polished.
1056N/A # Note the quoting requirements)
1056N/A #SKIN='-L "default"'
1056N/A
1056N/A # OPTIONAL: Set Maximum Indexed Words Per File
1056N/A # Note, that you might run out of memory, then either increase JVM memory
1056N/A # as noted in JAVA_OPTS, or set this limit(if you don't mind opengrok not
1056N/A # indexing the rest of the file, once the limit is reached)
1056N/A # (default: unlimited)
1056N/A #MAX_INDEXED_WORDS="-m 100000"
1056N/A
1056N/A # OPTIONAL: Configuration Address (host:port)
1056N/A # (conf/web.xml default is localhost:2424)
1056N/A WEBAPP_CONFIG=""
1056N/A if [ -n "${OPENGROK_WEBAPP_CFGADDR}" ]; then
1056N/A WEBAPP_CONFIG_ADDRESS=${OPENGROK_WEBAPP_CFGADDR}
1056N/A if [ "${OPENGROK_WEBAPP_CFGADDR}" == "none" ]; then
1056N/A WEBAPP_CONFIG_ADDRESS=""
1056N/A fi
1056N/A else
1056N/A WEBAPP_CONFIG_ADDRESS="localhost:2424"
1276N/A fi
1276N/A
1056N/A if [ -n "${WEBAPP_CONFIG_ADDRESS}" ]; then
1056N/A WEBAPP_CONFIG="-U ${WEBAPP_CONFIG_ADDRESS}"
1056N/A fi
1056N/A
1056N/A # OPTIONAL: JVM Options
1056N/A #JAVA_OPTS="-server -Xmx2048m"
1056N/A JAVA_OPTS="-Xmx2048m"
1056N/A
1056N/A # OPTIONAL: Full Path to History Utilities
1276N/A HG="`Which hg`"
1056N/A CVS="`Which cvs`"
1056N/A SVN="`Which svn`"
1056N/A SCCS="`Which sccs`"
1056N/A CLEARCASE="`Which cleartool`"
1056N/A GIT="`Which git`"
1056N/A P4="`Which p4`"
1056N/A MTN="`Which mtn`"
1056N/A BZR="`Which bzr`"
1056N/A
1056N/A # OPTIONAL: Override Built-in Properties
1056N/A # Assumption: We should not set properties to the empty string
1056N/A PROPERTIES="\
1056N/A${HG:+-Dorg.opensolaris.opengrok.history.Mercurial=$HG} \
1056N/A${CVS:+-Dorg.opensolaris.opengrok.history.cvs=$CVS} \
1056N/A${SVN:+-Dorg.opensolaris.opengrok.history.Subversion=$SVN} \
1056N/A${SCCS:+-Dorg.opensolaris.opengrok.history.SCCS=$SCCS} \
1056N/A${CLEARCASE:+-Dorg.opensolaris.opengrok.history.ClearCase=$CLEARCASE} \
1056N/A${GIT:+-Dorg.opensolaris.opengrok.history.git=$GIT} \
1276N/A${P4:+-Dorg.opensolaris.opengrok.history.Perforce=$P4} \
1056N/A${MTN:+-Dorg.opensolaris.opengrok.history.Monotone=$MTN} \
1056N/A${BZR:+-Dorg.opensolaris.opengrok.history.Bazaar=$BZR} \
1056N/A"
1056N/A
1056N/A # OPTIONAL: Store The History Cache in Java DB (derby),
1056N/A # instead of file system (in gzipped xml files).
1056N/A #
1056N/A # Requirements:
1056N/A # - derbyclient.jar - See README.txt for more details
1056N/A # - Running Derby Server - Defaults to localhost:1527
1056N/A #
1056N/A if [ -n "${OPENGROK_DERBY}" ]
1056N/A then
1056N/A DERBY_HISTORY_CACHE="-D"
1056N/A fi
1056N/A
1056N/A # DELIVERED: An update program for EftarFile
1056N/A # Usage: <class> inputFile [inputFile ...] outputFile
1056N/A # EftarFile == An Extremely Fast Tagged Attribute Read-only File System
1056N/A EFTAR_UPDATE="org.opensolaris.opengrok.web.EftarFile"
1056N/A
1056N/A # HARDCODED: Generated EftarFile (See web/*.jsp)
1056N/A EFTAR_OUTPUT_FILE="${DATA_ROOT}/index/dtags.eftar"
1056N/A
1056N/A # Be Quiet? (set indirectly by command line arguments in the main program)
1276N/A #QUIET=""
1056N/A
1056N/A # or alternatively, Be Verbose!
1056N/A #VERBOSE="-v"
1056N/A
1056N/A if [ -n "${OPENGROK_VERBOSE}" ]
1056N/A then
1056N/A VERBOSE="-v"
1056N/A QUIET=""
1056N/A fi
1056N/A
1056N/A if [ -n "${OPENGROK_PROGRESS}" ]
1056N/A then
1056N/A PROGRESS="-C"
1056N/A fi
1056N/A}
1056N/A
1056N/A#
1056N/A# Helper Functions - Logging
1056N/A#
1056N/A# In general, non-interactive use like cron jobs and automated
1056N/A# installation environments should not generate unnecessary
1056N/A# progress information or warnings, as usage and configuration
1056N/A# will have generally been debugged prior to automation.
1056N/A#
1056N/A
1056N/AProgress()
1056N/A{
1056N/A if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
1056N/A then
1056N/A echo "${@}"
1056N/A fi
1056N/A}
1056N/A
1056N/AWarning()
1056N/A{
1056N/A if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
1056N/A then
1056N/A echo "WARNING: ${@}" 1>&2
1056N/A fi
1056N/A}
1056N/A
1056N/AError()
1056N/A{
1276N/A echo "ERROR: ${@}" 1>&2
1056N/A}
1056N/A
1056N/AFatalError()
1056N/A{
1056N/A echo 1>&2
1056N/A echo "FATAL ERROR: ${@} - Aborting!" 1>&2
1056N/A echo 1>&2
1056N/A ${DO} exit 2
1056N/A}
1056N/A
1056N/A#
1056N/A# Helper Functions - Autodetection of Runtime Environment
1056N/A#
1056N/A
1056N/AWhich()
1056N/A{
1056N/A path="`which ${1} 2>/dev/null`"
1056N/A
1056N/A if [ -x "${path}" ]
1056N/A then
1056N/A echo "${path}"
1056N/A fi
1056N/A}
1056N/A
1056N/ALocateBinary() {
1056N/A for f in $@
1056N/A do
1056N/A file=`which $f 2>/dev/null | grep -v '^no '`
1056N/A if test -n "$file" -a -x "$file"
1056N/A then
1056N/A echo $file
1056N/A return 0
1056N/A fi
1056N/A done
1056N/A
1056N/A echo ""
1056N/A return 1
1056N/A}
1056N/A
1056N/AFindExuberantCTags()
1056N/A{
1056N/A binary=`LocateBinary ctags-exuberant exctags ctags`
1056N/A if test $? -eq 1
1056N/A then
1056N/A Error "Unable to determine Exuberant CTags command name" \
1056N/A "for ${OS_NAME} ${OS_VERSION}"
1056N/A return
1056N/A fi
1056N/A
1056N/A # Verify that this really is Exuberant Ctags
1056N/A $binary --version 2>&1 | grep "Exuberant Ctags" > /dev/null
1056N/A if test $? -ne 0
1056N/A then
1056N/A Error "Unable to determine Exuberant CTags command name" \
1056N/A "for ${OS_NAME} ${OS_VERSION}\n(${binary} is not Exuberant CTags)"
1056N/A return
1056N/A fi
1056N/A
1056N/A echo ${binary}
1056N/A}
1056N/A
1056N/AFindJavaHome()
1056N/A{
1056N/A javaHome=""
1056N/A case "${OS_NAME}:${OS_VERSION}" in
1056N/A SunOS:5.10) javaHome="/usr/jdk/instances/jdk1.6.0" ;;
1056N/A SunOS:5.11) javaHome="/usr/jdk/latest" ;;
1056N/A Linux:*)
1056N/A if [ -f /etc/alternatives/java ]
1056N/A then
1056N/A javaHome=`ls -l /etc/alternatives/java | cut -f 2 -d \> `
1056N/A javaHome=`dirname $javaHome`
1056N/A javaHome=`dirname $javaHome`
else
for dir in /usr/lib/jvm/sun-jdk-1.6 \
/usr/lib/jvm/sun-jre-1.6 \
/usr/lib/jvm/java-6-sun
do
if [ -f ${dir}/bin/java ]
then
javaHome=$dir
break;
fi
done
fi
;;
esac
if [ -z "${javaHome}" ]
then
Error "Unable to determine Java 6 Home" \
"for ${OS_NAME} ${OS_VERSION}"
return
fi
if [ ! -d "${javaHome}" ]
then
Error "Missing Java Home ${javaHome}"
return
fi
echo "${javaHome}"
}
FindApplicationServerType()
{
# Use this function to determine which environment the deploy the
# web application function into. Some users (especially
# developers) will have many deployment environments or will wish
# to specify directly the application server to deploy to.
# Either use the environment variable OPENGROK_APP_SERVER or
# reimplement this function in your configuration file (as
# specified by OPENGROK_CONFIGURATION)
if [ -n "${OPENGROK_APP_SERVER}" ]
then
echo "${OPENGROK_APP_SERVER}"
return
fi
# This implementation favours Tomcat, but needs a lot of work,
# especially if Glassfish is perferrerd or it is under the control
# of SMF (Service Management Facility)
# Maybe a better implementation would be to call Application
# Server specific WAR Directory and see if they exist.
if [ -d "/var/tomcat6/webapps" \
-o -d "/var/lib/tomcat6/webapps" \
-o -d "/var/lib/tomcat5/webapps" \
-o -d "/var/lib/tomcat5.5/webapps" \
]
then
echo "Tomcat"
return
fi
if [ -x "/etc/init.d/appserv" -a -d "/var/appserver/domains" ]
then
echo "Glassfish"
return
fi
# Assume Tomcat
echo "Tomcat"
}
DetermineWarDirectoryTomcat()
{
if [ -n "${OPENGROK_WAR_TARGET_TOMCAT}" ]
then
echo "${OPENGROK_WAR_TARGET_TOMCAT}"
return
elif [ -n "${OPENGROK_WAR_TARGET}" ]
then
echo "${OPENGROK_WAR_TARGET}"
return
fi
for prefix in \
${OPENGROK_TOMCAT_BASE} \
/var/tomcat6 \
/var/lib/tomcat6 \
/var/lib/tomcat5 \
/var/lib/tomcat5.5 \
do
if [ -d "${prefix}/webapps" ]
then
echo "${prefix}/webapps"
return
fi
done
}
DetermineWarDirectoryGlassfish()
{
if [ -n "${OPENGROK_WAR_TARGET_GLASSFISH}" ]
then
echo "${OPENGROK_WAR_TARGET_GLASSFISH}"
return
elif [ -n "${OPENGROK_WAR_TARGET}" ]
then
echo "${OPENGROK_WAR_TARGET}"
return
fi
for prefix in \
${OPENGROK_GLASSFISH_BASE} \
/var/appserver \
do
if [ -d "${prefix}/domains" ]
then
if [ -z "${domainDirectory}" ]
then
domainDirectory="${prefix}/domains"
fi
fi
done
if [ -z "${domainDirectory}" ]
then
return
fi
# User Specified Domain
if [ -n "${OPENGROK_GLASSFISH_DOMAIN}" ]
then
directory="${domainDirectory}/${OPENGROK_GLASSFISH_DOMAIN}/autodeploy"
if [ ! -d "${directory}" ]
then
FatalError "Missing Specified Glassfish Domain ${OPENGROK_GLASSFISH_DOMAIN}"
fi
echo "${directory}"
return
fi
# Arbitrary Domain Selection
firstDomain=`ls -1 ${domainDirectory} | head -1`
if [ -z "${firstDomain}" ]
then
FatalError "Failed to dynamically determine Glassfish Domain from ${domainDirectory}"
fi
echo "${domainDirectory}/${firstDomain}/autodeploy"
}
#
# Implementation
#
# The variable "DO" can usefully be set to "echo" to aid in script debugging
#
LoadStandardEnvironment()
{
# Setup a standard execution environment (if required)
OPENGROK_STANDARD_ENV="${OPENGROK_STANDARD_ENV:-/pkgs/sbin/CronExecutionEnvironment.sh}"
if [ -f "${OPENGROK_STANDARD_ENV}" ]
then
Progress "Loading ${OPENGROK_STANDARD_ENV} ..."
. "${OPENGROK_STANDARD_ENV}"
fi
}
#
# Load default configuration and then merge with user specified configuration.
#
LoadInstanceConfiguration()
{
# Note: As all functions have been defined by the time this routine
# is called, your configuration can, if desired, override functions
# in addition to setting the variables mentioned in the function
# DefaultInstanceConfiguration(), this maybe useful to override
# functionality used to determine the default deployment environment
# find dependencies or validate the configuration, for example.
Progress "Loading the default instance configuration ..."
DefaultInstanceConfiguration
if [ -n "${OPENGROK_CONFIGURATION}" -a -f "${OPENGROK_CONFIGURATION}" ]
then
# Load the Local OpenGrok Configuration Environment
Progress "Loading ${OPENGROK_CONFIGURATION} ..."
. "${OPENGROK_CONFIGURATION}"
fi
}
ValidateConfiguration()
{
if [ ! -x "${EXUBERANT_CTAGS}" ]
then
FatalError "Missing Dependent Application - Exuberant CTags"
fi
if [ ! -d "${SRC_ROOT}" ]
then
FatalError "OpenGrok Source Path ${SRC_ROOT} doesn't exist"
fi
if [ -n "${QUIET}" -a -n "${VERBOSE}" ]
then
Warning "Both Quiet and Verbose Mode Enabled - Choosing Verbose"
QUIET=""
VERBOSE="-v"
fi
if [ -n "${OPENGROK_DERBY}" ]
then
Warning "CHECK: derbyclient.jar needs to be in where the rest of opengrok used jars are and in unpacked source.war in WEB-INF/lib !!!"
fi
}
CreateRuntimeRequirements()
{
if [ ! -d "${DATA_ROOT}" ]
then
Warning "OpenGrok generated data path ${DATA_ROOT} doesn't exist"
Progress " Attempting to create generated data directory ... "
${DO} mkdir -p "${DATA_ROOT}"
fi
if [ ! -d "${DATA_ROOT}" ]
then
FatalError "OpenGrok data path ${DATA_ROOT} doesn't exist"
fi
if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
then
Warning "OpenGrok generated etc path ${OPENGROK_INSTANCE_BASE}/etc doesn't exist"
Progress " Attempting to create generated etc directory ... "
${DO} mkdir -p "${OPENGROK_INSTANCE_BASE}/etc"
fi
if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
then
FatalError "OpenGrok etc path ${OPENGROK_INSTANCE_BASE}/etc doesn't exist"
fi
if [ -n "${LOGGER_CONFIG_PATH}" -a ! -f "${LOGGER_CONFIG_PATH}" ]
then
Progress " Creating default ${LOGGER_CONFIG_PATH} ... "
if [ ! -f "${LOGGER_CONF_SOURCE}" ]
then
Warning "Can't find distribution logging configuration" \
"(${LOGGER_CONF_SOURCE}) to install as default" \
"logging configuration (${LOGGER_CONFIG_PATH})"
else
${DO} grep -v java.util.logging.FileHandler.pattern "${LOGGER_CONF_SOURCE}" > "${LOGGER_CONFIG_PATH}"
${DO} grep java.util.logging.FileHandler.pattern "${LOGGER_CONF_SOURCE}" | sed "s|opengrok%g.%u.log|${OPENGROK_INSTANCE_BASE}/log/opengrok%g.%u.log|g" >> "${LOGGER_CONFIG_PATH}"
if [ ! -d ${OPENGROK_INSTANCE_BASE}/log ]
then
${DO} mkdir ${OPENGROK_INSTANCE_BASE}/log
fi
fi
fi
if [ -n "${OPENGROK_DERBY}" ]
then
if [ ! -d "${OPENGROK_INSTANCE_BASE}/derby" ]
then
Warning "OpenGrok generated derby path ${OPENGROK_INSTANCE_BASE}/derby doesn't exist"
Progress " Attempting to create generated derby directory ... "
${DO} mkdir -p ${OPENGROK_INSTANCE_BASE}/derby
fi
fi
}
StdInvocation()
{
${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
${LOGGER_PROPERTIES} \
${JAVA_DEBUG} \
-jar ${OPENGROK_JAR} \
${IGNORE_PATTERNS} ${ENABLE_PROJECTS} \
${DERBY_HISTORY_CACHE} \
${SCAN_FOR_REPOSITORY} ${REMOTE_REPOSITORIES} \
${SCAN_DEPTH} \
${VERBOSE} ${QUIET} \
${PROGRESS} \
${EXUBERANT_CTAGS:+-c} ${EXUBERANT_CTAGS} \
${MAX_INDEXED_WORDS} ${SKIN} ${LEADING_WILDCARD} \
${READ_XML_CONF} \
-W ${XML_CONFIGURATION} \
${WEBAPP_CONFIG} \
-s ${SRC_ROOT} -d ${DATA_ROOT} \
"${@}"
}
UpdateGeneratedData()
{
StdInvocation -H
}
UpdateDescriptionCache()
{
# OPTIONAL : Update the EftarFile data
if [ -n "${PATH_DESC}" -a -s "${PATH_DESC}" ]
then
${DO} ${JAVA} -classpath ${OPENGROK_JAR} \
${EFTAR_UPDATE} ${PATH_DESC} ${EFTAR_OUTPUT_FILE}
fi
}
OpenGrokUsage()
{
echo "Options for opengrok.jar:" 1>&2
${DO} ${JAVA} ${JAVA_OPTS} -jar ${OPENGROK_JAR} '-?'
}
DeployWar()
{
applicationServer="`FindApplicationServerType`"
case "${applicationServer}" in
Tomcat) warTarget="`DetermineWarDirectoryTomcat`" ;;
Glassfish) warTarget="`DetermineWarDirectoryGlassfish`" ;;
*) FatalError "Unsupported Application Server ${applicationServer}" ;;
esac
if [ -z "${warTarget}" ]
then
FatalError "Unable to determine Deployment Directory for ${applicationServer}"
fi
if [ ! -f "${OPENGROK_DIST_WAR}" ]
then
FatalError "Missing Web Application Archive ${OPENGROK_DIST_WAR}"
fi
if [ ! -d "${warTarget}" ]
then
FatalError "Missing Deployment Directory ${warTarget}"
fi
Progress "Installing ${OPENGROK_DIST_WAR} to ${warTarget} ..."
${DO} cp -p "${OPENGROK_DIST_WAR}" "${warTarget}/"
if [ $? != 0 ]
then
FatalError "Web Application Installation FAILED"
fi
Progress
Progress "Start your application server (${applicationServer}), if it is not already"
Progress "running, or wait until it loads the just installed web application."
Progress
Progress "OpenGrok should be available on <HOST>:<PORT>/source"
Progress " where HOST and PORT are configured in ${applicationServer}."
Progress
}
DerbyServer()
{
case "${OS_NAME}:${OS_VERSION}" in
SunOS:5.10) Error "unsupported OS" ;;
SunOS:5.11)
/sbin/svcadm enable javadb
;;
Linux:*)
mkdir -p $DATA_ROOT/derby
java -Dderby.system.home=$DATA_ROOT/derby -jar /usr/lib/jvm/java-6-sun/db/lib/derbynet.jar start
;;
*) Error "unsupported OS" ;;
esac
}
#
# Main Program
#
if [ $# -eq 0 -o $# -gt 2 ]
then
Usage
fi
LoadStandardEnvironment
LoadInstanceConfiguration
case "${1}" in
deploy)
DeployWar
;;
derby)
ValidateConfiguration
CreateRuntimeRequirements
DerbyServer
;;
update)
ValidateConfiguration
CreateRuntimeRequirements
UpdateGeneratedData
UpdateDescriptionCache
;;
updateQuietly)
ValidateConfiguration
CreateRuntimeRequirements
QUIET="-q"
VERBOSE=""
UpdateGeneratedData
UpdateDescriptionCache
;;
index)
if [ -n "${2}" ]
then
SRC_ROOT="${2}"
fi
ValidateConfiguration
CreateRuntimeRequirements
UpdateGeneratedData
UpdateDescriptionCache
;;
usage)
OpenGrokUsage
Usage
;;
*)
Usage
;;
esac
#
# End of File
#