#!/bin/sh
# mnogoreindex - Rebuilds database used by "kjbible" search tool
# License:  BSD-style (for this file only)
# Revision: 111216

MNTDIR=/mnt/kjbibledata

if [ "x$FORCEINDEX" == "x" ]; then
    LOOPFILE=/xzm/kjbibledata.xzm
    PROGNAME="King James Bible"
    TITLE="Not provided by this version"

    if [ -f $LOOPFILE ]; then
        mkdir -p $MNTDIR
        n=`ls $MNTDIR | wc -l`
        if [ $n = 0 ]; then
            sudo /bin/mount -o loop $LOOPFILE $MNTDIR
        fi
    else

MSG="Due to disk-space constraints,  this version of the distro omits
the $PROGNAME. You can get the package by booting a lar-
ger version."

        /laclin/lacutil/single-instance --wait --usewin \
"^$TITLE" \
/laclin/bin/zenity --error --no-wrap --title="$TITLE" --text="$MSG"
    exit 1
    fi
fi

P=__META_PREFIX__
INDEXER=$P/sbin/mnogoindexer

if [ -f $INDEXER ]; then
    PATH=$P/bin:$P/sbin:$PATH
    DATADIR=$MNTDIR
    DBFILE=$DATADIR/mnogosearch.db

    mkdir -p $DATADIR                       || exit 1
    rm -fr   $DBFILE                        || exit 1
    touch    $DBFILE                        || exit 1
    rm       $DBFILE                        || exit 1
    sqlite3  $DBFILE < $P/etc/create.txt    || exit 1

    NP=`getconf _NPROCESSORS_ONLN`
    NP=`expr $NP + $NP + 1`
    $INDEXER -N $NP
    $INDEXER -Eblob -N $NP
fi
