#!/bin/sh
#
# $Header: rdbms/admin/sqlpatch/sqlpatch /st_rdbms_12.1.0.2.0dbpsu/2 2016/05/12 10:49:52 surman Exp $
#
#
# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
#
#    NAME
#      sqlpatch - <one-line expansion of the name>
#
#    DESCRIPTION
#      <short description of component this file declares/defines>
#
#    NOTES
#      <other useful comments, qualifications, etc.>
#
#    MODIFIED   (MM/DD/YY)
#    apfwkr      05/11/16 - Backport
#                           apfwkr_ci_backport_22923409_12.1.0.2.160419fa-dbbp
#                           from st_rdbms_12.1.0.2.0fa-dbbp
#    surman      04/21/16 - 22923409: Add lib directory
#    surman      07/21/14 - Backport surman_bug-19178851 from main
#    apfwkr      05/29/14 - Backport mpradeep_bug-18151716 from main
#    mpradeep    05/15/14 - 18151716 - Fix perl issues
#    surman      07/09/14 - 19178851: Library path for different platforms
#    surman      11/29/12 - 15909914: More portable syntax
#    surman      11/26/12 - 15902847: Add ORACLE_HOME/bin to path
#    surman      11/09/12 - 15857388: Fix LD_LIBRARY_PATH
#    surman      10/31/12 - 14763881: Set ORACLE_HOME
#    surman      10/19/12 - 14787047: CDB support
#    surman      07/12/12 - 14165102: Creation

# 15909914: Ensure /bin and /usr/bin are in the path so we can find dirname
PATH=$PATH:/bin:/usr/bin
export PATH

# Set ORACLE_HOME based on the full path to this script, which is
# $ORACLE_HOME/sqlpatch
CWD=`dirname $0`
ORACLE_HOME=`dirname ${CWD}`
export ORACLE_HOME

# Ensure LD_LIBRARY_PATH includes the right directories
# 19178851: Different flavors of unix use different variables.  This code
# is modeled off of srvctl.
PLATFORM=`uname`
case ${PLATFORM} in 
HP-UX)
  LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
  export LD_LIBRARY_PATH
  ;;
AIX)
  LIBPATH=${ORACLE_HOME}/lib:${LIBPATH}
  export LIBPATH
  ;;
Linux)
  LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
  # Linux ( ppc64 || s390x ) => LD_LIBRARY_PATH lib32
  ARCH=`uname -m`;
  if [ "${ARCH}" = "ppc64" -o "${ARCH}" = "s390x" ]
  then
    LD_LIBRARY_PATH=${ORACLE_HOME}/lib32:${LD_LIBRARY_PATH}
  fi
  export LD_LIBRARY_PATH
  ;;
SunOS) 
  LD_LIBRARY_PATH_64=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH_64}
  export LD_LIBRARY_PATH_64
  LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
  export LD_LIBRARY_PATH
  ;;
OSF1)
  LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
  export LD_LIBRARY_PATH
  ;;
Darwin) 
  DYLD_LIBRARY_PATH=${ORACLE_HOME}/lib:${DYLD_LIBRARY_PATH}
  export DYLD_LIBRARY_PATH 
  ;; 
*)
  if [ -d ${ORACLE_HOME}/lib32 ];
  then
    LD_LIBRARY_PATH=${ORACLE_HOME}/lib32:${LD_LIBRARY_PATH}
  else
    LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
  fi
  export LD_LIBRARY_PATH
  ;;
esac

# Ensure PATH includes the right directories
PATH=$ORACLE_HOME/bin:$PATH
export PATH

# Just call the Perl under $ORACLE_HOME with the arguments
$ORACLE_HOME/perl/bin/perl -I$ORACLE_HOME/sqlpatch -I$ORACLE_HOME/rdbms/admin  -I$ORACLE_HOME/sqlpatch/lib $ORACLE_HOME/sqlpatch/sqlpatch.pl $@

