#!/bin/sh
export TIVOSH_POOLSIZE=2916352
shopt -s extglob
dir=${0%%+([^/])}
bin=${dir}httpd-tt.tcl

if \[ ! -f ${dir}GPL       ] || \
   \[ ! -f ${dir}copyright ] || \
   \[ ! -f ${dir}TRADEMARK ] || \
   \[ ! -x ${dir}bsearch   ] || \
   \[ ! -d ${dir}images    ] || \
   \[ ! -d ${dir}uploads   ] || \
   \[ ! -d ${dir}modules   ] ; then
  echo
  echo "!!ERROR!! tivoweb was not installed correctly"
  echo "please follow the instructions in the README"
  echo " -- the establishment"
  echo
  exit
fi

if \[ -f /etc/SubTest ] ; then
  echo
  echo "!!ERROR!! Invalid service state"
  echo
  exit
fi

if \[ -f $bin ] ; then
   if [ ${1:-null} == "console" ] ; then
      tivosh $bin &
   else
      tivosh $bin >> /dev/null 2>> /dev/null &
   fi
else
   echo "Error: could not locate httpd-tt.tcl in dir '${dir}'"
fi
