#! /bin/sh

# Launch a process to scan and index files from the
# Pathena profiles named in arg list $*.
# Perform "full" indexing (delete old files and update
# database statistics).


# Home directory for Pathena files is changed in this script
# by invoking script 'build/relocate'.

export PATHENA=~/.pathena

if [ -e $PATHENA/config/definitions ];
    then DEFS=config ;
    else DEFS=bin ;
fi
source $PATHENA/$DEFS/definitions

#export PYTHONPATH=$PATHENA/lib:$PATHENA/types:$PATHENA/server

echo -e "\n<<<>>> Beginning full batch indexing job on $(date)." \
     >> $PATHENA/log/indexing_log

for profile in $*; do
   if [ $profile == null_profile ]; then continue; fi
   echo -e "\n>>>>> Start of batch indexing job for profile '$profile'." \
        >> $PATHENA/log/indexing_log
   # Do each profile in "quick" indexing mode.
   nice -n 15 $PATHENA/bin/index_files $PATHENA/profiles/$profile 50 0 0 0 \
        2>> $PATHENA/log/index_err_log
   echo "<<<<< End of batch indexing job for profile '$profile'." \
        >> $PATHENA/log/indexing_log
done

# Afterwards, index the null profile in "full" mode.

nice -n 15 $PATHENA/bin/index_files $PATHENA/profiles/null_profile 50 0 \
        2>> $PATHENA/log/index_err_log

echo -e "\n<<<>>> Full batch indexing job complete on $(date)." \
     >> $PATHENA/log/indexing_log

sleep 5
echo -e "\nStarting PostgreSQL vacuum process on $(date)." \
     >> $PATHENA/log/ops_log
$PGBIN/vacuumdb -p $PGPORT -d pathena -z >> $PATHENA/log/ops_log 2>&1 &



