OpenGrok revision 857
294N/A#!/bin/sh
294N/A#
787N/A# OpenGrok Wrapper (initial setup and cron job updating)
789N/A#
789N/A# Supported Operating Systems:
789N/A# - Solaris 10 (SunOS 5.10)
789N/A# - OpenSolaris (SunOS 5.11)
789N/A# - Debian (Linux)
789N/A#
873N/A# Supported Deployment Engines
789N/A# - Tomcat 6
877N/A# - Glassfish
789N/A#
294N/A# Supported Environment Variables :
873N/A# - OPENGROK_NON_INTERACTIVE Suppress Progress and Warnings Messages
873N/A# - OPENGROK_STANDARD_ENV Run Time Shell Environment (Shell Script)
789N/A# - OPENGROK_CONFIGURATION User Configuration (Shell Script)
789N/A#
789N/A# Supported Environment Variables for configuring the default setup
873N/A# - OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution
789N/A# - OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area
789N/A# - EXUBERANT_CTAGS Full Path to Exuberant CTags
789N/A# - JAVA_HOME Full Path to Java Installation Root
789N/A# - OPENGROK_APP_SERVER Application Server ("Tomcat" or "Glassfish")
789N/A# - OPENGROK_WAR_TARGET_TOMCAT Tomcat Specific WAR Target Directory
789N/A# - OPENGROK_WAR_TARGET_GLASSFISH Glassfish Specific WAR Target Directory
789N/A# - OPENGROK_WAR_TARGET Fallback WAR Target Directory
789N/A# - OPENGROK_TOMCAT_BASE Base Directory for Tomcat (contains webapps)
789N/A# - OPENGROK_GLASSFISH_BASE Base Directory for Glassfish (contains domains)
789N/A# - OPENGROK_GLASSFISH_DOMAIN Preferred Glassfish Domain Name
789N/A#
873N/A
941N/A#
941N/A# Usage
994N/A#
911N/A
911N/AUsage()
873N/A{
873N/A echo 1>&2
873N/A echo "Usage: ${0} <deploy|update|updateQuietly|updateConfiguration|usage>" 1>&2
789N/A echo 1>&2
787N/A echo " Optional environment variables:" 1>&2
294N/A echo " OPENGROK_CONFIGURATION - location of your configuartion" 1>&2
294N/A echo " e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf ${0} ... " 1>&2
294N/A echo 1>&2
294N/A echo " See the code for more information on configuration options" 1>&2
294N/A echo 1>&2
294N/A exit 1
294N/A}
877N/A
869N/A#
789N/A# Runtime Configuration
789N/A#
911N/A
789N/AOS_NAME="`/bin/uname -s`"
789N/AOS_VERSION="`/bin/uname -r`"
868N/A
294N/A#
294N/A# Default Instance Configuration
294N/A#
294N/A
294N/ADefaultInstanceConfiguration()
789N/A{
294N/A # Use the built-in defaults. This section can be copied to its own
787N/A # file and tailored to your local requirements. Then simply set
789N/A # OPENGROK_CONFIGURATION=/path/to/your/configuration, before using
789N/A # this wrapper. It will save you hand editing in your settings
787N/A # on each new release. A sample cron(1M) entry might look like:
869N/A # 15 0 * * * OPENGROK_CONFIGURATION=/pkgs/etc/OpenGrok.sh /pkgs/sbin/OpenGrok updateQuietly
869N/A
869N/A # Note: It is not really possible to ever provided defaults for
869N/A # these values which will run in every UNIX-like environment.
789N/A # So I have provided a set which are functional for a given
789N/A # environment on which you can based you own configuration.
789N/A
789N/A # This has been updated to support more environment variables and
789N/A # operating systems, if you have any reasonably generic
789N/A # improvements please feel free to submit a patch.
294N/A
789N/A OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/var/opengrok}"
294N/A
294N/A if [ -z "${OPENGROK_DISTRIBUTION_BASE}" ]
789N/A then
294N/A if [ -d "dist" -a -f "dist/opengrok.jar" -a -f "dist/source.war" ]
294N/A then
294N/A # Handle Developer Build Environments
294N/A OPENGROK_DISTRIBUTION_BASE="`pwd`/dist"
294N/A else
294N/A # Handle Binary Distributions
294N/A OPENGROK_DISTRIBUTION_BASE="`pwd`"
789N/A fi
789N/A fi
789N/A
787N/A # REQUIRED: Source Code/Repository Root
789N/A # (your source code or the root of all repositories)
294N/A SRC_ROOT="${OPENGROK_INSTANCE_BASE}/src"
869N/A
868N/A # REQUIRED: OpenGrok Generate Data Root
789N/A # (for Lucene index and hypertext cross-references)
789N/A # This area is rebuilt by "update" / "updateQuietly"
869N/A DATA_ROOT="${OPENGROK_INSTANCE_BASE}/data"
869N/A
869N/A # OPTIONAL: User Provided Source Path to Description Mapping (Tab Separated Value)
869N/A # (The user maintained source of the generated EftarFile file)
789N/A PATH_DESC="${OPENGROK_INSTANCE_BASE}/etc/paths.tsv"
789N/A
869N/A # REQUIRED: XML Configuration
949N/A # (the configuration used by Web/GUI interfaces)
789N/A XML_CONFIGURATION="${OPENGROK_INSTANCE_BASE}/etc/configuration.xml"
789N/A
979N/A # REQUIRED: Java Archive of OpenGrok (Installation Location)
979N/A OPENGROK_JAR="${OPENGROK_DISTRIBUTION_BASE}/opengrok.jar"
789N/A
787N/A # REQUIRED(deploy): Web Archive of OpenGrok (Distribution Location)
787N/A # (user building from source code will find this and other key
294N/A # files in the "dist" directory after the build is completed)
294N/A OPENGROK_DIST_WAR="${OPENGROK_DISTRIBUTION_BASE}/source.war"
789N/A
294N/A # REQUIRED: Exuberant CTags (http://ctags.sf.net)
294N/A EXUBERANT_CTAGS="${EXUBERANT_CTAGS:-`FindExuberantCTags`}"
294N/A
294N/A # REQUIRED: Java Home
789N/A JAVA_HOME="${JAVA_HOME:-`FindJavaHome`}"
294N/A export JAVA_HOME
294N/A
294N/A # REQUIRED: Java Virtual Machine
789N/A JAVA="${JAVA:-$JAVA_HOME/bin/java}"
294N/A
789N/A # OPTIONAL: Scanning Options (for Mercurial repositories)
294N/A SCAN_FOR_REPOSITORY="-S"
789N/A
789N/A # OPTIONAL: Full Path to History Utilities
911N/A HG="`Which hg`"
911N/A CVS="`Which cvs`"
911N/A SVN="`Which svn`"
915N/A SCCS="`Which sccs`"
911N/A
911N/A # OPTIONAL: Override Built-in Properties
911N/A # Assumption: We should not set properties to the empty string
869N/A PROPERTIES="\
869N/A${HG:+-Dorg.opensolaris.opengrok.history.Mercurial=$HG} \
869N/A${CVS:+-Dorg.opensolaris.opengrok.history.cvs=$CVS} \
869N/A${SVN:+-Dorg.opensolaris.opengrok.history.Subversion=$SVN} \
789N/A${SCCS:+-Dorg.opensolaris.opengrok.history.SCCS=$SCCS} \
857N/A"
789N/A
789N/A # OPTIONAL: JVM Options
789N/A #JAVA_OPTS="-server -Xmx1024m"
789N/A
789N/A # DELIVERED: An update program for EftarFile
294N/A # Usage: <class> inputFile [inputFile ...] outputFile
294N/A # EftarFile == An Extremely Fast Tagged Attribute Read-only File System
789N/A EFTAR_UPDATE="org.opensolaris.opengrok.web.EftarFile"
294N/A
294N/A # HARDCODED: Generated EftarFile (See web/*.jsp)
789N/A EFTAR_OUTPUT_FILE="${DATA_ROOT}/index/dtags.eftar"
294N/A
294N/A # Be Quiet? (set indirectly by command line arguments in the main program)
294N/A QUIET=
789N/A
294N/A # or alternatively, Be Verbose!
877N/A #VERBOSE="-v"
877N/A}
877N/A
869N/A#
869N/A# Helper Functions - Logging
868N/A#
869N/A# In general, non-interactive use like cron jobs and automated
869N/A# installation environments should not generate unnecessary
869N/A# progress information or warnings, as usage and configuration
868N/A# will have generally been debugged prior to automation.
789N/A#
941N/A
941N/AProgress()
911N/A{
941N/A if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
911N/A then
294N/A echo "${@}"
869N/A fi
869N/A}
941N/A
873N/AWarning()
872N/A{
941N/A if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
872N/A then
869N/A echo "WARNING: ${@}" 1>&2
994N/A fi
994N/A}
994N/A
994N/AError()
994N/A{
994N/A echo "ERROR: ${@}" 1>&2
869N/A}
869N/A
869N/AFatalError()
868N/A{
869N/A echo 1>&2
869N/A echo "FATAL ERROR: ${@} - Aborting!" 1>&2
869N/A echo 1>&2
869N/A ${DO} exit 2
868N/A}
870N/A
870N/A#
870N/A# Helper Functions - Autodetection of Runtime Environment
870N/A#
870N/A
869N/AWhich()
869N/A{
869N/A path="`which ${1} 2>/dev/null`"
869N/A
869N/A if [ -x "${path}" ]
869N/A then
869N/A echo "${path}"
912N/A fi
912N/A}
868N/A
789N/AFindExuberantCTags()
789N/A{
789N/A case "${OS_NAME}:${OS_VERSION}" in
789N/A SunOS:5.10) commandName="" ;;
789N/A SunOS:5.11) commandName="exctags" ;;
877N/A Linux:*) commandName="ctags-exuberant" ;;
877N/A *) commandName="" ;;
877N/A esac
877N/A
877N/A if [ -z "${commandName}" ]
787N/A then
294N/A Error "Unable to determine Exuberant CTags command name" \
789N/A "for ${OS_NAME} ${OS_VERSION}"
789N/A return
789N/A fi
789N/A
789N/A Which "${commandName}"
789N/A}
877N/A
877N/AFindJavaHome()
877N/A{
877N/A case "${OS_NAME}:${OS_VERSION}" in
877N/A SunOS:5.10) javaHome="/usr/jdk/instances/jdk1.6.0" ;;
789N/A SunOS:5.11) javaHome="/usr/jdk/latest" ;;
294N/A Linux:*) javaHome="/usr/lib/jvm/java-6-sun" ;;
869N/A *) javaHome="" ;;
869N/A esac
869N/A
869N/A if [ -z "${javaHome}" ]
869N/A then
869N/A Error "Unable to determine Java 6 Home" \
869N/A "for ${OS_NAME} ${OS_VERSION}"
869N/A return
294N/A fi
294N/A
294N/A if [ ! -d "${javaHome}" ]
294N/A then
294N/A Error "Missing Java Home ${javaHome}"
294N/A return
294N/A fi
294N/A
294N/A echo "${javaHome}"
294N/A}
869N/A
294N/AFindApplicationServerType()
294N/A{
869N/A # Use this function to determine which environment the deploy the
873N/A # web application function into. Some users (especially
873N/A # developers) will have many deployment environments or will wish
872N/A # to specify directly the application server to deploy to.
873N/A
873N/A # Either use the environment variable OPENGROK_APP_SERVER or
872N/A # reimplement this function in your configuration file (as
789N/A # specified by OPENGROK_CONFIGURATION)
789N/A
789N/A if [ -n "${OPENGROK_APP_SERVER}" ]
789N/A then
789N/A echo "${OPENGROK_APP_SERVER}"
789N/A return
789N/A fi
789N/A
789N/A # This implementation favours Tomcat, but needs a lot of work,
789N/A # especially if Glassfish is perferrerd or it is under the control
789N/A # of SMF (Service Management Facility)
789N/A
789N/A # Maybe a better implementation would be to call Application
789N/A # Server specific WAR Directory and see if they exist.
789N/A
789N/A if [ -d "/var/tomcat6/webapps" \
789N/A -o -d "/var/lib/tomcat6/webapps" \
789N/A ]
789N/A then
789N/A echo "Tomcat"
789N/A return
789N/A fi
789N/A
789N/A if [ -x "/etc/init.d/appserv" -a -d "/var/appserver/domains" ]
789N/A then
789N/A echo "Glassfish"
789N/A return
789N/A fi
789N/A
789N/A # Assume Tomcat
789N/A echo "Tomcat"
789N/A}
789N/A
789N/ADetermineWarDirectoryTomcat()
789N/A{
789N/A if [ -n "${OPENGROK_WAR_TARGET_TOMCAT}" ]
789N/A then
789N/A echo "${OPENGROK_WAR_TARGET_TOMCAT}"
789N/A return
789N/A elif [ -n "${OPENGROK_WAR_TARGET}" ]
789N/A then
789N/A echo "${OPENGROK_WAR_TARGET}"
789N/A return
789N/A fi
789N/A
789N/A for prefix in \
789N/A ${OPENGROK_TOMCAT_BASE} \
789N/A /var/tomcat6 \
789N/A /var/lib/tomcat6 \
789N/A
789N/A do
789N/A if [ -d "${prefix}/webapps" ]
789N/A then
294N/A echo "${prefix}/webapps"
789N/A return
789N/A fi
789N/A done
789N/A}
789N/A
789N/ADetermineWarDirectoryGlassfish()
789N/A{
789N/A
789N/A if [ -n "${OPENGROK_WAR_TARGET_GLASSFISH}" ]
789N/A then
789N/A echo "${OPENGROK_WAR_TARGET_GLASSFISH}"
789N/A return
789N/A elif [ -n "${OPENGROK_WAR_TARGET}" ]
789N/A then
789N/A echo "${OPENGROK_WAR_TARGET}"
789N/A return
789N/A fi
789N/A
789N/A for prefix in \
789N/A ${OPENGROK_GLASSFISH_BASE} \
789N/A /var/appserver \
789N/A
789N/A do
789N/A if [ -d "${prefix}/domains" ]
857N/A then
789N/A if [ -z "${domainDirectory}" ]
789N/A then
789N/A domainDirectory="${prefix}/domains"
789N/A fi
789N/A fi
789N/A done
789N/A
789N/A if [ -z "${domainDirectory}" ]
789N/A then
789N/A return
789N/A fi
789N/A
789N/A # User Specified Domain
789N/A if [ -n "${OPENGROK_GLASSFISH_DOMAIN}" ]
789N/A then
789N/A directory="${domainDirectory}/${OPENGROK_GLASSFISH_DOMAIN}/autodeploy"
789N/A
789N/A if [ ! -d "${directory}" ]
789N/A then
789N/A FatalError "Missing Specified Glassfish Domain ${OPENGROK_GLASSFISH_DOMAIN}"
789N/A fi
789N/A
789N/A echo "${directory}"
789N/A return
789N/A fi
789N/A
789N/A # Arbitrary Domain Selection
789N/A firstDomain=`ls -1 ${domainDirectory} | head -1`
789N/A
787N/A if [ -z "${firstDomain}" ]
789N/A then
789N/A FatalError "Failed to dynamically determine Glassfish Domain from ${domainDirectory}"
789N/A fi
789N/A
789N/A echo "${domainDirectory}/${firstDomain}/autodeploy"
789N/A}
789N/A
789N/A#
789N/A# Implementation
789N/A#
789N/A# The variable "DO" can usefully be set to "echo" to aid in script debugging
789N/A#
789N/A
789N/ALoadStandardEnvironment()
789N/A{
877N/A # Setup a standard execution environment (if required)
789N/A
789N/A OPENGROK_STANDARD_ENV="${OPENGROK_STANDARD_ENV:-/pkgs/sbin/CronExecutionEnvironment.sh}"
789N/A
789N/A if [ -f "${OPENGROK_STANDARD_ENV}" ]
789N/A then
789N/A Progress "Loading ${OPENGROK_STANDARD_ENV} ..."
789N/A . "${OPENGROK_STANDARD_ENV}"
789N/A fi
789N/A}
789N/A
789N/ALoadInstanceConfiguration()
789N/A{
789N/A # Note: As all functions have been defined by the time this routine
789N/A # is called, your configuration can, if desired, override functions
789N/A # in addition to setting the variables mentioned in the function
789N/A # DefaultInstanceConfiguration(), this maybe useful to override
789N/A # functionality used to determine the default deployment environment
789N/A # find dependencies or validate the configuration, for example.
789N/A
789N/A if [ -n "${OPENGROK_CONFIGURATION}" -a -f "${OPENGROK_CONFIGURATION}" ]
789N/A then
789N/A # Load the Local OpenGrok Configuration Environment
789N/A Progress "Loading ${OPENGROK_CONFIGURATION} ..."
789N/A . "${OPENGROK_CONFIGURATION}"
789N/A else
789N/A Progress "Loading the default instance configuration ..."
789N/A DefaultInstanceConfiguration
789N/A fi
789N/A}
789N/A
789N/AValidateConfiguration()
789N/A{
877N/A if [ ! -x "${EXUBERANT_CTAGS}" ]
789N/A then
789N/A FatalError "Missing Dependent Application - Exuberant CTags"
789N/A fi
789N/A
789N/A if [ ! -d "${SRC_ROOT}" ]
789N/A then
789N/A FatalError "OpenGrok Source Path ${SRC_ROOT} doesn't exist"
789N/A fi
789N/A}
787N/A
789N/ACreateRuntimeRequirements()
789N/A{
789N/A if [ ! -d "${DATA_ROOT}" ]
789N/A then
789N/A Warning "OpenGrok Generated Data Path ${DATA_ROOT} doesn't exist"
789N/A Progress " Attempting to create generated data directory ... "
789N/A ${DO} mkdir -p "${DATA_ROOT}"
789N/A fi
789N/A if [ ! -d "${DATA_ROOT}" ]
789N/A then
789N/A FatalError "OpenGrok Data Path ${DATA_ROOT} doesn't exist"
789N/A fi
789N/A
789N/A if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
789N/A then
789N/A Warning "OpenGrok Generated Etc Path ${OPENGROK_INSTANCE_BASE}/etc doesn't exist"
789N/A Progress " Attempting to create generated etc directory ... "
789N/A ${DO} mkdir -p "${OPENGROK_INSTANCE_BASE}/etc"
789N/A fi
789N/A if [ ! -d "${OPENGROK_INSTANCE_BASE}/etc" ]
789N/A then
789N/A FatalError "OpenGrok Etc Path ${OPENGROK_INSTANCE_BASE}/etc doesn't exist"
789N/A fi
789N/A
789N/A
789N/A}
789N/A
789N/AStdInvocation()
789N/A{
789N/A ${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
789N/A -jar ${OPENGROK_JAR} \
789N/A ${SCAN_FOR_REPOSITORY} ${VERBOSE} ${QUIET} \
789N/A ${EXUBERANT_CTAGS:+-c} ${EXUBERANT_CTAGS} \
789N/A -s ${SRC_ROOT} -d ${DATA_ROOT} \
789N/A "${@}"
789N/A}
789N/A
789N/AUpdateGeneratedConfiguration()
789N/A{
789N/A StdInvocation -W ${XML_CONFIGURATION}
789N/A}
789N/A
789N/AUpdateGeneratedData()
789N/A{
789N/A StdInvocation -H
789N/A}
789N/A
789N/AUpdateDescriptionCache()
789N/A{
789N/A # OPTIONAL : Update the EftarFile data
789N/A
789N/A if [ -n "${PATH_DESC}" -o -s "${PATH_DESC}" ]
789N/A then
789N/A ${DO} ${JAVA} -classpath ${OPENGROK_JAR} \
789N/A ${EFTAR_UPDATE} ${PATH_DESC} ${EFTAR_OUTPUT_FILE}
789N/A fi
787N/A}
294N/A
294N/AOpenGrokUsage()
294N/A{
789N/A ${DO} ${JAVA} ${JAVA_OPTS} -jar ${OPENGROK_JAR} '-?'
789N/A}
294N/A
789N/ADeployWar()
789N/A{
789N/A applicationServer="`FindApplicationServerType`"
789N/A
789N/A case "${applicationServer}" in
789N/A
789N/A Tomcat) warTarget="`DetermineWarDirectoryTomcat`" ;;
789N/A Glassfish) warTarget="`DetermineWarDirectoryGlassfish`" ;;
789N/A
789N/A *) FatalError "Unsupported Application Server ${applicationServer}" ;;
789N/A
789N/A esac
789N/A
789N/A if [ -z "${warTarget}" ]
789N/A then
789N/A FatalError "Unable to determine Deployment Directory for ${applicationServer}"
789N/A fi
789N/A
789N/A if [ ! -f "${OPENGROK_DIST_WAR}" ]
789N/A then
789N/A FatalError "Missing Web Application Archive ${OPENGROK_DIST_WAR}"
789N/A fi
789N/A
789N/A if [ ! -d "${warTarget}" ]
789N/A then
789N/A FatalError "Missing Deployment Directory ${warTarget}"
789N/A fi
789N/A
789N/A Progress "Installing ${OPENGROK_DIST_WAR} to ${warTarget} ..."
789N/A ${DO} cp "${OPENGROK_DIST_WAR}" "${warTarget}/"
789N/A if [ $? != 0 ]
789N/A then
789N/A FatalError "Web Application Installation FAILED"
789N/A fi
789N/A
789N/A Progress
789N/A Progress "Start your application server (${applicationServer}), if it is not already"
789N/A Progress "running, or wait until it loads the just installed web application."
789N/A Progress
789N/A Progress "OpenGrok should be available on <HOST>:<PORT>/source"
789N/A Progress " where HOST and PORT are configured in ${applicationServer}."
789N/A Progress
789N/A}
789N/A
873N/A#
873N/A# Main Program
873N/A#
873N/A
873N/Aif [ $# -ne 1 ]
873N/Athen
873N/A Usage
789N/Afi
789N/A
789N/ALoadStandardEnvironment
789N/A
789N/ALoadInstanceConfiguration
789N/A
789N/AValidateConfiguration
789N/A
789N/ACreateRuntimeRequirements
789N/A
857N/Acase "${1}" in
857N/A
857N/A deploy)
857N/A DeployWar
857N/A ;;
857N/A
857N/A update)
857N/A UpdateGeneratedData
857N/A UpdateDescriptionCache
857N/A ;;
857N/A
857N/A updateQuietly)
857N/A QUIET="-q"
857N/A VERBOSE=""
857N/A UpdateGeneratedData
857N/A UpdateDescriptionCache
869N/A ;;
868N/A
869N/A updateConfiguration)
869N/A UpdateGeneratedConfiguration
869N/A ;;
911N/A
911N/A usage)
869N/A OpenGrokUsage
917N/A ;;
917N/A
917N/A *)
917N/A Usage
869N/A ;;
868N/A
789N/Aesac
294N/A
294N/A#
294N/A# End of File
789N/A#
869N/A