###################################
# 
# $Header: coraenv.sh.pp 08-nov-96.11:12:35 hpiao Exp $ coraenv
# 
#
# Copyright 1987 Oracle Corporation
#
# This routine is used to condition a C shell user's environment
# for access to an ORACLE database.  It should be installed in
# the system local bin directory.
#
# The user will be prompted for the database SID, unless the variable
# ORAENV_ASK is set to NO, in which case the current value of ORACLE_SID
# is used.
# An asterisk '*' can be used to refer to the NULL SID.
#
# 'dbhome' is called to locate ORACLE_HOME for the SID.  If
# ORACLE_HOME cannot be located, the user will be prompted for it also.
# The following environment variables are set:
#
#	ORACLE_SID	Oracle system identifier
#	ORACLE_HOME	Top level directory of the Oracle system hierarchy
#	PATH		Old ORACLE_HOME/bin removed, new one added
#
# usage: source /usr/local/coraenv
#
#####################################

#
# Set minimum environment variables
#

if ($?ORACLE_SID == 0) then

    set ORASID=$LOGNAME
else
    set ORASID=$ORACLE_SID
endif
if ("$ORASID" == '' ) set ORASID='*'

if ($?ORAENV_ASK == 0 ) then
	set ORAENV_ASK=YES		#ORAENV_ASK suppresses prompt when set
endif

if ($ORAENV_ASK != NO ) then

    echo -n "ORACLE_SID = [$ORASID] ? "
    set READ=($<)

    if ("$READ" != '') set ORASID="$READ"
endif
if ("$ORASID" == '*') set ORASID=""
setenv ORACLE_SID "$ORASID"

if ($?ORACLE_HOME == 0) then
    set OLDHOME=$PATH		#This is just a dummy value so a null OLDHOME
else				#can't match anything in the switch below
    set OLDHOME=$ORACLE_HOME
endif

set ORAHOME=`dbhome "$ORASID"`
if ($status == 0) then
    setenv ORACLE_HOME $ORAHOME
else

    echo -n "ORACLE_HOME = [$ORAHOME] ? "
    set NEWHOME=$<

    if ($NEWHOME == "") then
	setenv ORACLE_HOME $ORAHOME
    else
	setenv ORACLE_HOME $NEWHOME
    endif
endif

#
# Reset LD_LIBRARY_PATH
#
if ($?LD_LIBRARY_PATH == 0) then
    setenv LD_LIBRARY_PATH $ORACLE_HOME/lib
else
    switch ($LD_LIBRARY_PATH)
    case *$OLDHOME/lib* :
        setenv LD_LIBRARY_PATH \
	    `echo $LD_LIBRARY_PATH | sed "s;$OLDHOME/lib;$ORACLE_HOME/lib;g"`
        breaksw
    case *$ORACLE_HOME/lib* :
        breaksw
    case "" :
        setenv LD_LIBRARY_PATH $ORACLE_HOME/lib
        breaksw
    default :
        setenv LD_LIBRARY_PATH $ORACLE_HOME/lib:${LD_LIBRARY_PATH}
        breaksw
    endsw
endif

#
# Adjust path accordingly
#

switch ($PATH)
case *$OLDHOME/bin* :
    setenv PATH `echo $PATH | sed "s;$OLDHOME/bin;$ORACLE_HOME/bin;g"`
    breaksw
case *$ORACLE_HOME/bin* :
    breaksw
case *[:] :
    setenv PATH ${PATH}$ORACLE_HOME/bin:
    breaksw
case "" :
    setenv PATH $ORACLE_HOME/bin
    breaksw
default :
    setenv PATH ${PATH}:$ORACLE_HOME/bin
    breaksw
endsw

unset ORASID ORAHOME OLDHOME NEWHOME READ

#
# Install local modifications here
#

