# run cgi scripts after copying them to kmldir directory
# runkmlcgi.sh <cgiscr> <parms>
cgiscr="$1"
parms="$2"
kmldir="kmldir"
if [ ! -d $kmldir/cgi-bin ] ; then
   mkdir $kmldir
   mkdir $kmldir/cgi-bin
fi
if [ -d $kmldir/cgi-bin ] ; then
   if [ -x "$cgiscr.cgi" ] ; then
      grep -v 'use CGI' $cgiscr.cgi >$kmldir/cgi-bin/$cgiscr.pl
      chmod 775 $kmldir/cgi-bin/$cgiscr.pl
      cd $kmldir
      cp -p ../htmldir/*file .
      cd cgi-bin
      cp -p ../../modeldir/*model.html .
      cp -p ../../modeldir/*style.css .
      ./$cgiscr.pl -d S $parms | tail -n +2 
   else
      echo "$0: Cannot find or execute $cgiscr, aborting"
      exit 1
   fi
else
   echo "$0: Cannot find directory $kmldir/cgi-bin, aborting"
   exit 1
fi