#!/bin/bash
# Created by Ben Okopnik on Thu Jan 15 23:41:56 CST 2009

WEBROOT="/var/www"

dir="$(pwd)"
db="$dir/search${dir##*/}"

# Exit if the database does not exist
[ -d "$db" ] ||  { /usr/bin/printf "$db not found - exiting...\n"; exit 1; }

sdir="$WEBROOT/search/${dir##*/}"
# Exit if the search directory with the proposed name already exists
[ -d "$sdir" ] && { /usr/bin/printf "$sdir already exists - exiting...\n"; exit 1; }

# Create the ".source" dir if it doesn't already exist and copy the key
# files into it
[ -d $WEBROOT/search/.source ] || {
	/bin/mkdir -p "$WEBROOT/search/.source"
	/bin/cp /usr/share/hyperestraier/estseek* $WEBROOT/search/.source
	/bin/cp /usr/lib/estraier/estseek.cgi $WEBROOT/search/.source
}

/bin/mkdir -p "$sdir"
cd "$sdir"
DB="$db" /usr/bin/perl -wpe's/^(indexname:).*$/$1 $ENV{DB}/' ../.source/estseek.conf > estseek.conf
/bin/ln -s ../.source/estseek.{cgi,help,tmpl,top} .
