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