OpenGrok revision 5a0ed1213a40c9ab7c990b442b77455ee27bc799
#
# OpenGrok Wrapper (initial setup and cron job updating)
#
# Supported Operating Systems:
# - Solaris 11 (SunOS 5.11)
# - Solaris 12 (SunOS 5.12)
# - Debian (Linux)
#
# Supported Deployment Engines:
# - Tomcat 7
# - Tomcat 6
# - Glassfish
#
# Supported Environment Variables:
# - OPENGROK_NON_INTERACTIVE Suppress Progress and Warnings Messages (*)
# - OPENGROK_STANDARD_ENV Run Time Shell Environment (Shell Script)
# - OPENGROK_CONFIGURATION User Configuration (Shell Script)
#
# Supported Environment Variables for configuring the default setup:
# - OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution
# - OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area
# - EXUBERANT_CTAGS Full Path to Exuberant CTags
# - OPENGROK_CTAGS_OPTIONS_FILE Full path to file with extra command line
# options for CTags program (for its --options
# switch), default is DATA_ROOT/etc/ctags.config
# - JAVA_HOME Full Path to Java Installation Root
# - JAVA Full Path to java binary (to enable 64bit JDK)
# - JAVA_OPTS Java options (e.g. for JVM memory increase
# or enabling server JDK)
# JAVA_OPTS=-Xmx2048m is the default!
# - OPENGROK_APP_SERVER Application Server ("Tomcat" or "Glassfish")
# - OPENGROK_WAR_TARGET_TOMCAT Tomcat Specific WAR Target Directory
# - OPENGROK_WAR_TARGET_GLASSFISH Glassfish Specific WAR Target Directory
# - OPENGROK_WAR_TARGET Fallback WAR Target Directory
# - OPENGROK_TOMCAT_BASE Base Directory for Tomcat (contains webapps)
# - OPENGROK_GLASSFISH_BASE Base Directory for Glassfish
# (contains domains)
# - OPENGROK_GLASSFISH_DOMAIN Preferred Glassfish Domain Name
# - OPENGROK_VERBOSE Enable Verbose Mode in opengrok.jar (*)
# - OPENGROK_PROGRESS Shows progress in %(percentage) of working
# through project, it's good to have Verbose
# Mode enabled too, cost of this is one more
# traversal of the project before indexing it(*)
# - OPENGROK_GENERATE_HISTORY Influence history cache generation
# Following values are recognized:
# on - enabled (default)
# off - disabled for indexing and UI
# dirbased - indexing enabled only for repos
# which can fetch history for
# directory
# local - for local repos only
# uionly - enabled for UI only
# - OPENGROK_SCAN_REPOS Disable Scan for repositories (*)
# - OPENGROK_SCAN_DEPTH how deep should scanning for repos go
# (by default 3 directories from SRC_ROOT)
# - OPENGROK_WEBAPP_CFGADDR Web app address to send configuration to
# (use "none" to avoid sending it to web app)
# - OPENGROK_WEBAPP_CONTEXT Context URL of the OpenGrok webapp
# (by default /source)
# - FULL reindex is needed once this is used
# (old already indexed files won't be refreshed)
# - OPENGROK_WPREFIX Disable wildcard prefix search query
# support (*)
# - OPENGROK_DERBY if set, then indexer tries to use derby as
# historycache (see derby command of this
# script)
# - OPENGROK_DERBY_URL Use specific URL to JavaDB, e.g.
# "jdbc:derby://localhost:1528/cachedb;create=true"
# (default port is 1527)
# - OPENGROK_TAG Enable parsing of revision tags into the History
# view
# - READ_XML_CONFIGURATION file with read only configuration
# - temporary workaround for bug # 327
# - OPENGROK_FLUSH_RAM_BUFFER_SIZE="-m 16" - set RAM buffer size for flushing,
# default is 16MB per thread, you might try to
# increase it to 256MB, but do increase JVM to
# 4/8/16GB ! Lucene defaults to 8 threads.
# Increase JVM memory as noted using JAVA_OPTS
# - OPENGROK_LOGGER_CONFIG_PATH Set path to custom logging.properties file.
# - OPENGROK_SUBVERSION_USERNAME name of the user that should be used for
# fetching the history from subversion
# - OPENGROK_SUBVERSION_PASSWORD password of the user that should be used for
# fetching the history from subversion
#
# Notes:
# (*) Any Non-Empty String will enable these options
#
#
#
#
# Print usage to stdout and exit.
#
Usage()
{
exec >&2
echo ""
echo "Usage: ${progname} <deploy|derby|update|updateQuietly|usage|help>"
echo " ${progname} index [<directory>]"
echo " ${progname} indexpart <src_root> <directory1> [..]"
echo " ${progname} clearHistory <src_root> <repository_name>"
echo ""
echo " Optional environment variables:"
echo " OPENGROK_CONFIGURATION - location of your configuration"
echo ""
echo " See the code for more information on configuration options /" \
"variables"
echo ""
exit 1
}
#
# Runtime Configuration
#
else
echo "Cannot determine operating system version"
exit 1
fi
# TODO: Handle symlinks correctly (especially in ${0})
#
# Default Instance Configuration
#
{
# Use the built-in defaults. This section can be copied to its own
# file and tailored to your local requirements. Then simply set
# OPENGROK_CONFIGURATION=/path/to/your/configuration, before using
# this wrapper. It will save you hand editing in your settings
# on each new release. A sample cron(1M) entry might look like:
# Note: It is not really possible to ever provided defaults for
# these values which will run in every UNIX-like environment.
# So I have provided a set which are functional for a given
# environment on which you can based you own configuration.
# This has been updated to support more environment variables and
# operating systems, if you have any reasonably generic
# improvements please feel free to submit a patch.
OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/var/opengrok}"
if [ -z "${OPENGROK_DISTRIBUTION_BASE}" ]
then
if [ -d "${SCRIPT_DIRECTORY}/dist" -a \
]
then
# Handle Developer Build Environments
OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/dist"
LOGGER_CONF_SOURCE="${SCRIPT_DIRECTORY}/${LOGGER_CONFIG_FILE}"
else
# Handle Binary Distributions
OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/../lib"
LOGGER_CONF_SOURCE="${OPENGROK_DISTRIBUTION_BASE}/../doc/"
LOGGER_CONF_SOURCE="${LOGGER_CONF_SOURCE}${LOGGER_CONFIG_FILE}"
fi
fi
# REQUIRED: Source Code/Repository Root
# (your source code or the root of all repositories)
SRC_ROOT="${OPENGROK_INSTANCE_BASE}/src"
# REQUIRED: OpenGrok Generate Data Root
# (for Lucene index and hypertext cross-references)
# This area is rebuilt by "update" / "updateQuietly"
DATA_ROOT="${OPENGROK_INSTANCE_BASE}/data"
# OPTIONAL: User Provided Source Path to Description Mapping
# (Tab Separated Value)
# (The user maintained source of the generated EftarFile file)
# REQUIRED: XML Configuration
XML_CONFIGURATION="${OPENGROK_INSTANCE_BASE}/etc/configuration.xml"
# OPTIONAL: read only XML config, if it exists, it will be read
READ_XML_CONFIGURATION="${READ_XML_CONFIGURATION:-}"
if [ -f "${READ_XML_CONFIGURATION}" ] ; then
READ_XML_CONF="-R ${READ_XML_CONFIGURATION}"
fi
# REQUIRED: Logger Configuration
if [ -n "${OPENGROK_LOGGER_CONFIG_PATH}" ]; then
if [ ! -f "${OPENGROK_LOGGER_CONFIG_PATH}" ]; then
echo "File ${OPENGROK_LOGGER_CONFIG_PATH} does not exist"
exit 1
fi
else
LOGGER_CONFIG_PATH="${OPENGROK_INSTANCE_BASE}/${LOGGER_CONFIG_FILE}"
fi
LOGGER_PROPERTIES="-Djava.util.logging.config.file=${LOGGER_CONFIG_PATH}"
# REQUIRED: Java Archive of OpenGrok (Installation Location)
OPENGROK_JAR="${OPENGROK_DISTRIBUTION_BASE}/opengrok.jar"
# REQUIRED(deploy): Web Archive of OpenGrok (Distribution Location)
# (user building from source code will find this and other key
# files in the "dist" directory after the build is completed)
OPENGROK_DIST_WAR="${OPENGROK_DISTRIBUTION_BASE}/source.war"
# REQUIRED: Exuberant CTags (http://ctags.sf.net)
# OPTIONAL: supply extra command line options to CTags program
if [ -n "${OPENGROK_CTAGS_OPTIONS_FILE}" ]; then
CTAGS_OPTIONS_FILE="${OPENGROK_CTAGS_OPTIONS_FILE}"
CTAGS_OPTIONS_FILE="${OPENGROK_INSTANCE_BASE}/etc/ctags.config"
fi
# REQUIRED: Java Home
export JAVA_HOME
# REQUIRED: Java Virtual Machine
JAVA="${JAVA:-$JAVA_HOME/bin/java}"
# DEVELOPMENT: Debug option, if enabled current indexer will listen on the
# port 8010 until a debugger connects
#JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket"
#JAVA_DEBUG="$JAVA_DEBUG,server=y,address=8010,suspend=y"
# OPTIONAL: Ignore these patterns as names of files or directories
#IGNORE_PATTERNS="-i dummy"
# To ignore skipping just the history cache creation for a particular
# directory and all of it's subdirectories, touch an empty
# .opengrok_skip_history file at the root of that directory
# OPTIONAL: Enable Projects
# (Every directory in SRC_ROOT is considered a separate project)
ENABLE_PROJECTS="-P"
# OPTIONAL: Scanning Options (for Mercurial repositories)
SCAN_FOR_REPOSITORY="-S"
if [ -n "${OPENGROK_SCAN_REPOS}" ]
then
fi
# OPTIONAL: Disable remote repository support (CVS or SVN) [on by default]
GENERATE_HISTORY="-r on"
if [ -n "${OPENGROK_GENERATE_HISTORY}" ]
then
GENERATE_HISTORY="-r ${OPENGROK_GENERATE_HISTORY}"
fi
# OPTIONAL: override depth of scanning for repositories
if [ -n "${OPENGROK_SCAN_DEPTH}" ]
then
SCAN_DEPTH="-z${OPENGROK_SCAN_DEPTH}"
fi
# OPTIONAL: Allow Leading Wildcard Searches
# (default: on)
LEADING_WILDCARD="-a on"
if [ -n "${OPENGROK_WPREFIX}" ]
then
fi
# OPTIONAL: Web Site Look & Feel
# (Options: default, offwhite and polished.
# Note the quoting requirements)
#SKIN='-L default'
# OPTIONAL: Configuration Address (host:port)
if [ -n "${OPENGROK_WEBAPP_CFGADDR}" ]; then
if [ "${OPENGROK_WEBAPP_CFGADDR}" = "none" ]; then
fi
else
WEBAPP_CONFIG_ADDRESS="localhost:2424"
fi
if [ -n "${WEBAPP_CONFIG_ADDRESS}" ]; then
WEBAPP_CONFIG="-U ${WEBAPP_CONFIG_ADDRESS}"
fi
# OPTIONAL: Context URL of the OpenGrok webapp
# (default is /source)
if [ -n "${OPENGROK_WEBAPP_CONTEXT}" ]; then
WEBAPP_CONTEXT="-w ${OPENGROK_WEBAPP_CONTEXT}"
fi
# OPTIONAL: JVM Options
JAVA_OPTS="${JAVA_OPTS:--Xmx2048m}"
# OPTIONAL: Full Path to History Utilities
# OPTIONAL: Override Built-in Properties
# Assumption: We should not set properties to the empty string
PROPERTIES="\
${CVS:+-Dorg.opensolaris.opengrok.history.cvs=$CVS} \
${SCCS:+-Dorg.opensolaris.opengrok.history.SCCS=$SCCS} \
${CLEARCASE:+-Dorg.opensolaris.opengrok.history.ClearCase=$CLEARCASE} \
${GIT:+-Dorg.opensolaris.opengrok.history.git=$GIT} \
"
# OPTIONAL: Store The History Cache in Java DB (derby),
# instead of file system (in gzipped xml files).
#
# Requirements:
# - derbyclient.jar - See README.txt for more details
# - Running Derby Server - Defaults to localhost:1527
#
if [ -n "${OPENGROK_DERBY}" ]
then
DERBY_OPTIONS="-D"
if [ -n "${OPENGROK_DERBY_URL}" ]; then
DERBY_OPTIONS="${DERBY_OPTIONS} -u ${OPENGROK_DERBY_URL}"
fi
fi
# OPTIONAL: Show revision tags in History view.
# Turn this off if you want to increase indexing performance a bit
# (default: off)
if [ -n "${OPENGROK_TAG}" ]
then
HISTORY_TAGS="-G"
fi
# DELIVERED: An update program for EftarFile
# Usage: <class> inputFile [inputFile ...] outputFile
# EftarFile == An Extremely Fast Tagged Attribute Read-only File System
# HARDCODED: Generated EftarFile (See web/*.jsp)
EFTAR_OUTPUT_FILE="${DATA_ROOT}/index/dtags.eftar"
# Be Quiet? (set indirectly by command line arguments in the main program)
#QUIET=""
# or alternatively, Be Verbose!
#VERBOSE="-v"
if [ -n "${OPENGROK_VERBOSE}" ]
then
VERBOSE="-v"
QUIET=""
fi
if [ -n "${OPENGROK_PROGRESS}" ]
then
PROGRESS="-C"
fi
}
#
# Helper Functions - Logging
#
# In general, non-interactive use like cron jobs and automated
# installation environments should not generate unnecessary
# progress information or warnings, as usage and configuration
# will have generally been debugged prior to automation.
#
Progress()
{
if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
then
echo "${@}"
fi
}
Warning()
{
if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
then
echo "WARNING: ${@}" 1>&2
fi
}
Error()
{
echo "ERROR: ${@}" 1>&2
}
{
exec >&2
echo ""
echo "FATAL ERROR: ${@} - Aborting!"
echo ""
${DO} exit 2
}
#
# Helper Functions - Autodetection of Runtime Environment
#
Which()
{
if [ -x "${path}" ]
then
echo "${path}"
fi
}
for f in $@
do
then
echo $file
return 0
fi
done
echo ""
return 1
}
{
#
# Search for Exuberant ctags intelligently, skipping
# over other ctags implementations.
#
binary=""
found=0
# Verify that this really is Exuberant Ctags.
if [ $? -eq 0 ]; then
found=1
break
fi
fi
done
break;
fi
done
"for ${OS_NAME} ${OS_VERSION}"
return
fi
echo ${binary}
}
{
javaHome=""
Linux:*)
if [ -f /etc/alternatives/java ]
then
fi
;;
esac
if [ -z "${javaHome}" ]
then
"for ${OS_NAME} ${OS_VERSION}"
return
fi
if [ ! -d "${javaHome}" ]
then
Error "Missing Java Home ${javaHome}"
return
fi
echo "${javaHome}"
}
{
# 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.
]
then
echo "Tomcat"
return
fi
then
echo "Glassfish"
return
fi
# Assume Tomcat
echo "Tomcat"
}
{
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
${OPENGROK_TOMCAT_BASE} \
do
if [ -d "${prefix}/webapps" ]
then
echo "${prefix}/webapps"
return
fi
done
}
{
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
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
"${OPENGROK_GLASSFISH_DOMAIN}"
fi
echo "${directory}"
return
fi
# Arbitrary Domain Selection
firstDomain=`ls -1 ${domainDirectory} | head -1`
if [ -z "${firstDomain}" ]
then
"${domainDirectory}"
fi
echo "${domainDirectory}/${firstDomain}/autodeploy"
}
#
# Implementation
#
# The variable "DO" can usefully be set to "echo" to aid in script debugging
#
{
# Setup a standard execution environment (if required)
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.
#
{
#
# 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 ..."
}
{
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
then
then
fi
fi
else
fi
fi
}
{
if [ ! -d "${DATA_ROOT}" ]
then
Warning "OpenGrok generated data path ${DATA_ROOT} doesn't exist"
Progress " Attempting to create generated data directory ... "
fi
if [ ! -d "${DATA_ROOT}" ]
then
FatalError "OpenGrok data path ${DATA_ROOT} doesn't exist"
fi
if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
then
"doesn't exist"
Progress " Attempting to create generated etc directory ... "
fi
if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
then
"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
"(${LOGGER_CONF_SOURCE}) to install as default" \
"logging configuration (${LOGGER_CONFIG_PATH})"
else
"${LOGGER_CONF_SOURCE}" > "${LOGGER_CONFIG_PATH}"
"${LOGGER_CONF_SOURCE}" | \
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
"${OPENGROK_INSTANCE_BASE}/derby doesn't exist"
Progress " Attempting to create generated derby directory ... "
${DO} mkdir -p ${OPENGROK_INSTANCE_BASE}/derby
fi
fi
}
{
${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
${JAVA_DEBUG} \
${LOGGER_PROPERTIES} \
"${@}"
}
{
${IGNORE_PATTERNS} \
${DERBY_OPTIONS} \
${HISTORY_TAGS} \
${GENERATE_HISTORY} \
${SCAN_DEPTH} \
${PROGRESS} \
${EXUBERANT_CTAGS:+-c} ${EXUBERANT_CTAGS} \
${CTAGS_OPTIONS_FILE:+-o} ${CTAGS_OPTIONS_FILE} \
${OPENGROK_FLUSH_RAM_BUFFER_SIZE} ${SKIN} ${LEADING_WILDCARD} \
${READ_XML_CONF} \
"${@}"
}
{
-W ${XML_CONFIGURATION} \
${SCAN_FOR_REPOSITORY} \
${ENABLE_PROJECTS} \
${WEBAPP_CONFIG} \
${WEBAPP_CONTEXT} \
-s "${SRC_ROOT}" \
-d "${DATA_ROOT}" \
"${@}"
}
{
}
{
extra_args=""
extra_args="$extra_args -h $arg"
else
extra_args="-h $arg"
fi
done
}
{
# OPTIONAL : Update the EftarFile data
if [ -n "${PATH_DESC}" -a -s "${PATH_DESC}" ]
then
${EFTAR_UPDATE} "${PATH_DESC}" "${EFTAR_OUTPUT_FILE}"
fi
}
{
}
{
esac
if [ -z "${warTarget}" ]
then
"${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} ..."
if [ $? != 0 ]
then
FatalError "Web Application Installation FAILED"
fi
"if it is not already"
"application."
Progress "OpenGrok should be available on <HOST>:<PORT>/source"
Progress " where HOST and PORT are configured in ${applicationServer}."
}
{
SunOS:5.11)
;;
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
;;
Linux:*)
mkdir -p $DATA_ROOT/derby
;;
esac
}
#
# Clear history index for given project.
#
{
Progress "Removing history index data for repository ${1}"
}
#
# Main Program
#
if [ $# -eq 0 ]
then
fi
case "${1}" in
;;
;;
;;
QUIET="-q"
VERBOSE=""
;;
if [ $# -gt 2 ]
then
fi
if [ -n "${2}" ]
then
SRC_ROOT="${2}"
fi
;;
if [ $# -ne 3 ]
then
fi
SRC_ROOT="${2}"
shift 2
;;
if [ $# -ne 3 ]
then
fi
SRC_ROOT="${2}"
shift 2
if [ -z "${1}" ]; then
fi
ClearHistory "${1}"
;;
;;
*)
;;
esac