OpenGrok revision 789
d2b2911c5530a5fec6e337a52ac906e14beea5f4Natanael Copa#!/bin/sh
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa#
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber# OpenGrok Wrapper (initial setup and cron job updating)
c63c04fcaf1c3a78c70500eae253d72fa9c8358aTAMUKI Shoichi#
d2b2911c5530a5fec6e337a52ac906e14beea5f4Natanael Copa# Supported Operating Systems:
d2b2911c5530a5fec6e337a52ac906e14beea5f4Natanael Copa# - Solaris 10 (SunOS 5.10)
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber# - OpenSolaris (SunOS 5.11)
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber# - Debian (Linux)
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber#
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber# Supported Deployment Engines
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber# - Tomcat 6
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber# - Glassfish
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber#
d2b2911c5530a5fec6e337a52ac906e14beea5f4Natanael Copa# Supported Environment Variables :
d2b2911c5530a5fec6e337a52ac906e14beea5f4Natanael Copa# - OPENGROK_NON_INTERACTIVE Suppress Progress and Warnings Messages
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber# - OPENGROK_STANDARD_ENV Run Time Shell Environment (Shell Script)
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa# - OPENGROK_CONFIGURATION User Configuration (Shell Script)
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa#
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa# Supported Environment Variables for configuring the default setup
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa# - OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa# - OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa# - EXUBERANT_CTAGS Full Path to Exuberant CTags
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa# - JAVA_HOME Full Path to Java Installation Root
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa# - OPENGROK_APP_SERVER Application Server ("Tomcat" or "Glassfish")
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen# - OPENGROK_WAR_TARGET_TOMCAT Tomcat Specific WAR Target Directory
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen# - OPENGROK_WAR_TARGET_GLASSFISH Glassfish Specific WAR Target Directory
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen# - OPENGROK_WAR_TARGET Fallback WAR Target Directory
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen# - OPENGROK_TOMCAT_BASE Base Directory for Tomcat (contains webapps)
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen# - OPENGROK_GLASSFISH_BASE Base Directory for Glassfish (contains domains)
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen# - OPENGROK_GLASSFISH_DOMAIN Preferred Glassfish Domain Name
abf117c398c957b213feebe3fa6dea3107c3a452Natanael Copa#
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen#
abf117c398c957b213feebe3fa6dea3107c3a452Natanael Copa# Usage
abf117c398c957b213feebe3fa6dea3107c3a452Natanael Copa#
abf117c398c957b213feebe3fa6dea3107c3a452Natanael Copa
abf117c398c957b213feebe3fa6dea3107c3a452Natanael CopaUsage()
abf117c398c957b213feebe3fa6dea3107c3a452Natanael Copa{
abf117c398c957b213feebe3fa6dea3107c3a452Natanael Copa echo 1>&2
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen echo "Usage: ${0} <deploy|update|updateQuietly|updateConfiguration|usage>" 1>&2
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen echo 1>&2
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen echo " Optional environment variables:" 1>&2
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen echo " OPENGROK_CONFIGURATION - location of your configuartion" 1>&2
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen echo " e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf ${0} ... " 1>&2
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen echo 1>&2
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen echo " See the code for more information on configuration options" 1>&2
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen echo 1>&2
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen exit 1
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen}
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa#
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa# Runtime Configuration
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen#
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael CopaOS_NAME="`/bin/uname -s`"
569bee5cc3d647032573db8f72734faa9307d577Natanael CopaOS_VERSION="`/bin/uname -r`"
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen#
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa# Default Instance Configuration
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa#
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael CopaDefaultInstanceConfiguration()
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa{
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # Use the built-in defaults. This section can be copied to its own
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # file and tailored to your local requirements. Then simply set
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # OPENGROK_CONFIGURATION=/path/to/your/configuration, before using
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # this wrapper. It will save you hand editing in your settings
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # on each new release. A sample cron(1M) entry might look like:
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # 15 0 * * * OPENGROK_CONFIGURATION=/pkgs/etc/OpenGrok.sh /pkgs/sbin/OpenGrok updateQuietly
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # Note: It is not really possible to ever provided defaults for
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # these values which will run in every UNIX-like environment.
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # So I have provided a set which are functional for a given
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # environment on which you can based you own configuration.
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # This has been updated to support more environment variables and
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # operating systems, if you have any reasonably generic
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # improvements please feel free to submit a patch.
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/var/opengrok}"
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa if [ -z "${OPENGROK_DISTRIBUTION_BASE}" ]
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa then
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa if [ -d "dist" -a -f "dist/opengrok.jar" -a -f "dist/source.war" ]
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa then
e00f9e4e7ab5a76cfd4068e09579f9f471666a90Natanael Copa # Handle Developer Build Environments
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa OPENGROK_DISTRIBUTION_BASE="`pwd`/dist"
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen else
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen # Handle Binary Distributions
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen OPENGROK_DISTRIBUTION_BASE="`pwd`"
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen fi
d2b2911c5530a5fec6e337a52ac906e14beea5f4Natanael Copa fi
d2b2911c5530a5fec6e337a52ac906e14beea5f4Natanael Copa
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen # REQUIRED: Source Code/Repository Root
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen # (your source code or the root of all repositories)
85b41c7d7f72213199b5cff9525d17f44b49a842Kaarle Ritvanen SRC_ROOT="${OPENGROK_INSTANCE_BASE}/src"
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # REQUIRED: OpenGrok Generate Data Root
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # (for Lucene index and hypertext cross-references)
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # This area is rebuilt by "update" / "updateQuietly"
670c6ab8caac48ce5cf043796dd8908114b7f607Natanael Copa DATA_ROOT="${OPENGROK_INSTANCE_BASE}/data"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # OPTIONAL: User Provided Source Path to Description Mapping (Tab Separated Value)
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # (The user maintained source of the generated EftarFile file)
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa PATH_DESC="${OPENGROK_INSTANCE_BASE}/etc/paths.tsv"
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # REQUIRED: XML Configuration
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # (the configuration used by Web/GUI interfaces)
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa XML_CONFIGURATION="${OPENGROK_INSTANCE_BASE}/etc/configuration.xml"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2e599a6a25b533fe63840edc34ee265811b7b814Natanael Copa # REQUIRED: Java Archive of OpenGrok (Installation Location)
0b8cdc10346baebe63b5ed87d11182720a1f67bbKaarle Ritvanen OPENGROK_JAR="${OPENGROK_INSTANCE_BASE}/opengrok.jar"
2e599a6a25b533fe63840edc34ee265811b7b814Natanael Copa
2e599a6a25b533fe63840edc34ee265811b7b814Natanael Copa # REQUIRED(deploy): Java Archive of OpenGrok (Distribution Location)
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # (user building from source code will find this and other key
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa # files in the "dist" directory after the build is completed)
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa OPENGROK_DIST_JAR="${OPENGROK_DISTRIBUTION_BASE}/opengrok.jar"
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa # REQUIRED(deploy): Web Archive of OpenGrok (Distribution Location)
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa # (user building from source code will find this and other key
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # files in the "dist" directory after the build is completed)
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa OPENGROK_DIST_WAR="${OPENGROK_DISTRIBUTION_BASE}/source.war"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # REQUIRED: Exuberant CTags (http://ctags.sf.net)
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa EXUBERANT_CTAGS="${EXUBERANT_CTAGS:-`FindExuberantCTags`}"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # REQUIRED: Java Home
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa JAVA_HOME="${JAVA_HOME:-`FindJavaHome`}"
646b1ef753d24d458ee5c2420cf4af16e4971f74Natanael Copa export JAVA_HOME
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
44f820e30b6fab2094dff1269a137983208b3b6dNatanael Copa # REQUIRED: Java Virtual Machine
44f820e30b6fab2094dff1269a137983208b3b6dNatanael Copa JAVA="${JAVA:-$JAVA_HOME/bin/java}"
44f820e30b6fab2094dff1269a137983208b3b6dNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # OPTIONAL: Scanning Options (for Mercurial repositories)
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa SCAN_FOR_REPOSITORY="-S"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
691ac4a3397a652dc163e4014720f3c6f4836052Kaarle Ritvanen # OPTIONAL: Full Path to History Utilities
691ac4a3397a652dc163e4014720f3c6f4836052Kaarle Ritvanen HG="`Which hg`"
691ac4a3397a652dc163e4014720f3c6f4836052Kaarle Ritvanen CVS="`Which cvs`"
691ac4a3397a652dc163e4014720f3c6f4836052Kaarle Ritvanen SVN="`Which svn`"
691ac4a3397a652dc163e4014720f3c6f4836052Kaarle Ritvanen SCCS="`Which sccs`"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # OPTIONAL: Override Built-in Properties
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # Assumption: We should not set properties to the empty string
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa PROPERTIES="\
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa${HG:+-Dorg.opensolaris.opengrok.history.Mercurial=$HG} \
3d460a3856376a043b3fa9addee50f89d21fa747Natanael Copa${CVS:+-Dorg.opensolaris.opengrok.history.cvs=$CVS} \
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa${SVN:+-Dorg.opensolaris.opengrok.history.Subversion=$SVN} \
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa${SCCS:+-Dorg.opensolaris.opengrok.history.SCCS=$SCCS} \
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # OPTIONAL: JVM Options
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa #JAVA_OPTS="-server -Xmx1024m"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # DELIVERED: An update program for EftarFile
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # Usage: <class> inputFile [inputFile ...] outputFile
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # EftarFile == An Extremely Fast Tagged Attribute Read-only File System
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa EFTAR_UPDATE="org.opensolaris.opengrok.web.EftarFile"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # HARDCODED: Generated EftarFile (See web/*.jsp)
48c63f8d035045af1103b677b5ec577aec59a5b5Natanael Copa EFTAR_OUTPUT_FILE="${DATA_ROOT}/index/dtags.eftar"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # Be Quiet? (set indirectly by command line arguments in the main program)
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa QUIET=
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # or alternatively, Be Verbose!
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa #VERBOSE="-v"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa}
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa#
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# Helper Functions - Logging
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa#
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# In general, non-interactive use like cron jobs and automated
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# installation environments should not generate unnecessary
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# progress information or warnings, as usage and configuration
2899ab0b1a607e7824214590ebe93f76fa7f7c20Natanael Copa# will have generally been debugged prior to automation.
2899ab0b1a607e7824214590ebe93f76fa7f7c20Natanael Copa#
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael CopaProgress()
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa{
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa then
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa echo "${@}"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa fi
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa}
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael CopaWarning()
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa{
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa if [ -z "${OPENGROK_NON_INTERACTIVE}" ]
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa then
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa echo "WARNING: ${@}" 1>&2
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa fi
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa}
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael CopaError()
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa{
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa echo "ERROR: ${@}" 1>&2
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa}
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael CopaFatalError()
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa{
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa echo 1>&2
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa echo "FATAL ERROR: ${@} - Aborting!" 1>&2
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa echo 1>&2
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa ${DO} exit 2
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa}
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa#
75b5535282453b3442a41df4a3ba6d3058cd6e48Natanael Copa# Helper Functions - Autodetection of Runtime Environment
75b5535282453b3442a41df4a3ba6d3058cd6e48Natanael Copa#
75b5535282453b3442a41df4a3ba6d3058cd6e48Natanael Copa
75b5535282453b3442a41df4a3ba6d3058cd6e48Natanael CopaWhich()
75b5535282453b3442a41df4a3ba6d3058cd6e48Natanael Copa{
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa path="`which ${1} 2>/dev/null`"
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa if [ -x "${path}" ]
1d1774b1ac705364c8eb7959a554935d8c134230Bogdan Purcareata then
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa echo "${path}"
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa fi
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa}
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael CopaFindExuberantCTags()
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa{
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa case "${OS_NAME}:${OS_VERSION}" in
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa SunOS:5.10) commandName="" ;;
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa SunOS:5.11) commandName="exctags" ;;
6ff9f8ec1c997d52fac089f9db929f1fea534faaNatanael Copa Linux:*) commandName="ctags-exuberant" ;;
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa *) commandName="" ;;
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa esac
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ -z "${commandName}" ]
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa then
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa Error "Unable to determine Exuberant CTags command name" \
6bd3f98c469f311f6afbffbb3586efddae3c4eb4Natanael Copa "for ${OS_NAME} ${OS_VERSION}"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa return
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa fi
6bd3f98c469f311f6afbffbb3586efddae3c4eb4Natanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa Which "${commandName}"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa}
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael CopaFindJavaHome()
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa{
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa case "${OS_NAME}:${OS_VERSION}" in
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa SunOS:5.10) javaHome="/usr/jdk/instances/jdk1.6.0" ;;
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa SunOS:5.11) javaHome="/usr/jdk/latest" ;;
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa Linux:*) javaHome="/usr/lib/jvm/java-6-sun/bin" ;;
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa *) javaHome="" ;;
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa esac
eee3ba81c88e64b8a732694fc4843a39d5bde491Serge Hallyn
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ -z "${javaHome}" ]
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa then
f24a52d5f588ff4e4575046903fb9498c376d833Stéphane Graber Error "Unable to determine Java 6 Home" \
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa "for ${OS_NAME} ${OS_VERSION}"
83828d6770ff2a186a2f17cba8e8a15a4dfb8ca8Natanael Copa return
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa fi
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ ! -d "${javaHome}" ]
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa then
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa Error "Missing Java Home ${javaHome}"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa return
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa fi
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa echo "${javaHome}"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa}
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael CopaFindApplicationServerType()
e5846a6f89db72bdbf3d651e5faf232045d17af8Natanael Copa{
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen # Use this function to determine which environment the deploy the
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen # web application function into. Some users (especially
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn # developers) will have many deployment environments or will wish
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn # to specify directly the application server to deploy to.
e5846a6f89db72bdbf3d651e5faf232045d17af8Natanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # Either use the environment variable OPENGROK_APP_SERVER or
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # reimplement this function in your configuration file (as
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # specified by OPENGROK_CONFIGURATION)
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ -n "${OPENGROK_APP_SERVER}" ]
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa then
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa echo "${OPENGROK_APP_SERVER}"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa return
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen fi
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # This implementation favours Tomcat, but needs a lot of work,
5be56973e5e874a142263dfb164b0b03e18a65f3Serge Hallyn # especially if Glassfish is perferrerd or it is under the control
5be56973e5e874a142263dfb164b0b03e18a65f3Serge Hallyn # of SMF (Service Management Facility)
5be56973e5e874a142263dfb164b0b03e18a65f3Serge Hallyn
5be56973e5e874a142263dfb164b0b03e18a65f3Serge Hallyn # Maybe a better implementation would be to call Application
5be56973e5e874a142263dfb164b0b03e18a65f3Serge Hallyn # Server specific WAR Directory and see if they exist.
5be56973e5e874a142263dfb164b0b03e18a65f3Serge Hallyn
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen if [ -d "/var/tomcat6/webapps" \
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen -o -d "/var/lib/tomcat6/webapps" \
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen ]
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen then
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa echo "Tomcat"
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen return
b1aa0624bae5a81d6f6bbc2653a388d148cffef8Natanael Copa fi
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ -x "/etc/init.d/appserv" -a -d "/var/appserver/domains" ]
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa then
b1aa0624bae5a81d6f6bbc2653a388d148cffef8Natanael Copa echo "Glassfish"
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen return
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa fi
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen # Assume Tomcat
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn echo "Tomcat"
b1aa0624bae5a81d6f6bbc2653a388d148cffef8Natanael Copa}
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael CopaDetermineWarDirectoryTomcat()
e5846a6f89db72bdbf3d651e5faf232045d17af8Natanael Copa{
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen if [ -n "${OPENGROK_WAR_TARGET_TOMCAT}" ]
e5846a6f89db72bdbf3d651e5faf232045d17af8Natanael Copa then
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen echo "${OPENGROK_WAR_TARGET_TOMCAT}"
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen return
982e7b6ea40ea57923f4f094858424debc1a5f7fKaarle Ritvanen elif [ -n "${OPENGROK_WAR_TARGET}" ]
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa then
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen echo "${OPENGROK_WAR_TARGET}"
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber return
b1aa0624bae5a81d6f6bbc2653a388d148cffef8Natanael Copa fi
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa for prefix in \
b1aa0624bae5a81d6f6bbc2653a388d148cffef8Natanael Copa ${OPENGROK_TOMCAT_BASE} \
5afb809607919f245e635a3883d7d7febb0caffaKaarle Ritvanen /var/tomcat6 \
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa /var/lib/tomcat6 \
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa do
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ -d "${prefix}/webapps" ]
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa then
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa echo "${prefix}/webapps"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa return
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa fi
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa done
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa}
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge HallynDetermineWarDirectoryGlassfish()
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn{
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ -n "${OPENGROK_WAR_TARGET_GLASSFISH}" ]
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa then
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa echo "${OPENGROK_WAR_TARGET_GLASSFISH}"
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa return
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa elif [ -n "${OPENGROK_WAR_TARGET}" ]
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa then
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber echo "${OPENGROK_WAR_TARGET}"
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber return
91828b0e1f7b2c88dab7708694e3d93ac6e6cf80Carlo Landmeter fi
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber for prefix in \
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber ${OPENGROK_GLASSFISH_BASE} \
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber /var/appserver \
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber do
0e18cacab53447931c82475920ca6a18a8fe29e2Natanael Copa if [ -d "${prefix}/domains" ]
0e18cacab53447931c82475920ca6a18a8fe29e2Natanael Copa then
0e18cacab53447931c82475920ca6a18a8fe29e2Natanael Copa if [ -z "${domainDirectory}" ]
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber then
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber domainDirectory="${prefix}/domains"
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber fi
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa fi
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael Copa done
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa if [ -z "${domainDirectory}" ]
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa then
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa return
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa fi
670c6ab8caac48ce5cf043796dd8908114b7f607Natanael Copa
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # User Specified Domain
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa if [ -n "${OPENGROK_GLASSFISH_DOMAIN}" ]
then
directory="${domainDirectory}/${OPENGROK_GLASSFISH_DOMAIN}/autodeploy"
if [ ! -d "${directory}" ]
then
FatalError "Missing Specified Glassfish Domain ${OPENGROK_GLASSFISH_DOMAIN}"
fi
echo "${directory}"
return
fi
# Arbitrary Domain Selection
firstDomain=`ls -1 ${domainDirectory} | head -1`
if [ -z "${firstDomain}" ]
then
FatalError "Failed to dynamically determine Glassfish Domain from ${domainDirectory}"
fi
echo "${domainDirectory}/${firstDomain}/autodeploy"
}
#
# Implementation
#
# The variable "DO" can usefully be set to "echo" to aid in script debugging
#
LoadStandardEnvironment()
{
# Setup a standard execution environment (if required)
OPENGROK_STANDARD_ENV="${OPENGROK_STANDARD_ENV:-/pkgs/sbin/CronExecutionEnvironment.sh}"
if [ -f "${OPENGROK_STANDARD_ENV}" ]
then
Progress "Loading ${OPENGROK_STANDARD_ENV} ..."
. "${OPENGROK_STANDARD_ENV}"
fi
}
LoadInstanceConfiguration()
{
# 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}"
else
Progress "Loading the default instance configuration ..."
DefaultInstanceConfiguration
fi
}
ValidateConfiguration()
{
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
}
CreateRuntimeRequirements()
{
if [ ! -d "${DATA_ROOT}" ]
then
Warning "OpenGrok Generated Data Path ${DATA_ROOT} doesn't exist"
Progress " Attempting to create generated data directory ... "
${DO} mkdir -p "${DATA_ROOT}"
fi
}
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()
{
applicationServer="`FindApplicationServerType`"
case "${applicationServer}" in
Tomcat) warTarget="`DetermineWarDirectoryTomcat`" ;;
Glassfish) warTarget="`DetermineWarDirectoryGlassfish`" ;;
*) FatalError "Unsupported Application Server ${applicationServer}" ;;
esac
if [ -z "${warTarget}" ]
then
FatalError "Unable to determine Deployment Directory for ${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} ..."
${DO} cp "${OPENGROK_DIST_WAR}" "${warTarget}/"
if [ $? != 0 ]
then
FatalError "Web Application Installation FAILED"
fi
Progress
Progress "Start your application server (${applicationServer}), if it is not already"
Progress "running, or wait until it loads the just installed web application."
Progress
Progress "OpenGrok should be available on <HOST>:<PORT>/source"
Progress " where HOST and PORT are configured in ${applicationServer}."
Progress
}
#
# Main Program
#
if [ $# -ne 1 ]
then
Usage
fi
LoadStandardEnvironment
LoadInstanceConfiguration
ValidateConfiguration
CreateRuntimeRequirements
case "${1}" in
deploy)
DeployWar
;;
update)
UpdateGeneratedData
UpdateDescriptionCache
;;
updateQuietly)
QUIET="-q"
VERBOSE=""
UpdateGeneratedData
UpdateDescriptionCache
;;
updateConfiguration)
UpdateGeneratedConfiguration
;;
usage)
OpenGrokUsage
;;
*)
Usage
;;
esac
#
# End of File
#