#! /bin/sh -e
# Expects: <lurker-index> <config file>

idx="$1"
cfg="$2"

if test -z "$idx" || test ! -x $idx; then echo Cannot execute indexer; exit 1; fi
if test -z "$cfg" || test ! -f $cfg; then echo Cannot read config; exit 1; fi

idx=`which $idx`
if echo "$idx" | grep -q '^\.'; then idx="$PWD/$idx"; fi
if echo "$cfg" | grep -q '^[^/~]'; then cfg="$PWD/$cfg"; fi

dbdir=`grep "[ 	]*dbdir" $cfg | cut -d= -f2`
dbdir=`echo $dbdir`

cd $dbdir

test -d .tmp || mkdir .tmp
cd .tmp
mv -i ../* .
rm -f db.* db

for l in *; do
  echo Reindexing $l
  gzip -dfc < $l | $idx -c $cfg -l $l -v -b 5
done

cd ..
rm -rf .tmp
