HTTP_ROOT="/usr/local/apache2"
HTML_ROOT="$HTTP_ROOT/htdocs"
CGI_ROOT="$HTTP_ROOT/cgi-bin"
echo "Attempting to install SARA data in $HTTP_ROOT ..."
if [ ! -d "$HTML_ROOT" ]; then
  echo "$HTML_ROOT does not exist, edit this script to point to html root"
  exit 1
fi
if [ ! -d $HTML_ROOT/sss ]; then
  mkdir $HTML_ROOT/sss
fi
if [ ! -d  "$CGI_ROOT" ]; then
 echo "CGI_ROOT doe not exist, edit this script to point to the cgi path"
 exit 1
fi
if [ ! -d $CGI_ROOT/sss ]; then
  mkdir $CGI_ROOT/sss
fi

sara_in="/tmp/sara-in"
if [ -d "$sara_in" ]; then
  echo "Loading web files"
  own=`ls -l /tmp | grep sara-in | awk '{print $3}'`
  cp sss.html $HTML_ROOT/sss/index.html
  cp *.gif $HTML_ROOT/sss
  cp sss.cgi $CGI_ROOT/sss
  cp ../bin/fping $CGI_ROOT/sss
  chmod +s $CGI_ROOT/sss/fping
  chown $own $HTML_ROOT/sss/index.html
  chown $own $CGI_ROOT/sss/sss.cgi
  chmod 700 $HTML_ROOT/sss/index.html
  chmod 700 $CGI_ROOT/sss/sss.cgi
  ps=`ps -def | grep sss.pl | grep -v grep`
  if [ -z "$ps" ]; then
   cd ..
   echo "Starting sss server"
   nohup sss/sss.pl > /dev/null &
  fi
else
  echo 'Can not find directory FIFO (/tmp/sara-in), install aborted'
fi


