OpenGrok revision 5baba343b1d32252619db7e6aff0c1c0be67761c
0N/A#!/bin/sh
328N/A#
0N/A# OpenGrok Wrapper (initial setup and cron job updating)
0N/A#
0N/A# Supported Operating Systems:
0N/A# - Solaris 11 (SunOS 5.11)
180N/A# - Solaris 12 (SunOS 5.12)
0N/A# - Debian (Linux)
180N/A#
0N/A# Supported Deployment Engines:
0N/A# - Tomcat 7
0N/A# - Tomcat 6
0N/A# - Glassfish
0N/A#
0N/A# Supported Environment Variables:
0N/A# - OPENGROK_NON_INTERACTIVE Suppress Progress and Warnings Messages (*)
0N/A# - OPENGROK_STANDARD_ENV Run Time Shell Environment (Shell Script)
0N/A# - OPENGROK_CONFIGURATION User Configuration (Shell Script)
0N/A#
0N/A# Supported Environment Variables for configuring the default setup:
180N/A# - OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution
180N/A# - OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area
180N/A# - EXUBERANT_CTAGS Full Path to Exuberant CTags
0N/A# - OPENGROK_CTAGS_OPTIONS_FILE Full path to file with extra command line
0N/A# options for CTags program (for its --options
5N/A# switch), default is DATA_ROOT/etc/ctags.config
5N/A# - JAVA_HOME Full Path to Java Installation Root
338N/A# - JAVA Full Path to java binary (to enable 64bit JDK)
338N/A# - JAVA_OPTS Java options (e.g. for JVM memory increase
338N/A# or enabling server JDK)
338N/A# JAVA_OPTS=-Xmx2048m is the default!
338N/A# - OPENGROK_APP_SERVER Application Server ("Tomcat" or "Glassfish")
338N/A# - OPENGROK_WAR_TARGET_TOMCAT Tomcat Specific WAR Target Directory
338N/A# - OPENGROK_WAR_TARGET_GLASSFISH Glassfish Specific WAR Target Directory
338N/A# - OPENGROK_WAR_TARGET Fallback WAR Target Directory
338N/A# - OPENGROK_TOMCAT_BASE Base Directory for Tomcat (contains webapps)
338N/A# - OPENGROK_GLASSFISH_BASE Base Directory for Glassfish
338N/A# (contains domains)
338N/A# - OPENGROK_GLASSFISH_DOMAIN Preferred Glassfish Domain Name
338N/A# - OPENGROK_VERBOSE Enable Verbose Mode in opengrok.jar (*)
338N/A# - OPENGROK_PROGRESS Shows progress in %(percentage) of working
338N/A# through project, it's good to have Verbose
338N/A# Mode enabled too, cost of this is one more
338N/A# traversal of the project before indexing it(*)
338N/A# - OPENGROK_REMOTE_REPOS Influence history cache generation for remote
338N/A# repositories. Following values are recognized:
338N/A# on - enabled (default)
338N/A# off - disabled for indexing and UI
338N/A# dirbased - indexing enabled only for repos
338N/A# which can fetch history for
338N/A# directory
338N/A# uionly - enabled for UI only
338N/A# - OPENGROK_SCAN_REPOS Disable Scan for repositories (*)
338N/A# - OPENGROK_SCAN_DEPTH how deep should scanning for repos go
338N/A# (by default 3 directories from SRC_ROOT)
0N/A# - OPENGROK_WEBAPP_CFGADDR Web app address to send configuration to
8N/A# (use "none" to avoid sending it to web app)
0N/A# - OPENGROK_WEBAPP_CONTEXT Context URL of the OpenGrok webapp
0N/A# (by default /source)
0N/A# - FULL reindex is needed once this is used
0N/A# (old already indexed files won't be refreshed)
0N/A# - OPENGROK_WPREFIX Disable wildcard prefix search query
0N/A# support (*)
0N/A# - OPENGROK_DERBY if set, then indexer tries to use derby as
0N/A# historycache (see derby command of this
0N/A# script)
27N/A# - OPENGROK_DERBY_URL Use specific URL to JavaDB, e.g.
0N/A# "jdbc:derby://localhost:1528/cachedb;create=true"
27N/A# (default port is 1527)
27N/A# - OPENGROK_TAG Enable parsing of revision tags into the History
27N/A# view
0N/A# - READ_XML_CONFIGURATION file with read only configuration
0N/A# - temporary workaround for bug # 327
0N/A# - OPENGROK_FLUSH_RAM_BUFFER_SIZE="-m 16" - set RAM buffer size for flushing,
0N/A# default is 16MB per thread, you might try to
0N/A# increase it to 256MB, but do increase JVM to
0N/A# 4/8/16GB ! Lucene defaults to 8 threads.
0N/A# Increase JVM memory as noted using JAVA_OPTS
0N/A# - OPENGROK_LOGGER_CONFIG_PATH Set path to custom logging.properties file.
0N/A#
0N/A# Notes:
286N/A# (*) Any Non-Empty String will enable these options
27N/A#
27N/A
27N/A#
27N/A# Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
27N/A#
27N/A#
27N/A# Print usage to stdout and exit.
27N/A#
27N/AUsage()
32N/A{
32N/A progname=`basename $0`
315N/A
315N/A exec >&2
311N/A echo ""
311N/A echo "Usage: ${progname} <deploy|derby|update|updateQuietly|usage|help>"
27N/A echo " ${progname} index [<directory>]"
27N/A echo " ${progname} indexpart <src_root> <directory1> [..]"
27N/A echo " ${progname} clearHistory [<repository_name>]"
27N/A echo ""
27N/A echo " Optional environment variables:"
27N/A echo " OPENGROK_CONFIGURATION - location of your configuration"
27N/A echo " e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf ${0} ... "
311N/A echo ""
27N/A echo " See the code for more information on configuration options /" \
27N/A "variables"
27N/A echo ""
27N/A exit 1
311N/A}
27N/A
27N/A#
27N/A# Runtime Configuration
27N/A#
27N/Aif [ -x "/bin/uname" ]; then
27N/A OS_NAME="`/bin/uname -s`"
311N/A OS_VERSION="`/bin/uname -r`"
311N/Aelif [ -x "/usr/bin/uname" ]; then
311N/A OS_NAME="`/usr/bin/uname -s`"
311N/A OS_VERSION="`/usr/bin/uname -r`"
311N/Aelse
311N/A echo "Cannot determine operating system version"
311N/A exit 1
311N/Afi
311N/A
27N/A# TODO: Handle symlinks correctly (especially in ${0})
189N/ASCRIPT_DIRECTORY="`dirname ${0}`"
332N/ASCRIPT_DIRECTORY="`cd ${SCRIPT_DIRECTORY}; pwd`"
338N/A
311N/A#
27N/A# Default Instance Configuration
27N/A#
27N/A
27N/ADefaultInstanceConfiguration()
27N/A{
27N/A # Use the built-in defaults. This section can be copied to its own
27N/A # file and tailored to your local requirements. Then simply set
27N/A # OPENGROK_CONFIGURATION=/path/to/your/configuration, before using
27N/A # this wrapper. It will save you hand editing in your settings
27N/A # on each new release. A sample cron(1M) entry might look like:
27N/A # 15 0 * * * OPENGROK_CONFIGURATION=/pkgs/etc/OpenGrok.sh /pkgs/sbin/OpenGrok updateQuietly
27N/A
27N/A # Note: It is not really possible to ever provided defaults for
27N/A # these values which will run in every UNIX-like environment.
27N/A # So I have provided a set which are functional for a given
27N/A # environment on which you can based you own configuration.
27N/A
27N/A # This has been updated to support more environment variables and
27N/A # operating systems, if you have any reasonably generic
27N/A # improvements please feel free to submit a patch.
27N/A
27N/A OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/var/opengrok}"
27N/A
27N/A LOGGER_CONFIG_FILE="logging.properties"
27N/A
27N/A if [ -z "${OPENGROK_DISTRIBUTION_BASE}" ]
27N/A then
27N/A if [ -d "${SCRIPT_DIRECTORY}/dist" -a \
27N/A -f "${SCRIPT_DIRECTORY}/dist/opengrok.jar" -a \
27N/A -f "${SCRIPT_DIRECTORY}/dist/source.war" \
27N/A ]
27N/A then
27N/A # Handle Developer Build Environments
27N/A OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/dist"
27N/A LOGGER_CONF_SOURCE="${SCRIPT_DIRECTORY}/${LOGGER_CONFIG_FILE}"
27N/A else
613N/A # Handle Binary Distributions
613N/A OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/../lib"
613N/A LOGGER_CONF_SOURCE="${OPENGROK_DISTRIBUTION_BASE}/../doc/"
613N/A LOGGER_CONF_SOURCE="${LOGGER_CONF_SOURCE}${LOGGER_CONFIG_FILE}"
613N/A fi
311N/A fi
311N/A
311N/A # REQUIRED: Source Code/Repository Root
27N/A # (your source code or the root of all repositories)
613N/A SRC_ROOT="${OPENGROK_INSTANCE_BASE}/src"
613N/A
613N/A # REQUIRED: OpenGrok Generate Data Root
27N/A # (for Lucene index and hypertext cross-references)
27N/A # This area is rebuilt by "update" / "updateQuietly"
27N/A DATA_ROOT="${OPENGROK_INSTANCE_BASE}/data"
338N/A
613N/A # OPTIONAL: User Provided Source Path to Description Mapping
338N/A # (Tab Separated Value)
27N/A # (The user maintained source of the generated EftarFile file)
27N/A PATH_DESC="${OPENGROK_INSTANCE_BASE}/etc/paths.tsv"
27N/A
27N/A # REQUIRED: XML Configuration
27N/A # (the configuration used by Web/GUI interfaces)
189N/A XML_CONFIGURATION="${OPENGROK_INSTANCE_BASE}/etc/configuration.xml"
189N/A
189N/A # OPTIONAL: read only XML config, if it exists, it will be read
189N/A READ_XML_CONFIGURATION="${READ_XML_CONFIGURATION:-}"
27N/A
27N/A if [ -f "${READ_XML_CONFIGURATION}" ] ; then
27N/A READ_XML_CONF="-R ${READ_XML_CONFIGURATION}"
338N/A fi
338N/A
613N/A # REQUIRED: Logger Configuration
27N/A if [ -n "${OPENGROK_LOGGER_CONFIG_PATH}" ]; then
27N/A if [ ! -f "${OPENGROK_LOGGER_CONFIG_PATH}" ]; then
142N/A echo "File ${OPENGROK_LOGGER_CONFIG_PATH} does not exist"
27N/A exit 1
27N/A fi
27N/A LOGGER_CONFIG_PATH=${OPENGROK_LOGGER_CONFIG_PATH}
27N/A else
27N/A LOGGER_CONFIG_PATH="${OPENGROK_INSTANCE_BASE}/${LOGGER_CONFIG_FILE}"
142N/A fi
27N/A LOGGER_PROPERTIES="-Djava.util.logging.config.file=${LOGGER_CONFIG_PATH}"
27N/A
27N/A # REQUIRED: Java Archive of OpenGrok (Installation Location)
27N/A OPENGROK_JAR="${OPENGROK_DISTRIBUTION_BASE}/opengrok.jar"
27N/A
142N/A # REQUIRED(deploy): Web Archive of OpenGrok (Distribution Location)
27N/A # (user building from source code will find this and other key
27N/A # files in the "dist" directory after the build is completed)
27N/A OPENGROK_DIST_WAR="${OPENGROK_DISTRIBUTION_BASE}/source.war"
27N/A
27N/A # REQUIRED: Exuberant CTags (http://ctags.sf.net)
27N/A EXUBERANT_CTAGS="${EXUBERANT_CTAGS:-`FindExuberantCTags`}"
27N/A
27N/A # OPTIONAL: supply extra command line options to CTags program
27N/A if [ -n "${OPENGROK_CTAGS_OPTIONS_FILE}" ]; then
27N/A CTAGS_OPTIONS_FILE="${OPENGROK_CTAGS_OPTIONS_FILE}"
311N/A elif [ -r "${OPENGROK_INSTANCE_BASE}/etc/ctags.config" ]; then
311N/A CTAGS_OPTIONS_FILE="${OPENGROK_INSTANCE_BASE}/etc/ctags.config"
27N/A fi
613N/A
27N/A # REQUIRED: Java Home
27N/A JAVA_HOME="${JAVA_HOME:-`FindJavaHome`}"
27N/A export JAVA_HOME
27N/A
27N/A # REQUIRED: Java Virtual Machine
27N/A JAVA="${JAVA:-$JAVA_HOME/bin/java}"
27N/A
27N/A # DEVELOPMENT: Debug option, if enabled current indexer will listen on the
27N/A # port 8010 until a debugger connects
27N/A #JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket"
27N/A #JAVA_DEBUG="$JAVA_DEBUG,server=y,address=8010,suspend=y"
27N/A
27N/A # OPTIONAL: Ignore these patterns as names of files or directories
27N/A #IGNORE_PATTERNS="-i dummy"
27N/A # To ignore skipping just the history cache creation for a particular
27N/A # directory and all of it's subdirectories, touch an empty
27N/A # .opengrok_skip_history file at the root of that directory
27N/A
27N/A # OPTIONAL: Enable Projects
27N/A # (Every directory in SRC_ROOT is considered a separate project)
27N/A ENABLE_PROJECTS="-P"
27N/A
27N/A # OPTIONAL: Scanning Options (for Mercurial repositories)
27N/A SCAN_FOR_REPOSITORY="-S"
27N/A if [ -n "${OPENGROK_SCAN_REPOS}" ]
27N/A then
27N/A SCAN_FOR_REPOSITORY=""
27N/A fi
189N/A
189N/A # OPTIONAL: Disable remote repository support (CVS or SVN) [on by default]
189N/A REMOTE_REPOSITORIES="-r on"
189N/A if [ -n "${OPENGROK_REMOTE_REPOS}" ]
27N/A then
27N/A REMOTE_REPOSITORIES="-r ${OPENGROK_REMOTE_REPOS}"
338N/A fi
27N/A
142N/A # OPTIONAL: override depth of scanning for repositories
613N/A if [ -n "${OPENGROK_SCAN_DEPTH}" ]
613N/A then
27N/A SCAN_DEPTH="-z${OPENGROK_SCAN_DEPTH}"
27N/A fi
27N/A
27N/A # OPTIONAL: Allow Leading Wildcard Searches
27N/A # (default: on)
27N/A LEADING_WILDCARD="-a on"
27N/A if [ -n "${OPENGROK_WPREFIX}" ]
27N/A then
27N/A LEADING_WILDCARD=""
27N/A fi
27N/A
27N/A # OPTIONAL: Web Site Look & Feel
27N/A # (Options: default, offwhite and polished.
0N/A # Note the quoting requirements)
332N/A #SKIN='-L default'
332N/A
332N/A # OPTIONAL: Configuration Address (host:port)
332N/A # (conf/web.xml default is localhost:2424)
332N/A WEBAPP_CONFIG=""
332N/A if [ -n "${OPENGROK_WEBAPP_CFGADDR}" ]; then
332N/A WEBAPP_CONFIG_ADDRESS=${OPENGROK_WEBAPP_CFGADDR}
332N/A if [ "${OPENGROK_WEBAPP_CFGADDR}" = "none" ]; then
311N/A WEBAPP_CONFIG_ADDRESS=""
311N/A fi
0N/A else
0N/A WEBAPP_CONFIG_ADDRESS="localhost:2424"
0N/A fi
0N/A
0N/A if [ -n "${WEBAPP_CONFIG_ADDRESS}" ]; then
27N/A WEBAPP_CONFIG="-U ${WEBAPP_CONFIG_ADDRESS}"
27N/A fi
27N/A
27N/A # OPTIONAL: Context URL of the OpenGrok webapp
27N/A # (default is /source)
27N/A WEBAPP_CONTEXT=""
27N/A if [ -n "${OPENGROK_WEBAPP_CONTEXT}" ]; then
27N/A WEBAPP_CONTEXT="-w ${OPENGROK_WEBAPP_CONTEXT}"
27N/A fi
27N/A
27N/A # OPTIONAL: JVM Options
27N/A JAVA_OPTS="${JAVA_OPTS:--Xmx2048m}"
0N/A
0N/A # OPTIONAL: Full Path to History Utilities
0N/A HG="`Which hg`"
0N/A CVS="`Which cvs`"
0N/A SVN="`Which svn`"
0N/A SCCS="`Which sccs`"
0N/A CLEARCASE="`Which cleartool`"
0N/A GIT="`Which git`"
0N/A P4="`Which p4`"
0N/A MTN="`Which mtn`"
0N/A BZR="`Which bzr`"
0N/A
0N/A # OPTIONAL: Override Built-in Properties
0N/A # Assumption: We should not set properties to the empty string
0N/A PROPERTIES="\
0N/A${HG:+-Dorg.opensolaris.opengrok.history.Mercurial=$HG} \
0N/A${CVS:+-Dorg.opensolaris.opengrok.history.cvs=$CVS} \
0N/A${SVN:+-Dorg.opensolaris.opengrok.history.Subversion=$SVN} \
0N/A${SCCS:+-Dorg.opensolaris.opengrok.history.SCCS=$SCCS} \
0N/A${CLEARCASE:+-Dorg.opensolaris.opengrok.history.ClearCase=$CLEARCASE} \
0N/A${GIT:+-Dorg.opensolaris.opengrok.history.git=$GIT} \
0N/A${P4:+-Dorg.opensolaris.opengrok.history.Perforce=$P4} \
0N/A${MTN:+-Dorg.opensolaris.opengrok.history.Monotone=$MTN} \
0N/A${BZR:+-Dorg.opensolaris.opengrok.history.Bazaar=$BZR} \
0N/A"
0N/A
0N/A # OPTIONAL: Store The History Cache in Java DB (derby),
0N/A # instead of file system (in gzipped xml files).
0N/A #
0N/A # Requirements:
0N/A # - derbyclient.jar - See README.txt for more details
0N/A # - Running Derby Server - Defaults to localhost:1527
0N/A #
0N/A if [ -n "${OPENGROK_DERBY}" ]
0N/A then
0N/A DERBY_OPTIONS="-D"
0N/A if [ -n "${OPENGROK_DERBY_URL}" ]; then
0N/A DERBY_OPTIONS="${DERBY_OPTIONS} -u ${OPENGROK_DERBY_URL}"
0N/A fi
0N/A fi
0N/A
0N/A # OPTIONAL: Show revision tags in History view.
0N/A # Turn this off if you want to increase indexing performance a bit
0N/A # (default: off)
0N/A if [ -n "${OPENGROK_TAG}" ]
0N/A then
0N/A HISTORY_TAGS="-G"
0N/A fi
0N/A
0N/A # DELIVERED: An update program for EftarFile
0N/A # Usage: <class> inputFile [inputFile ...] outputFile
0N/A # EftarFile == An Extremely Fast Tagged Attribute Read-only File System
0N/A EFTAR_UPDATE="org.opensolaris.opengrok.web.EftarFile"
0N/A
0N/A # HARDCODED: Generated EftarFile (See web/*.jsp)
0N/A EFTAR_OUTPUT_FILE="${DATA_ROOT}/index/dtags.eftar"
0N/A
0N/A # Be Quiet? (set indirectly by command line arguments in the main program)
0N/A #QUIET=""
0N/A
0N/A # or alternatively, Be Verbose!
0N/A #VERBOSE="-v"
0N/A
0N/A if [ -n "${OPENGROK_VERBOSE}" ]
0N/A then
0N/A VERBOSE="-v"
0N/A QUIET=""
0N/A fi
0N/A
0N/A if [ -n "${OPENGROK_PROGRESS}" ]
0N/A then
0N/A PROGRESS="-C"
0N/A fi
0N/A}
0N/A
0N/A#
0N/A# Helper Functions - Logging
0N/A#
0N/A# In general, non-interactive use like cron jobs and automated
0N/A# installation environments should not generate unnecessary
0N/A# progress information or warnings, as usage and configuration
0N/A# will have generally been debugged prior to automation.
0N/A#
0N/A
0N/AProgress()
0N/A{
0N/A if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
0N/A then
0N/A echo "${@}"
0N/A fi
0N/A}
0N/A
0N/AWarning()
0N/A{
0N/A if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
0N/A then
0N/A echo "WARNING: ${@}" 1>&2
0N/A fi
0N/A}
0N/A
0N/AError()
0N/A{
0N/A echo "ERROR: ${@}" 1>&2
0N/A}
0N/A
0N/AFatalError()
0N/A{
0N/A exec >&2
0N/A echo ""
0N/A echo "FATAL ERROR: ${@} - Aborting!"
0N/A echo ""
0N/A
0N/A ${DO} exit 2
0N/A}
289N/A
0N/A#
0N/A# Helper Functions - Autodetection of Runtime Environment
289N/A#
0N/A
0N/AWhich()
0N/A{
0N/A path="`which ${1} 2>/dev/null`"
0N/A
0N/A if [ -x "${path}" ]
0N/A then
0N/A echo "${path}"
0N/A fi
0N/A}
0N/A
0N/ALocateBinary() {
0N/A for f in $@
0N/A do
0N/A file=`which "$f" 2>/dev/null | grep -v '^no '`
0N/A if test -n "$file" -a -x "$file"
0N/A then
0N/A echo $file
0N/A return 0
0N/A fi
0N/A done
0N/A
0N/A echo ""
0N/A return 1
0N/A}
0N/A
0N/AFindExuberantCTags()
0N/A{
0N/A #
0N/A # Search for Exuberant ctags intelligently, skipping
0N/A # over other ctags implementations.
0N/A #
0N/A binary=""
0N/A found=0
0N/A for program in ctags-exuberant exctags ctags; do
0N/A for path in `echo $PATH | tr ':' '\n'`; do
0N/A if [ -x "$path/$program" ]; then
0N/A binary="$path/$program"
0N/A
0N/A # Verify that this really is Exuberant Ctags.
0N/A $binary --version 2>&1 | grep "Exuberant Ctags" > /dev/null
0N/A if [ $? -eq 0 ]; then
0N/A found=1
0N/A break
0N/A fi
0N/A fi
0N/A done
0N/A if [ $found -eq 1 ]; then
0N/A break;
0N/A fi
0N/A done
0N/A if [ $found -ne 1 ]; then
0N/A Error "Unable to determine Exuberant CTags command name" \
0N/A "for ${OS_NAME} ${OS_VERSION}"
276N/A return
0N/A fi
0N/A
0N/A echo ${binary}
0N/A}
0N/A
0N/AFindJavaHome()
189N/A{
189N/A javaHome=""
189N/A case "${OS_NAME}:${OS_VERSION}" in
222N/A SunOS:5.10) javaHome="/usr/jdk/instances/jdk1.7.0" ;;
189N/A SunOS:5.11) javaHome="/usr/jdk/latest" ;;
222N/A SunOS:5.12) javaHome="/usr/jdk/latest" ;;
222N/A Darwin:*) javaHome=`/usr/libexec/java_home` ;;
222N/A Linux:*)
222N/A if [ -f /etc/alternatives/java ]
189N/A then
189N/A javaHome=`ls -l /etc/alternatives/java | cut -f 2 -d \> `
189N/A javaHome=`dirname $javaHome`
189N/A javaHome=`dirname $javaHome`
189N/A fi
189N/A ;;
189N/A esac
189N/A
189N/A if [ -z "${javaHome}" ]
189N/A then
189N/A Error "Unable to determine Java 7 Home" \
189N/A "for ${OS_NAME} ${OS_VERSION}"
189N/A return
189N/A fi
189N/A
189N/A if [ ! -d "${javaHome}" ]
189N/A then
189N/A Error "Missing Java Home ${javaHome}"
189N/A return
189N/A fi
189N/A
189N/A echo "${javaHome}"
189N/A}
189N/A
189N/AFindApplicationServerType()
222N/A{
189N/A # Use this function to determine which environment the deploy the
189N/A # web application function into. Some users (especially
189N/A # developers) will have many deployment environments or will wish
338N/A # to specify directly the application server to deploy to.
338N/A
189N/A # Either use the environment variable OPENGROK_APP_SERVER or
189N/A # reimplement this function in your configuration file (as
189N/A # specified by OPENGROK_CONFIGURATION)
189N/A
189N/A if [ -n "${OPENGROK_APP_SERVER}" ]
189N/A then
222N/A echo "${OPENGROK_APP_SERVER}"
189N/A return
189N/A fi
222N/A
222N/A # This implementation favours Tomcat, but needs a lot of work,
189N/A # especially if Glassfish is perferrerd or it is under the control
189N/A # of SMF (Service Management Facility)
189N/A
0N/A # Maybe a better implementation would be to call Application
0N/A # Server specific WAR Directory and see if they exist.
0N/A
0N/A if [ -d "/var/tomcat6/webapps" \
0N/A -o -d "/var/lib/tomcat6/webapps" \
0N/A -o -d "/var/lib/tomcat7/webapps" \
0N/A ]
0N/A then
0N/A echo "Tomcat"
222N/A return
613N/A fi
613N/A
27N/A if [ -x "/etc/init.d/appserv" -a -d "/var/appserver/domains" ]
27N/A then
27N/A echo "Glassfish"
27N/A return
27N/A fi
27N/A
27N/A # Assume Tomcat
27N/A echo "Tomcat"
27N/A}
27N/A
27N/ADetermineWarDirectoryTomcat()
0N/A{
5N/A if [ -n "${OPENGROK_WAR_TARGET_TOMCAT}" ]
5N/A 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/tomcat7
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)
cronexec="/pkgs/sbin/CronExecutionEnvironment.sh"
OPENGROK_STANDARD_ENV="${OPENGROK_STANDARD_ENV:-$cronexec}"
if [ -f "${OPENGROK_STANDARD_ENV}" ]
then
Progress "Loading ${OPENGROK_STANDARD_ENV} ..."
. "${OPENGROK_STANDARD_ENV}"
fi
}
#
# Load custom configuration and then fill remaining stuff with defaults.
#
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.
#
if [ -n "${OPENGROK_CONFIGURATION}" -a -f "${OPENGROK_CONFIGURATION}" ]
then
# Load the Local OpenGrok Configuration Environment
Progress "Loading ${OPENGROK_CONFIGURATION} ..."
. "${OPENGROK_CONFIGURATION}"
fi
Progress "Loading the default instance configuration ..."
DefaultInstanceConfiguration
}
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
if [ `uname -s` == "SunOS" -a -d /opt/SUNWjavadb -a -d /usr/opengrok ];
then
if [ -d "/var/tomcat6" -a \
! -r "/var/tomcat6/webapps/source/WEB-INF/lib/derbyclient.jar" ];
then
FatalError "JavaDB on but no derbyclient.jar under" \
"/var/tomcat6/webapps/source/WEB-INF/lib"
fi
if [ ! -r "/usr/opengrok/lib/derbyclient.jar" ]; then
FatalError "JavaDB on but no derbyclient.jar under" \
"/usr/opengrok/lib"
fi
else
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
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
filename="opengrok%g.%u.log"
fullpath="${OPENGROK_INSTANCE_BASE}/log/opengrok%g.%u.log"
${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|$filename|$fullpath|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
}
CommonInvocation()
{
${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
${LOGGER_PROPERTIES} \
${JAVA_DEBUG} \
-jar ${OPENGROK_JAR} \
${IGNORE_PATTERNS} \
${DERBY_OPTIONS} \
${HISTORY_TAGS} \
${REMOTE_REPOSITORIES} \
${SCAN_DEPTH} \
${VERBOSE} ${QUIET} \
${PROGRESS} \
${EXUBERANT_CTAGS:+-c} ${EXUBERANT_CTAGS} \
${CTAGS_OPTIONS_FILE:+-o} ${CTAGS_OPTIONS_FILE} \
${OPENGROK_FLUSH_RAM_BUFFER_SIZE} ${SKIN} ${LEADING_WILDCARD} \
${READ_XML_CONF} \
"${@}"
}
StdInvocation()
{
CommonInvocation \
-W ${XML_CONFIGURATION} \
${SCAN_FOR_REPOSITORY} \
${ENABLE_PROJECTS} \
${WEBAPP_CONFIG} \
${WEBAPP_CONTEXT} \
-s ${SRC_ROOT} \
-d ${DATA_ROOT}
}
UpdateGeneratedData()
{
StdInvocation -H
}
UpdateDataPartial()
{
extra_args=""
for arg in "$@"; do
if [ -n "$extra_args" ]; then
extra_args="$extra_args -h $arg"
else
extra_args="-h $arg"
fi
done
CommonInvocation $extra_args "$@"
}
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
;;
SunOS:5.12)
echo "Below might need your socket permission setup"
echo "see JDK1.7_51 release notes"
set -x
mkdir -p $DATA_ROOT/derby
java -Dderby.system.home=$DATA_ROOT/derby \
-jar /usr/jdk/instances/jdk1.7.0/db/lib/derbynet.jar start
;;
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
}
#
# Clear history index for given project.
#
ClearHistory()
{
Progress "Removing history index data for repository ${1}"
StdInvocation -k "${1}"
}
#
# Main Program
#
if [ $# -eq 0 ]
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 [ $# -gt 2 ]
then
Usage
fi
if [ -n "${2}" ]
then
SRC_ROOT="${2}"
fi
ValidateConfiguration
CreateRuntimeRequirements
UpdateGeneratedData
UpdateDescriptionCache
;;
indexpart)
if [ $# -ne 3 ]
then
Usage
fi
SRC_ROOT="${2}"
shift 2
ValidateConfiguration
CreateRuntimeRequirements
UpdateDataPartial $@
;;
clearHistory)
if [ -z "${2}" ]; then
Usage
fi
ClearHistory "${2}"
;;
usage|help)
OpenGrokUsage
Usage
;;
*)
Usage
;;
esac