OpenGrok revision 949
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# OpenGrok Wrapper (initial setup and cron job updating)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Supported Operating Systems:
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - Solaris 10 (SunOS 5.10)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OpenSolaris (SunOS 5.11)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - Debian (Linux)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Supported Deployment Engines:
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - Tomcat 6
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - Tomcat 5.5
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - Glassfish
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Supported Environment Variables:
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_NON_INTERACTIVE Suppress Progress and Warnings Messages (*)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_STANDARD_ENV Run Time Shell Environment (Shell Script)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_CONFIGURATION User Configuration (Shell Script)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Supported Environment Variables for configuring the default setup:
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - EXUBERANT_CTAGS Full Path to Exuberant CTags
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - JAVA_HOME Full Path to Java Installation Root
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_APP_SERVER Application Server ("Tomcat" or "Glassfish")
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_WAR_TARGET_TOMCAT Tomcat Specific WAR Target Directory
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_WAR_TARGET_GLASSFISH Glassfish Specific WAR Target Directory
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_WAR_TARGET Fallback WAR Target Directory
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_TOMCAT_BASE Base Directory for Tomcat (contains webapps)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_GLASSFISH_BASE Base Directory for Glassfish (contains domains)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_GLASSFISH_DOMAIN Preferred Glassfish Domain Name
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_VERBOSE Enable Verbose Mode in opengrok.jar (*)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_REMOTE_REPOS Disable History Cache for (remote) Repositories (*)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - OPENGROK_SCAN_REPOS Disable Scan for repositories (*)_
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# - READ_XML_CONFIGURATION file with read only configuration - a temp workaround for bug # 327
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# (*) Any Non-Empty String will enable these options
3db86aab554edbb4244c8d1a1c90f152eee768afstevel echo "Usage: ${0} <deploy|update|updateQuietly|usage>" 1>&2
3db86aab554edbb4244c8d1a1c90f152eee768afstevel echo " OPENGROK_CONFIGURATION - location of your configuration" 1>&2
3db86aab554edbb4244c8d1a1c90f152eee768afstevel echo " e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf ${0} ... " 1>&2
3db86aab554edbb4244c8d1a1c90f152eee768afstevel echo " See the code for more information on configuration options / variables" 1>&2
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Runtime Configuration
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# TODO: Handle symlinks correctly (especially in ${0})
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Default Instance Configuration
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Use the built-in defaults. This section can be copied to its own
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # file and tailored to your local requirements. Then simply set
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # OPENGROK_CONFIGURATION=/path/to/your/configuration, before using
0d282d1376eb7ba06504448622a6d65726e4bd3erw # this wrapper. It will save you hand editing in your settings
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # on each new release. A sample cron(1M) entry might look like:
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # 15 0 * * * OPENGROK_CONFIGURATION=/pkgs/etc/OpenGrok.sh /pkgs/sbin/OpenGrok updateQuietly
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Note: It is not really possible to ever provided defaults for
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # these values which will run in every UNIX-like environment.
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # So I have provided a set which are functional for a given
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # environment on which you can based you own configuration.
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # This has been updated to support more environment variables and
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # operating systems, if you have any reasonably generic
3db86aab554edbb4244c8d1a1c90f152eee768afstevel OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/var/opengrok}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/dist"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel LOGGER_CONF_SOURCE="${SCRIPT_DIRECTORY}/${LOGGER_CONFIG_FILE}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel LOGGER_CONF_SOURCE="${OPENGROK_DISTRIBUTION_BASE}/${LOGGER_CONFIG_FILE}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # OPTIONAL: User Provided Source Path to Description Mapping (Tab Separated Value)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # (The user maintained source of the generated EftarFile file)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel XML_CONFIGURATION="${OPENGROK_INSTANCE_BASE}/etc/configuration.xml"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # OPTIONAL: read only XML config, if it exists, it will be read
3db86aab554edbb4244c8d1a1c90f152eee768afstevel LOGGER_CONFIG_PATH="${OPENGROK_INSTANCE_BASE}/${LOGGER_CONFIG_FILE}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel LOGGER_PROPERTIES="-Djava.util.logging.config.file=${LOGGER_CONFIG_PATH}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # REQUIRED: Java Archive of OpenGrok (Installation Location)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel OPENGROK_JAR="${OPENGROK_DISTRIBUTION_BASE}/opengrok.jar"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # REQUIRED(deploy): Web Archive of OpenGrok (Distribution Location)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # (user building from source code will find this and other key
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # files in the "dist" directory after the build is completed)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel OPENGROK_DIST_WAR="${OPENGROK_DISTRIBUTION_BASE}/source.war"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel EXUBERANT_CTAGS="${EXUBERANT_CTAGS:-`FindExuberantCTags`}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # DEVELOPMENT: Debug option, if enabled current indexer will listen on the port 8010 until a debugger connects
3db86aab554edbb4244c8d1a1c90f152eee768afstevel #JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,address=8010,suspend=y"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # OPTIONAL: Ignore these patterns as names of files or directories
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # (Every directory in SRC_ROOT is considered a separate project)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # OPTIONAL: Scanning Options (for Mercurial repositories)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Note, that you might run out of memory, then either increase JVM memory
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # as noted in JAVA_OPTS, or set this limit(if you don't mind opengrok not
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # indexing the rest of the file, once the limit is reached)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Assumption: We should not set properties to the empty string
3db86aab554edbb4244c8d1a1c90f152eee768afstevel${HG:+-Dorg.opensolaris.opengrok.history.Mercurial=$HG} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel${SVN:+-Dorg.opensolaris.opengrok.history.Subversion=$SVN} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel${SCCS:+-Dorg.opensolaris.opengrok.history.SCCS=$SCCS} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel${CLEARCASE:+-Dorg.opensolaris.opengrok.history.ClearCase=$CLEARCASE} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel${P4:+-Dorg.opensolaris.opengrok.history.Perforce=$P4} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel${MTN:+-Dorg.opensolaris.opengrok.history.Monotone=$MTN} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel${BZR:+-Dorg.opensolaris.opengrok.history.Bazaar=$BZR} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # OPTIONAL: Store The History Cache in Java DB (derby),
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # - derbyclient.jar - See README.txt for more details
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # - Running Derby Server - Defaults to localhost:1527
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Usage: <class> inputFile [inputFile ...] outputFile
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # EftarFile == An Extremely Fast Tagged Attribute Read-only File System
3db86aab554edbb4244c8d1a1c90f152eee768afstevel EFTAR_UPDATE="org.opensolaris.opengrok.web.EftarFile"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Be Quiet? (set indirectly by command line arguments in the main program)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Helper Functions - Logging
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# In general, non-interactive use like cron jobs and automated
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# installation environments should not generate unnecessary
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# progress information or warnings, as usage and configuration
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# will have generally been debugged prior to automation.
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Helper Functions - Autodetection of Runtime Environment
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Error "Unable to determine Exuberant CTags command name" \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel SunOS:5.10) javaHome="/usr/jdk/instances/jdk1.6.0" ;;
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Use this function to determine which environment the deploy the
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # web application function into. Some users (especially
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # developers) will have many deployment environments or will wish
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # to specify directly the application server to deploy to.
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Either use the environment variable OPENGROK_APP_SERVER or
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # reimplement this function in your configuration file (as
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # This implementation favours Tomcat, but needs a lot of work,
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # especially if Glassfish is perferrerd or it is under the control
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Maybe a better implementation would be to call Application
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Server specific WAR Directory and see if they exist.
3db86aab554edbb4244c8d1a1c90f152eee768afstevel if [ -x "/etc/init.d/appserv" -a -d "/var/appserver/domains" ]
3db86aab554edbb4244c8d1a1c90f152eee768afstevel directory="${domainDirectory}/${OPENGROK_GLASSFISH_DOMAIN}/autodeploy"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "Missing Specified Glassfish Domain ${OPENGROK_GLASSFISH_DOMAIN}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "Failed to dynamically determine Glassfish Domain from ${domainDirectory}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Implementation
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# The variable "DO" can usefully be set to "echo" to aid in script debugging
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Setup a standard execution environment (if required)
3db86aab554edbb4244c8d1a1c90f152eee768afstevel OPENGROK_STANDARD_ENV="${OPENGROK_STANDARD_ENV:-/pkgs/sbin/CronExecutionEnvironment.sh}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # Note: As all functions have been defined by the time this routine
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # is called, your configuration can, if desired, override functions
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # in addition to setting the variables mentioned in the function
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # DefaultInstanceConfiguration(), this maybe useful to override
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # functionality used to determine the default deployment environment
3db86aab554edbb4244c8d1a1c90f152eee768afstevel # find dependencies or validate the configuration, for example.
3db86aab554edbb4244c8d1a1c90f152eee768afstevel if [ -n "${OPENGROK_CONFIGURATION}" -a -f "${OPENGROK_CONFIGURATION}" ]
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress "Loading the default instance configuration ..."
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "Missing Dependent Application - Exuberant CTags"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "OpenGrok Source Path ${SRC_ROOT} doesn't exist"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Warning "Both Quiet and Verbose Mode Enabled - Choosing Verbose"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Warning "OpenGrok Generated Data Path ${DATA_ROOT} doesn't exist"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress " Attempting to create generated data directory ... "
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "OpenGrok Data Path ${DATA_ROOT} doesn't exist"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Warning "OpenGrok Generated Etc Path ${OPENGROK_INSTANCE_BASE}/etc doesn't exist"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress " Attempting to create generated etc directory ... "
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "OpenGrok Etc Path ${OPENGROK_INSTANCE_BASE}/etc doesn't exist"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel if [ -n "${LOGGER_CONFIG_PATH}" -a ! -f "${LOGGER_CONFIG_PATH}" ]
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress " Creating default ${LOGGER_CONFIG_PATH} ... "
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Warning "Can't find distribution logging configuration" \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel ${DO} grep -v java.util.logging.FileHandler.pattern "${LOGGER_CONF_SOURCE}" > "${LOGGER_CONFIG_PATH}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel ${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}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel ${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel -s ${SRC_ROOT} -d ${DATA_ROOT} \
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Glassfish) warTarget="`DetermineWarDirectoryGlassfish`" ;;
3db86aab554edbb4244c8d1a1c90f152eee768afstevel *) FatalError "Unsupported Application Server ${applicationServer}" ;;
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "Unable to determine Deployment Directory for ${applicationServer}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "Missing Web Application Archive ${OPENGROK_DIST_WAR}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel FatalError "Missing Deployment Directory ${warTarget}"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress "Installing ${OPENGROK_DIST_WAR} to ${warTarget} ..."
3db86aab554edbb4244c8d1a1c90f152eee768afstevel if [ $? != 0 ]
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress "Start your application server (${applicationServer}), if it is not already"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress "running, or wait until it loads the just installed web application."
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress "OpenGrok should be available on <HOST>:<PORT>/source"
3db86aab554edbb4244c8d1a1c90f152eee768afstevel Progress " where HOST and PORT are configured in ${applicationServer}."
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# Main Program
3db86aab554edbb4244c8d1a1c90f152eee768afstevel if [ -n "${2}" ]
3db86aab554edbb4244c8d1a1c90f152eee768afstevel# End of File