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