#!/bin/csh -f
@ STATUS = 0
echo " "
source ./.schedrc
if ( $status == 1 ) then
  echo "Cant set up program environment: 'source ./.schedrc' failed."
  exit 1
endif

cp /dev/null ${resourcelist}
echo $today > $cleandate
rm -rf  ${resv}/* >& /dev/null
rm -rf  ${printdir}/* >& /dev/null

#SET RESOURCE TYPE
echo -n "What type of resource do you want to schedule [HOST]?  "
set response = $<
if ( $response == "" ) then
  echo "HOST" > $resourcefile
else
  echo $response|cut -c1-10|tr 'a-z' 'A-Z' > $resourcefile
endif
@ STATUS = $STATUS + $status

echo " "
#HELP CHOOSE A REASONABLE TEMPLATE
echo "There are 3 pre-made reservation templates you can choose from:"
echo "   1) The hours from 8am to 5pm (default)."
echo "   2) The 1/2 hours from 12am to 12pm."
echo "   3) The hours from 12am to 12pm."
echo "   4) Make my own template."
echo " "
echo -n "CHOICE?  "
set option = $<
set option = `expr "$option" : '\(.\)'`

switch ( $option )
case 2:
  cp ${dir}/.template.half-hour_slots $template
  breaksw
case 3:
  cp ${dir}/.template.one-hour_slots $template
  breaksw
case 4:
  breaksw
default:
  cp ${dir}/.template.8-5_slots $template
  breaksw
endsw
nl $template > $numtemp
@ STATUS = $STATUS + $status


#SET DEFAULT POSTSCRIPT STATE
echo " "
echo -n "Do you want to use Postscript for printing [YES]? "
set response = $<
if ( `expr "$response" : '\(.\)'` !~ [nN] || $response == "" ) then
  cd $a2pssource
  make
  if ( $status == 0 ) then
     echo "ON" > $ps
     cp ./a2ps ${dir}/.a2ps
  else
     @ STATUS = $STATUS + 1
     echo "OFF" > $ps
     echo "Could not make a2ps; Postscript printing will be set to OFF."
     echo "Try to make the executable yourself, and change to Postscript"
     echo "printing later."
  endif
  cd $dir
else
  echo "OFF" > $ps
endif

#SET DEFAULT PRINTER
echo " "
SET_DEFAULT_PRINTER:
echo -n "What is the default printer name [lp]?  "
set response = $<
if ( $response == "" ) then
  set newprinter = lp
else
  set newprinter = $response
endif
if ( `lpstat -p|grep -c $newprinter` == 0 ) then
  echo "No such printer: ${newprinter}."
  goto SET_DEFAULT_PRINTER
endif
echo $newprinter > $printerfile
@ STATUS = $STATUS + $status


#SET DEFAULT REPORT FORMAT
echo " "
echo -n "What will be the default report format (FLAT|[MATRIX])?  "
set response = $<
if ( `expr "$response" : '\(.\)'` !~ [fF] || $response == "" ) then
  echo MATRIX > $reportfile
else
  echo FLAT > $reportfile
endif
@ STATUS = $STATUS + $status

#TRY TO DETERMINE IF DISPLAY IS VT100, TO MAKE NICE MENUS. IF NOT, TURN
#MENUING OFF.
setenv TERM `tset - vt100`
if ( $status != 0 ) then
  setenv TERM unknown
endif

echo Installation completed with $STATUS errors.
