#!/bin/csh -f
# ensure-cedar-server
# developed by Pavel; made popular by Christian
# Christian Jacobi, April 1, 1992 5:59:01 pm PST
#
#set path=(/project/cedar10.1/bin /bin /usr/bin)

/project/cedar10.1/bin/peekcedar

switch ($status)
case 0:	# normal termination, the server's working fine and the command worked
case 1: # abnormal termination, the server's OK, but the command failed
case 3: # abnormal termination, the server is screwed up
  exit
case 2: # no server there, fall through
endsw

# start the server
echo -n "Starting local Cedar server (it takes about 30 seconds) ..."
setenv COMMANDER←INITIAL←PERSIST TRUE
setenv COMMANDER←INITIAL←COMMAND /Cedar10.1/CedarFromUnix/StartCedarServer.cm
(CedarCommander /Cedar10.1/CedarFromUnix/StartCedarServer.cm > /tmp/cedar-server.log < /dev/null &)

# loop waiting for the server to get up
loop:

sleep 5
/project/cedar10.1/bin/peekcedar

switch ($status)
case 0:
  echo " done."
  exit (0)
case 2:
  echo -n "."
  goto loop
default:
  echo " ERROR ($status)\!"
  exit (1)
endsw