#! /bin/sh

# This script starts a new shell and sets all enviroment variables, which
# are necessary for building the examples of the Office Development Kit.
# The Script was developed for the operating systems Solaris and Linux.

# The SDK name
OO_SDK_NAME=OpenOffice.org1.1.3_SDK

# Installation directory of the Software Development Kit.
# Example: OO_SDK_HOME=/work/StarOffice_SDK
OO_SDK_HOME=/usr/lib/openoffice/sdk

# Office installation directory.
# Example: OFFICE_HOME=/opt/staroffice
OFFICE_HOME=/usr/lib/openoffice

# Directory of the make command.
# Example: OO_SDK_MAKE_HOME=/usr/bin
OO_SDK_MAKE_HOME=/usr/bin

# Directory of the C++ compiler.
# Example: OO_SDK_CPP_HOME=/usr/bin
OO_SDK_CPP_HOME=/usr/bin

# Directory of the Java SDK.
# Example: OO_SDK_JAVA_HOME=/usr/local/j2sdk1.4.1_01
OO_SDK_JAVA_HOME=@OO_SDK_JAVA_HOME@

# Environment variable to enable auto deployment of example components
# Example: SDK_AUTO_DEPLOYMENT=YES
SDK_AUTO_DEPLOYMENT=NO
export SDK_AUTO_DEPLOYMENT

# Special output directory
# Example: OO_SDK_OUTPUT_DIR=$HOME
#OO_SDK_OUTPUT_DIR=$HOME

# Check installation path for the StarOffice Development Kit.
if [ -z "$OO_SDK_HOME" ]
then
    echo Error: Please insert a correct value for the variable OO_SDK_HOME.
    exit 0
fi

export OO_SDK_HOME

# Check installation path for the office.
if [ -z "$OFFICE_HOME" ]
then
    echo Error: Please insert a correct value for the variable OFFICE_HOME.
    exit 0
fi

# Set office program path.
OFFICE_PROGRAM_PATH=$OFFICE_HOME/program

export OFFICE_PROGRAM_PATH

OO_EXAMPLE_OUT=$OO_SDK_HOME
# Prepare apropriate output directory.
if [ -n "$OO_SDK_OUTPUT_DIR" ]
then
    OO_EXAMPLE_OUT=$OO_SDK_OUTPUT_DIR/$OO_SDK_NAME
    export OO_SDK_OUTPUT_DIR
fi

# Get the operating system.
sd_platform=`uname -s`
sd_proctype=`uname -p`

# Set the directory name.
case $sd_platform in
  SunOS)
    if [ "$sd_proctype" = "sparc" ]
    then
        directoryname=solsparc
    else
        directoryname=solintel
    fi
    exampleout=SOLARISexample.out
    LD_LIBRARY_PATH=$OO_SDK_HOME/$directoryname/lib:$OO_EXAMPLE_OUT/$exampleout/lib:$OFFICE_PROGRAM_PATH:.:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH
    ;;

  Darwin)
    directoryname=macosx
    exampleout=MACOSXexample.out
    DYLD_LIBRARY_PATH=$OO_SDK_HOME/$directoryname/lib:$OO_EXAMPLE_OUT/$exampleout/lib:$OFFICE_PROGRAM_PATH:.:$DYLD_LIBRARY_PATH
    export DYLD_LIBRARY_PATH
    ;;

  Linux)
    directoryname=linux
    exampleout=LINUXexample.out
    LD_LIBRARY_PATH=$OO_SDK_HOME/$directoryname/lib:$OO_EXAMPLE_OUT/$exampleout/lib:$OFFICE_PROGRAM_PATH:.:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH
    ;;
esac

# Add directory of the SDK tools to the path.
PATH=$OO_SDK_HOME/$directoryname/bin:$OO_EXAMPLE_OUT/$exampleout/bin:$OFFICE_PROGRAM_PATH:.:$PATH

# Set the classpath
CLASSPATH=$OFFICE_PROGRAM_PATH/classes/jurt.jar:$OFFICE_PROGRAM_PATH/classes/unoil.jar:$OFFICE_PROGRAM_PATH/classes/ridl.jar:$OFFICE_PROGRAM_PATH/classes/sandbox.jar:$OFFICE_PROGRAM_PATH/classes/juh.jar:$CLASSPATH
export CLASSPATH


# Add directory of the command make to the path, if necessary.
if [ -n "$OO_SDK_MAKE_HOME" ]
then
    PATH=$OO_SDK_MAKE_HOME:$PATH
    export OO_SDK_MAKE_HOME
fi

# Add directory of the C++ tools to the path, if necessary.
if [ -n "$OO_SDK_CPP_HOME" ]
then
    PATH=$OO_SDK_CPP_HOME:$PATH
    export OO_SDK_CPP_HOME
fi

# Add directory of the Java tools to the path, if necessary.
if [ -n "$OO_SDK_JAVA_HOME" ]
then
    PATH=$OO_SDK_JAVA_HOME/bin:$PATH
#    JAVA_HOME=$OO_SDK_JAVA_HOME
#    export JAVA_HOME
    export OO_SDK_JAVA_HOME
fi

export PATH

# Starting a new shell with all necessary environment variables.
echo Starting shell with SDK environment.

echo "]2;Shell prepared with the SDK environment"

"$SHELL" "$@"
echo  Shell terminated.

TERMHEAD=`hostname`
echo "]2;$TERMHEAD"
