#!/bin/bash
#
# Run the thttpd in its own environment for nightview server
#
#

# print help
if [ "$1" == "-h" -o "$1" == "--help" ]; then
    echo "NIGHTVIEW package utilities 0.3.0, (C) 2001-2 F. Hroch, Monte Boo, Brno, CZ"
    echo "nightview - thttpd Script to start thttpd server as nightview http server."
    echo "Usage: $0 [-h|--help]"
    printf "\t-h print help"
    echo 
    echo "The packaged thttp server under debian has documented bug so it don't work correctly at now (end of 2002). Use the boa server or compile thttpd from sources."
    echo "This is a exmaple of the script to run http server. You can customize it as you needs."
    exit 0
fi


# create new web server root
cd /tmp
if [ ! -d nightview ]; then
   mkdir nightview
fi
cd nightview

# copy nightview.cgi to to this directory (link switch off the -nos, see below)
if [ "$1" == "" ]; then
  echo "Please, specify as a first parameter the full path to nightview.cgi"
  exit 1
fi
cp -f $1 .

# copy nightview.html to to this directory (link switch off the -nos, see below)
if [ "$2" != "" ]; then
  cp -f $2 .
  ln -sf $2 index.html
fi

# options:
# -p 7666  default port
# -r       chroot
# -u nobody default user
# -l thttpd.log   log to file
# -c nightview.cgi CGI file
# -nos 
exec /usr/sbin/thttpd -d /tmp/nightview -p 7666 -l /tmp/thttpd.log \
                      -i /tmp/thttpd.pid -c nightview.cgi -D -nos
# /home/f/thttpd-2.22beta4/thttpd
# /home/f/thttpd-2.22beta4/thttpd
