#!/bin/sh

# variables
INDEXES='/usr/share/namazu/index/JF /usr/share/namazu/index/JMAN /usr/share/namazu/index/VineDocs'
BROWSER='gnome-open'
RCDIR="$HOME/.vhelpdesk"
RCFILE="$RCDIR/vhelpdeskrc"
OUTDIR="$RCDIR/results"
RESULT="$OUTDIR/`date +'%Y%m%d%H%M%S'`.html"
RESOPT=''

# Read  and  execute  commands from resource file if it's exists.
if [ -e $RCFILE ]; then
	source $RCFILE
fi

# If resource directory isn't exists, this script make it.
if [ ! -e $RCDIR ]; then
	mkdir $RCDIR
fi

# If output directory isn't exists, this script make it.
if [ ! -e $OUTDIR ]; then
	mkdir $OUTDIR
fi

# get settings from GConf.
if [ -x `which gconftool-2` ]; then  
	if [ `gconftool-2 -g /apps/vhelpdesk/UseGConf` = 'true' ]; then
		case `gconftool-2 -g /apps/vhelpdesk/ResultIndex` in
			"0")	RESOPT='-n 9';;
			"1")	RESOPT='-n 10';;
			"2")	RESOPT='-n 20';;
			"3")	RESOPT='-n 30';;
			"4")	RESOPT='-n 40';;
			"5")	RESOPT='-n 50';;
			"6")	RESOPT='-n 100';;
			"7")	RESOPT='-a';;
		esac
	fi
fi

# Search
namazu $RESOPT --html -o $RESULT "$1" $INDEXES

# Open search result.
$BROWSER $RESULT
