#!/bin/csh
##
# Copyright (C) 1996-1999  IDS Software.  All Rights Reserved.
#
# This software is the confidential and proprietary information of
# IDS Software ("Confidential Information").  You shall not
# disclose such Confidential Information and shall use it only in
# accordance with the terms of the license agreement you entered into
# with IDS Software.
#
# IDS SOFTWARE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
# OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE, OR NON-INFRINGEMENT. IDS SOFTWARE SHALL NOT BE LIABLE FOR ANY
# DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
# DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
##

set self=$0
if ($self:h == $self) then
  setenv IDSS_HOME $PWD
else if ($self !~ /*) then
  setenv IDSS_HOME $PWD/$self:h
else
  setenv IDSS_HOME $self:h
endif

if (-e $IDSS_HOME/idss) then
  if ($?LD_LIBRARY_PATH) then
    setenv LD_LIBRARY_PATH ${IDSS_HOME}:$LD_LIBRARY_PATH
  else
    setenv LD_LIBRARY_PATH ${IDSS_HOME}
  endif
  if ("$1" == "-init") then
    $IDSS_HOME/idss $*
    exit
  endif
  set pidfile=$IDSS_HOME/Logs/idss.pid
  if (-e $pidfile) then
    set pid=`cat $pidfile`
    /bin/sh -c "kill -0 $pid 2> /dev/null"
    if ($status == 0) then
      echo IDS Server \(PID $pid\) is already running.
      exit
    endif
    rm $pidfile
  endif
  if ("$1" == "-con") then
    $IDSS_HOME/idss $*
  else
    echo IDSS_HOME=$IDSS_HOME
    $IDSS_HOME/idss $*
    sleep 1s
    if (!(-e $pidfile)) then
      sleep 2s
      if (!(-e $pidfile)) then
        echo IDS Server failed to start. Check system log for error message.
		exit
      endif
    endif
    set pid=`cat $pidfile`
    echo IDS Server \(PID $pid\) is started.
  endif
else
  echo This shell script cannot be copied out of the IDS Server directory.
endif
