#!/bin/sh
# This script is primarily to be used in crontab
# It calls other scripts to do data collecting and indexing,
# then it rebuilds the result of hotest queries into the cache.

PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/5bin:/bin; export PATH
#CGI not allowed
if [ ! -z "$REMOTE_ADDR" ]; then
  exit
fi

# proxy server setting for flcollect.pl
# uncomment below line if you want ftplocate to use proxy for http
#
# http_proxy="http://your_proxy_server:3128/"; export http_proxy

cd /usr/local/www/cgi-bin/ftplocate

test -d filelist || mkdir filelist
test -d desc     || mkdir desc
test -d cache    || mkdir cache
test -f log.system || touch log.system
test -f log.user   || touch log.user
test -f log.map    || touch log.map
chown nobody cache log.system log.user log.map 

if ! ./flcollect.pl $*; then
  exit $?
fi
if ! ./flindex.pl $*; then
  exit $?
fi
if ! ./dcollect.pl; then
  exit $?
fi
if ! ./dindex.pl; then
  exit $?
fi

./fltop.pl 50|./fltrain.pl
rm /tmp/*tmp.[0-9]* /tmp/.*tmp.[0-9]* 2>/dev/null
exit 0
