OpenGrok revision 787
294N/A#!/bin/sh
294N/A#
787N/A# OpenGrok Wrapper (initial setup and cron job updating)
787N/A# targeted against OpenSolaris + Debian , tomcat6 and glassfish
294N/A#
294N/A
787N/Aerror() { echo " ERROR: $@" ; }
787N/Awarning() { echo "WARNING: $@" ; }
787N/A# `date +%Y-%m-%d-%H-%M`
787N/A
294N/A#
294N/A# Usage
294N/A#
294N/A
294N/AUsage()
294N/A{
294N/A echo 1>&2
787N/A echo "Usage: ${0} <deploy|update|updateQuietly|updateConfiguration|usage>" 1>&2
787N/A echo "Optional env variables: "1>&2
787N/A echo "OPENGROK_CONFIGURATION - location of own config, see sample.env.conf" 1>&2
787N/A echo "e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf ./${0} ... " 1>&2
294N/A echo 1>&2
294N/A exit 1
294N/A}
294N/A
294N/A#
294N/A# Configuration
294N/A#
787N/A
787N/AOS=`/bin/uname`
787N/A
294N/Aif [ -n "${OPENGROK_CONFIGURATION}" -a -f "${OPENGROK_CONFIGURATION}" ]
294N/Athen
294N/A # Load the Local OpenGrok Configuration Environment
787N/A echo Loading ${OPENGROK_CONFIGURATION} ...
294N/A . "${OPENGROK_CONFIGURATION}"
294N/Aelse
294N/A # Use the built-in defaults. This section can be copied to its own
294N/A # file and tailored to your local requirements. Then simply set
294N/A # OPENGROK_CONFIGURATION=/path/to/your/configuration, before using
294N/A # this wrapper. It will save you hand editing in your settings
294N/A # on each new release. A sample Cron Entry might look like:
294N/A # 15 0 * * * OPENGROK_CONFIGURATION=/pkgs/etc/OpenGrok.sh /pkgs/sbin/OpenGrok updateQuietly
294N/A
787N/A # Note: below is doing some small autodetection, use own config in case it fails
787N/A
294N/A # Note: It is not really possible to ever provided defaults for
294N/A # these values which will run in every UNIX-like environment.
294N/A # So I have provided a set which are functional for a given
294N/A # environment on which you can based you own configuration.
294N/A
787N/A STANDARD_ENV=/pkgs/sbin/CronExecutionEnvironment.sh
787N/A
294N/A # Setup a standard execution environment
787N/A if [ -f $STANDARD_ENV ]
294N/A then
787N/A echo Loading $STANDARD_ENV ...
787N/A . $STANDARD_ENV
294N/A fi
294N/A
787N/A VARBASE="/var/opengrok"
787N/A
787N/A if [ x"$OS" = x"SunOS" ]; then
787N/A BINARYBASE="/usr/share/lib/java"
787N/A elif [ x"$OS" = x"Linux" ]; then
787N/A BINARYBASE="/usr/share/java"
787N/A fi
787N/A # BINARYBASE="./" in case of local execution ...
787N/A
294N/A # REQUIRED: Source Code/Repository Root
294N/A # (your source code or the root of all repositories)
787N/A SRC_ROOT="$VARBASE/src"
294N/A
294N/A # REQUIRED: OpenGrok Generate Data Root
294N/A # (for Lucene index and hypertext cross-references)
294N/A # This area is rebuilt by "update" / "updateQuietly"
787N/A DATA_ROOT="$VARBASE/data"
294N/A
294N/A # OPTIONAL: User Provided Source Path to Description Mapping (Tab Separated Value)
294N/A # (The user maintained source of the generated EftarFile file)
787N/A PATH_DESC="$VARBASE/paths.tsv"
294N/A
294N/A # REQUIRED: XML Configuration
294N/A # (the configuration used by Web/GUI interfaces)
787N/A XML_CONFIGURATION="$VARBASE/etc/configuration.xml"
294N/A
294N/A # REQUIRED: Java Archive of OpenGrok
294N/A # (user building from source code will find this other key
294N/A # files in the "dist" directory after the build is completed)
787N/A OPENGROK_JAR="$BINARYBASE/opengrok.jar"
294N/A
294N/A # REQUIRED: Exuberant CTags (http://ctags.sf.net)
787N/A if [ x"$OS" = x"SunOS" ]; then
787N/A EXCTAGS="exctags"
787N/A elif [ x"$OS" = x"Linux" ]; then
787N/A EXCTAGS="ctags-exuberant"
787N/A fi
787N/A EXUBERANT_CTAGS=`which $EXCTAGS`
787N/A # EXUBERANT_CTAGS="/pkgs/64-bit/release/ctags-5.7/bin/ctags"
294N/A
294N/A # REQUIRED: Java Home
787N/A if [ x"$OS" = x"SunOS" ]; then
787N/A JAVA_HOME="/usr/jdk/instances/jdk1.6.0"
787N/A #JAVA_HOME="/usr/jdk/latest/" # if we will be backwards compatible
787N/A elif [ x"$OS" = x"Linux" ]; then
787N/A JAVA_HOME="/usr/lib/jvm/java-6-sun/bin/"
787N/A fi
294N/A export JAVA_HOME
294N/A
294N/A # REQUIRED: Java Virtual Machine
294N/A JAVA="${JAVA_HOME}/bin/java"
294N/A
294N/A # OPTIONAL: Uncomment the following line if your source contains Mercurial repositories.
294N/A SCAN_FOR_REPOSITORY="-S"
294N/A
787N/A HG=`which hg`
787N/A CVS=`which cvs`
787N/A SVN=`which svn`
787N/A SCCS=`which sccs`
787N/A
294N/A # OPTIONAL: Override Built-in Properties
787N/A PROPERTIES="-Dorg.opensolaris.opengrok.history.Mercurial=$HG \
787N/A-Dorg.opensolaris.opengrok.history.cvs=$CVS \
787N/A-Dorg.opensolaris.opengrok.history.Subversion=$SVN \
787N/A-Dorg.opensolaris.opengrok.history.SCCS=$SCCS"
294N/A
294N/A # OPTIONAL: JVM Options
294N/A #JAVA_OPTS="-server -Xmx1024m"
294N/A
787N/A WAR="dist/source.war"
787N/A
294N/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
294N/A EFTAR_UPDATE="org.opensolaris.opengrok.web.EftarFile"
294N/A
294N/A # HARDCODED: Generated EftarFile (See web/*.jsp)
294N/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=
294N/A
294N/A # or alternatively, Be Verbose!
294N/A #VERBOSE="-v"
294N/Afi
294N/A
787N/Aif [ ! -x $EXUBERANT_CTAGS ] ; then
787N/Aecho "Exuberant ctags for $OS: $EXCTAGS not found or not executable, exiting until this dependency is resolved ..."
787N/Aexit 2
787N/Afi
787N/A
787N/Aif [ ! -d $SRC_ROOT ] ; then
787N/Aecho "The source path: $SRC_ROOT doesn't exist, exiting cowardly ..."
787N/Aexit 2
787N/Afi
787N/A
787N/Aif [ ! -d $DATA_ROOT ] ; then
787N/Aecho "Index path $DATA_ROOT nonexistent, attempting to create one ... "
787N/Amkdir -p $DATA_ROOT
787N/Afi
787N/A
294N/A#
294N/A# Implementation
294N/A#
294N/A
294N/A# The variable "DO" can usefully be set to "echo" to aid in script debugging
294N/A
294N/AStdInvocation()
294N/A{
294N/A ${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
294N/A -jar ${OPENGROK_JAR} \
294N/A ${SCAN_FOR_REPOSITORY} ${VERBOSE} ${QUIET} \
294N/A ${EXUBERANT_CTAGS:+-c} ${EXUBERANT_CTAGS} \
294N/A -s ${SRC_ROOT} -d ${DATA_ROOT} \
294N/A "${@}"
294N/A}
294N/A
294N/AUpdateGeneratedConfiguration()
294N/A{
294N/A StdInvocation -W ${XML_CONFIGURATION}
294N/A}
294N/A
294N/AUpdateGeneratedData()
294N/A{
294N/A StdInvocation -H
294N/A}
294N/A
294N/AUpdateDescriptionCache()
294N/A{
294N/A # OPTIONAL : Update the EftarFile data
294N/A
294N/A if [ -n "${PATH_DESC}" -o -s "${PATH_DESC}" ]
294N/A then
294N/A ${DO} ${JAVA} -classpath ${OPENGROK_JAR} \
294N/A ${EFTAR_UPDATE} ${PATH_DESC} ${EFTAR_OUTPUT_FILE}
294N/A fi
294N/A}
294N/A
294N/AOpenGrokUsage()
294N/A{
294N/A ${DO} ${JAVA} ${JAVA_OPTS} -jar ${OPENGROK_JAR} '-?'
294N/A}
294N/A
787N/A
787N/A
787N/ADeployWar()
787N/A{
787N/A# detection mechanism could be better, but as a starter this will do the job,
787N/A# if you expect more, write it, we accept patches !
787N/ACONTAINER=""
787N/A
787N/A# tomcat is preffered
787N/Aif [ x"$OS" = x"SunOS" ]; then
787N/A WARDIR=/var/tomcat6/webapps/
787N/Aelif [ x"$OS" = x"Linux" ]; then
787N/A WARDIR=/var/lib/tomcat6/webapps/
787N/Afi
787N/ACONTAINER="tomcat"
787N/A
787N/ADOMAINDIR=/var/appserver/domains
787N/A
787N/Aif [ ! -d $WARDIR ]; then
787N/A# test whether glassfish is there, only if tomcat webapp dir is not present
787N/A if [ -x /etc/init.d/appserv ]; then
787N/A if [ -d $DOMAINDIR ]; then
787N/A FIRSTDOMAIN=`ls -1 $DOMAINDIR | head -1`
787N/A WARDIR=$DOMAINDIR/$FIRSTDOMAIN/autodeploy/
787N/A CONTAINER="glassfish"
787N/A else
787N/A error "Glassfish installed, but cannot get first domain from $DOMAINDIR."
787N/A exit 1;
787N/A fi
787N/A else
787N/A error "$WARDIR doesn't exist, seems this combination of application container and $OS is unsupported"
787N/A exit 1;
787N/A fi
787N/Afi
787N/A
787N/A
787N/Aecho "Copying $WAR to $WARDIR , start your $CONTAINER or wait until it loads the war"
787N/Acp $WAR $WARDIR/
787N/ARC=$?
787N/Aif [ x$RC=x"0" ]; then
787N/Aecho "OpenGrok should be listening on HOST:PORT/source , where HOST and PORT are configured in your $CONTAINER."
787N/Aelse
787N/Aecho "There was a problem copying the web archive to target directory, consult error message above."
787N/Afi
787N/A
787N/A}
787N/A
294N/A#
294N/A# Main Program
294N/A#
294N/A
294N/Aif [ $# -ne 1 ]
294N/Athen
294N/A Usage
294N/Afi
294N/A
294N/Acase "${1}" in
294N/A
787N/A deploy)
787N/A DeployWar
787N/A ;;
787N/A
294N/A update)
294N/A UpdateGeneratedData
294N/A UpdateDescriptionCache
294N/A ;;
294N/A
294N/A updateQuietly)
294N/A QUIET="-q"
294N/A VERBOSE=""
294N/A UpdateGeneratedData
294N/A UpdateDescriptionCache
294N/A ;;
294N/A
294N/A updateConfiguration)
294N/A UpdateGeneratedConfiguration
294N/A ;;
294N/A
294N/A usage)
294N/A OpenGrokUsage
294N/A ;;
294N/A
294N/A *)
294N/A Usage
294N/A ;;
294N/A
294N/Aesac
294N/A
294N/A#
294N/A# End of File
294N/A#