#!/bin/sh

#
# 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 "        |- TransactionService"
    echo "        |- PersistentStateService"
    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
        else
            if [ ! -d $TCOO_HOME/TransactionService ]
            then
                usage
                return 4
            else
                if [ ! -d $TCOO_HOME/PersistentStateService ]
                then
                    usage
                    return 5
                fi
            fi
        fi
    fi
fi


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

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

echo "Setting environment..."

#
# Concatenate all the libraries in the lib directory and append
# it to the classpath environment variable
#
export CLASSPATH=`echo $TCOO_HOME/tools/lib/*.jar | tr ' ' ${PS}`${PS}$CLASSPATH
export CLASSPATH=`echo $TCOO_HOME/tools/lib/ext/*.jar | tr ' ' ${PS}`${PS}$CLASSPATH
export CLASSPATH=`echo $TCOO_HOME/OpenORB/lib/*.jar | tr ' ' ${PS}`${PS}$CLASSPATH
export CLASSPATH=`echo $TCOO_HOME/TransactionService/lib/*.jar | tr ' ' ${PS}`${PS}$CLASSPATH
export CLASSPATH=`echo $TCOO_HOME/PersistentStateService/lib/*.jar | tr ' ' ${PS}`${PS}$CLASSPATH
export CLASSPATH=`echo ./lib/*.jar | tr ' ' ${PS}`${PS}$CLASSPATH


#
# Add the bin folder to the path environment variable
#
export PATH=$TCOO_HOME/OpenORB/bin:$TCOO_HOME/TransactionService/bin:$TCOO_HOME/PersistentStateService/bin:$TCOO_HOME/NamingService/bin:$PATH

