#!/bin/ksh

#umask 002

LIBS=libs
PATH_SEPARATOR=":"
JAVA_SERVER_OPTION=""

case "$TEC_SYSNAME" in
  (Win32)
    PATH_SEPARATOR=";"
    ;;
  (Linux)
    JAVA_SERVER_OPTION="-server"
    ;;
  (SunOS)
    JAVA_SERVER_OPTION="-server"
    ;;
  (*)
esac

dirsToProcess="\
      csfs \
      jacorb \
"

for d in $dirsToProcess; do
    # alguns diretórios (p.ex. junit) podem não existir no ambiente de
    # produção
    test -d $LIBS/$d || continue
    DIR=$(print $d | tr "[a-z]" "[A-Z]")
    files=$(find $LIBS/$d -type d -name .svn -prune -o -type f -name '*jar' -print)
    eval "export JAR_$DIR=\"$(print $files | tr ' ' $PATH_SEPARATOR)\""
done

CSFS_CLASSPATH=\
$LIBS/csfs$PATH_SEPARATOR\
${JAR_CSFS}$PATH_SEPARATOR\
${JAR_JACORB}
echo $CSFS_CLASSPATH

rm -f csfs.pid
java $JAVA_SERVER_OPTION -Xmx128m -Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB -Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton -classpath "$CSFS_CLASSPATH" csfs.impl.Server ./server.ior.txt $* &
pid=$!
echo $pid > csfs.pid
# The exit status from this command is that of the last process waited for
wait $pid

STATUS=$?
if [ $STATUS -ne 0 ]; then #O valor 1 significa restart.
  echo 'Processo CSFS (JAVA) terminado ou não iniciado.'
fi


