#!/bin/sh 
#
#	$Id: //depot2/idl/Installers/idl-unix-scripts/trunk/src/bridge_post_unpack#5 $
#
# unpack_idl
#
# This script expects to be run from the top level 'NV5' directory
# after IDL has been unpacked from the distribution media. It performs
# tasks that need to be run on the target machine to complete localization.
#
#	$1 - If $1 is non-empty, this script assumes that it's being
#	     run directly from the tty and offers the user the option
#	     of trimming excess binaries from the IDL tree. Otherwise, it
#	     limits itself to non-interactive setup tasks.

VERSION=92
ENVI_VERSION=__ENVISHORTVERSION__

# If this is an ENVI install, go into the envixx directory.
if [ "$1" = "ENVI" ]; then
  cd envi$ENVI_VERSION
fi

IDL_DIR=`pwd`/idl$VERSION
IDL_BIN=$IDL_DIR/bin
UDIR=`pwd`
ENVI_IDL_DIR=`pwd`
UNAME=`uname`


# Create the shell scripts bridge_setup, bridge_setup.ksh and 
# bridge_setup.bash, which can be used to set up the environment variables 
# required by the IDL connectivity bridges.
#
# C shell users should source bridge_setup from their .cshrc files,
# using the full path to the IDL directory as follows:
#    source full_path_to_IDL_Directory/idl_setup
# Korn shell users should run bridge_setup.ksh from their
# .profile file (using the ". bridge_setup.ksh" notation), as follows:
#    . full_path_to_IDL_Directory/bridge_setup.ksh
# Bash shell users should source bridge_setup from their .bashrc files,
# using the full path to the IDL directory as follows:
#    . full_path_to_IDL_Directory/bridge_setup.bash

echo "
# Korn and Bash shell commands to define IDL environment variables for the 
# connectivity bridges.
#
# These scripts can be used by IDL users who use ksh or bash as their 
# interactive shell to define the environment variables required 
# by IDL connectivity bridges using the following command:
#
# Korn shell users should run bridge_setup.ksh from their .profile file,
# using the full path the the IDL directory as follows:
#    . $IDL_DIR/bin/bridge_setup.ksh
# Bash shell users should source bridge_setup.bash from their .bashrc files,
# using the full path to the IDL directory as follows:
#    . $IDL_DIR/bin/bridge_setup.bash
#

ENVI_IDL_DIR=$ENVI_IDL_DIR
IDL_DIR=$IDL_DIR
export ENVI_IDL_DIR IDL_DIR

UNAME=\`uname\`

case \$UNAME in
	\"Linux\")
           ARCH=\".x86_64\"
           BIN_DIR=\"\$IDL_DIR/bin/bin.linux\$ARCH\"
           if [ \"\$LD_LIBRARY_PATH\" = \"\" ]; then
               LD_LIBRARY_PATH=\"\$BIN_DIR\"
           else
               LD_LIBRARY_PATH=\"\$BIN_DIR\":\"\$LD_LIBRARY_PATH\"
           fi
           export LD_LIBRARY_PATH
        ;;

	\"Darwin\")
           ARCH=\".x86_64\"
 	   BIN_DIR=\"\$IDL_DIR/bin/bin.darwin\$ARCH\"
           if [ \"\$DYLD_LIBRARY_PATH\" = \"\" ]; then
               DYLD_LIBRARY_PATH=\"\$BIN_DIR\"
           else
               DYLD_LIBRARY_PATH=\"\$BIN_DIR\":\"\$DYLD_LIBRARY_PATH\"
           fi
           export DYLD_LIBRARY_PATH
        ;;

        *)
        ;;
    
esac

PATH=\"\$PATH:\$BIN_DIR\"
export PATH

if [ \$CLASSPATH ];  then
    CLASSPATH=\"\$CLASSPATH\":.:\"\$IDL_DIR/resource/bridges/export/java/javaidlb.jar\"
else
    CLASSPATH=\".:\$IDL_DIR/resource/bridges/export/java/javaidlb.jar\"
fi
export CLASSPATH

" > $IDL_BIN/bridge_setup.ksh
chmod 755 $IDL_BIN/bridge_setup.ksh
cp $IDL_BIN/bridge_setup.ksh $IDL_BIN/bridge_setup.bash
chmod 755 $IDL_BIN/bridge_setup.bash

#-----------------------------------------------------------------

echo "
# C shell commands to define IDL environment variables for the 
# connectivity bridges.
#
# This script can be used by IDL users who use csh as their interactive shell
# to define the environment variables required by IDL connectivity bridges
# using the following command:
#
#    source $IDL_DIR/bin/bridge_setup


setenv ENVI_IDL_DIR $ENVI_IDL_DIR
setenv IDL_DIR $IDL_DIR

set UNAME=\`uname\`

switch (\$UNAME)
 	case \"Linux\":
           set ARCH=\".x86_64\"
           set BIN_DIR=\"\$IDL_DIR/bin/bin.linux\$ARCH\"
           if (\$?LD_LIBRARY_PATH == 0 )  then
               setenv LD_LIBRARY_PATH \"\$BIN_DIR\"
           else
               setenv LD_LIBRARY_PATH \"\$BIN_DIR\":\"\$LD_LIBRARY_PATH\"
           endif
        breaksw

	case \"Darwin\":
           set ARCH=\".x86_64\"
 	   set	BIN_DIR=\"\$IDL_DIR/bin/bin.darwin\$ARCH\"
           if (\$?DYLD_LIBRARY_PATH == 0)  then
               setenv DYLD_LIBRARY_PATH \"\$BIN_DIR\"
           else
               setenv DYLD_LIBRARY_PATH \"\$BIN_DIR\":\"\$DYLD_LIBRARY_PATH\"
           endif
        breaksw

        default:
endsw

set path = (\$path \$BIN_DIR)

if (\$?CLASSPATH == 0)  then
    setenv CLASSPATH \".:\$IDL_DIR/resource/bridges/export/java/javaidlb.jar\"
else
    setenv CLASSPATH \"\$CLASSPATH\":.:\"\$IDL_DIR/resource/bridges/export/java/javaidlb.jar\"
endif

" > $IDL_BIN/bridge_setup
chmod 755 $IDL_BIN/bridge_setup
