#! /bin/sh

# Launch a process to scan and index files from the
# Pathena profiles named in arg list $*.
# This is the "quick" version that suppresses inessential
# cleanup and update tasks before and after indexing.
# Make sure full version runs periodically (e.g., weekly).


# 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

indexing_log=$PATHENA/log/indexing_log

for profile in $*; do
   echo -e \
     "\n$(date) -- >>>>> Start of quick indexing job for profile '$profile'." \
     >> $indexing_log
   echo -e "\n>>> Suppressing old file purge." >> $indexing_log
   nice -n 15 $PATHENA/bin/index_files $PATHENA/profiles/$profile 50 0 0 0 \
        2>> $PATHENA/log/index_err_log
   echo -e "\n>>> Suppressing statistics update." >> $indexing_log
   echo "$(date) -- <<<<< End of quick indexing job for profile '$profile'." \
        >> $indexing_log
done

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 &

