Open main menu

CDOT Wiki β

Changes

OpenGrok/script

3,860 bytes added, 21:39, 12 November 2008
New page: Here is the script to set up OpenGrok: <pre> #!/bin/bash #This script written by John Ford. #I hope it is useful to you but I take no responsibility #for any ensuing calamity. johnhford.g...
Here is the script to set up OpenGrok:
<pre>

#!/bin/bash
#This script written by John Ford.
#I hope it is useful to you but I take no responsibility
#for any ensuing calamity. johnhford.gmail@com

#NOTE:
# There are logs in your BASEDIR

#Mercurial Repository to use
REPO=http://hg.mozilla.org/mozilla-central

#Base directory for contents
BASEDIR=/home/jhford/mozilla

#This is the name of the data directory for OpenGrok
DATADIR=data-dir

#This is the name of the source directory for OpenGrok
SRCDIR=src-dir

#OpenGrok install path - Where is opengrok.jar?
OGDIR="/home/jhford/opengrok/opengrok-0.7"

#OpenGrok source.war from opengrok tarball
OGCONTEXT="grokzilla"
OGWAR="${OGCONTEXT}.war"

#Your application server's .war deployment directory
WEBAPPDIR="/home/jhford/tomcat/apache-tomcat-6.0.18/webapps"

#TODO:
# -Capture return values
# -Log all output of opengrok.jar
# -Test mercurial repo updates
# -Test what happens if OGDIR is not writable
# -Add option to download tomcat, opengrok to make it
# easy for a developer to isntall on their machine

#This function prints some useful information
function printinfo {
echo "Grokzilla Setup"
echo " Base Directory: $BASEDIR"
echo " Data Directory: $BASEDIR/$DATADIR"
echo " Source Directory: $BASEDIR/$SRCDIR"
echo " Repository: $REPO"
echo " OpenGrok Directory: $OGDIR"
echo " OpenGrok Web Archive: `pwd`/${OGWAR}"
echo " Web App Directory: $WEBAPPDIR"
}

#This function either checks out a new copy or
#updates an existing one
function checkout {
echo "Now checking out source"
mkdir -p $BASEDIR
if [ ! -e $BASEDIR/$DATADIR/.repo-created ]; then
echo " New checkout"
cd $BASEDIR
echo "## CHECKOUT AT `date --rfc-3339=seconds`" > $BASEDIR/checkout.log
rm -rf $BASEDIR/$DATADIR $BASEDIR/$SRCDIR
mkdir -p $BASEDIR/$DATADIR
hg clone $REPO $SRCDIR >> $BASEDIR/checkout.log
touch $BASEDIR/$DATADIR/.repo-created
else
echo " Updating hg repository"
cd $BASEDIR/$SRCDIR
echo "## UPDATE AT `date --rfc-3339=seconds`" >> $BASEDIR/checkout.log
hg up >> $BASEDIR/checkout.log
fi
}

#This function uses opengrok.jar to generate the data index
function generateOGData {
echo "The gurus are groking"
touch $BASEDIR/opengrok.jar.log
nice java -Xmx1524m -jar $OGDIR/opengrok.jar -W $BASEDIR/$DATADIR/configuration.xml \
-P -S -v -s $BASEDIR/$SRCDIR -d $BASEDIR/$DATADIR -w $OGCONTEXT \
>> $BASEDIR/opengrok.jar.log 2>>$BASEDIR/opengrok.jar.stderr.log
}

#Configure the WebApp to work with our src-dir and data-dir
function configureOGWar {
echo "Copying in $OGDIR/source.war and saving as $OGWAR"
#TODO: Maybe rename source.war to something if it is customized for mozilla
cp $OGDIR/source.war ./$OGWAR
unzip $OGWAR WEB-INF/web.xml > /dev/null
echo "Modifying source.war configuration"
echo "!! Warning !! This script uses sed to modify XML which is very hacky."
echo " if your deployed website isn't working it is likely the"
echo " 'configureOGWar' function in this script"
#echo " SED SCRIPT: s|/etc/opengrok|${BASEDIR}/${DATADIR}|"
sed -i -e "s|/etc/opengrok|${BASEDIR}/${DATADIR}|" WEB-INF/web.xml
sed -i -e "s|<!-- context-param>|<context-param>|" WEB-INF/web.xml
sed -i -e "s|</context-param-->|</context-param>|" WEB-INF/web.xml
sed -i -e "s|/directory/containing/data|$BASEDIR/$DATADIR|" WEB-INF/web.xml
sed -i -e "s|/directory/containing/src|$BASEDIR/$SRCDIR|" WEB-INF/web.xml
zip -u $OGWAR WEB-INF/web.xml > /dev/null
rm -rf WEB-INF
echo "Your WAR has been faught: `pwd`/$OGWAR"
}

#Deploy your war file to wherever you want it
function deployWar {
echo "Deploying $OGCONTEXT to $WEBAPPDIR"
cp $OGWAR $WEBAPPDIR
echo "All Done!"
}

printinfo
checkout
generateOGData
configureOGWar
deployWar

</pre>
1
edit