#!/bin/bash
ROOT=$(dirname $0)
source $ROOT/control.sh
source $ROOT/solr-rev
# stop p4d and solr, don't fail
echo "Stopping running services"
control stop noexit
# install solr? (SOLR_VERSION is set in solr-rev)
if [ ! -d $ROOT/libs/solr-$SOLR_VERSION ] ; then
if [ -e $ROOT/../../util/solr-$SOLR_VERSION.tgz ] ; then
echo "Extracting util version of solr..."
tar xf $ROOT/../../util/solr-$SOLR_VERSION.tgz -C $ROOT/libs/
else
echo "Downloading solr-$SOLR_VERSION..."
wget http://www.gtlib.gatech.edu/pub/apache/lucene/solr/4.5.1/solr-$SOLR_VERSION.tgz || exit 1
tar xf solr-$SOLR_VERSION.tgz -C $ROOT/libs/
fi
fi
# copy solr schema and the solr controller
echo "Updating schema.xml"
cp -f $ROOT/../build/solr-config/$SOLR_VERSION/schema.xml $ROOT/libs/solr-$SOLR_VERSION/example/solr/collection1/conf/schema.xml || exit 1
echo "Updating control script"
cp -f $ROOT/../build/scripts/solr-control.sh $ROOT/libs/solr-$SOLR_VERSION/example
# expand the depot zip
echo "Extracting test base server..."
if [ -d "$ROOT/libs/p4d/tmp/searchtest" ] ; then rm -rf $ROOT/libs/p4d/tmp/searchtest || exit 1 ; fi
unzip -q $ROOT/libs/testdepot/searchtest.zip -d $ROOT/libs/p4d
echo "Starting p4d and solr services..."
# start p4d and solr
control start