#!/bin/echo source_this_script

#
# A environment setup script for the The Community OpenORB (TCOO) project module OpenORB
#

#
# A message explaining the user how to resolve any problems
#

usage ()
{
    echo
    echo "The Community OpenORB (TCOO) environment has not been setup properly!"
    echo "The following folder layout is required:"
    echo
    echo "    <TCOO_HOME>"
    echo "        |- tools"
    echo "        |- OpenORB"
    echo "        |- <Any other module>"
    echo
    echo "The environment variable TCOO_HOME must be set to the root of the"
    echo "folder tree:"
    echo "    export TCOO_HOME=<TCOO_HOME>"
    echo
}


#
# Check the necessary folders and print a usage message upon failure
#

if [ -z $TCOO_HOME ]
then
    usage
    return 1
else
    if [ ! -d $TCOO_HOME/tools ]
    then
        usage
        return 2
    else
        if [ ! -d $TCOO_HOME/OpenORB ]
        then
            usage
            return 3
        fi
    fi
fi


#
# Change the CLASSPATH seperator for CYGWIN environments to ";" instead of ":"
#

case `uname` in
   CYGWIN*) PS=';' ;;
   *) PS=':' ;;
esac


#
# Set the library path
#

UNAME=`uname`
TCOO_LIB_PATH=${TCOO_HOME}/tools/lib
case "${UNAME}" in
   AIX)
      if test -z "${LIBPATH}"
      then
         LIBPATH=$TCOO_LIB_PATH
      else
         LIBPATH=$TCOO_LIB_PATH:$LIBPATH
      fi
      export LIBPATH
      ;;
   Linux|SunOS|CYGWIN*)
      if [ -z "${LD_LIBRARY_PATH}" ]; then
         LD_LIBRARY_PATH=$TCOO_LIB_PATH
      else
         LD_LIBRARY_PATH=$TCOO_LIB_PATH:$LD_LIBRARY_PATH
      fi
      export LD_LIBRARY_PATH
      ;;
   *)
      dump "Operating system '${UNAME}' not supported! Library path not set!"
      ;;
esac


#
# Set the path
#

echo "Setting environment for"

export PATH=$TCOO_HOME/tools/bin:$PATH
export PATH=$TCOO_HOME/OpenORB/bin:$PATH

if [ -d $TCOO_HOME/TransactionService ]
then
    echo "   TransactionService"
    export PATH=$TCOO_HOME/TransactionService/bin:$PATH
fi

if [ -d $TCOO_HOME/PersistentStateService ]
then
    echo "   PersistentStateService"
    export PATH=$TCOO_HOME/PersistentStateService/bin:$PATH
fi

if [ -d $TCOO_HOME/NamingService ]
then
    echo "   NamingService"
    export PATH=$TCOO_HOME/NamingService/bin:$PATH
fi

#if [ -d $TCOO_HOME/EvaluatorUtility ]
#then
#    echo "   EvaluatorUtility"
#    echo "...done!"
#fi

if [ -d $TCOO_HOME/NotificationService ]
then
    echo "   NotificationService"
    export PATH=$TCOO_HOME/NotificationService/bin:$PATH
fi

if [ -d $TCOO_HOME/TradingService ]
then
    echo "   TradingService"
    export PATH=$TCOO_HOME/TradingService/bin:$PATH
fi

if [ -d $TCOO_HOME/EventService ]
then
    echo "   EventService"
    export PATH=$TCOO_HOME/EventService/bin:$PATH
fi

if [ -d $TCOO_HOME/TimeService ]
then
    echo "   TimeService"
    export PATH=$TCOO_HOME/TimeService/bin:$PATH
fi

if [ -d $TCOO_HOME/ConcurrencyControlService ]
then
    echo "   ConcurrencyControlService"
    export PATH=$TCOO_HOME/ConcurrencyControlService/bin:$PATH
fi

if [ -d $TCOO_HOME/PropertyService ]
then
    echo "   PropertyService"
    export PATH=$TCOO_HOME/PropertyService/bin:$PATH
fi

#if [ -d $TCOO_HOME/SSL ]
#then
#    echo "   SSL"
#fi

if [ -d $TCOO_HOME/InterfaceRepository ]
then
    echo "   InterfaceRepository"
    export PATH=$TCOO_HOME/InterfaceRepository/bin:$PATH
fi

if [ -d $TCOO_HOME/ManagementBoard ]
then
    echo "   ManagementBoard"
    export PATH=$TCOO_HOME/ManagementBoard/bin:$PATH
fi

echo "Done!"

