#!/bin/sh

db_setupEnvironmentForPatch () {

    # Various Oracle utilities
    SQLPLUS=${ORACLE_HOME}/bin/sqlplus
    if [ ! -f "$SQLPLUS" ] ; then
        echolog 'FATAL: core database utilities missing.'
        return 1
    fi

    #
    # Check current Sun Management Center version. Some variables may be different depending
    # on this.
    #
    /usr/bin/pkginfo -q SUNWescom 1>/dev/null 2>&1
    if [ $? -ne 0 ] ; then
        echolog 'Sun Management Center missing or not properly installed. Aborting.'
        return 1
    fi

    SUNMC_VERSION=`/usr/bin/pkgparam SUNWescom SUNW_PRODVERS | /usr/bin/awk -F_ '{ print substr($1,0,3) }'`
    majver=`/bin/echo "$SUNMC_VERSION" | /usr/bin/cut -f1 -d.`

    ESTBL_BASEDIR=`/usr/bin/pkginfo -r SUNWestbl`
    if [ $? -ne 0 ] ; then
       echolog 'Unable to determine current database data directory'
       return 1
    fi
    if [ ! -d "$ESTBL_BASEDIR" ] ; then
       echolog 'SUNWestbl base directory is invalid: $2' "$ESTBL_BASEDIR"
       return 1
    fi
    ORA_DATADIR=$ESTBL_BASEDIR/db/oradata/SunMC
    ORA_INITFILE=$ORACLE_HOME/admin/$ORACLE_SID/pfile/initSunMC.ora
    NLS_LANG=AMERICAN_AMERICA.UTF8; export NLS_LANG
    VAR_ORA_DATADIR=$ESDIR/db/oradata/SunMC
    SMC_CONFIG_FILE=$ESROOT/db/cfg/db-memconfig.cfg
    if [ ! -f "$SMC_CONFIG_FILE" ] ; then
        echolog '$2 does not exist. Aborting.' "$SMC_CONFIG_FILE"
        return 1
    fi

    TEMPDIR=/tmp
    if [ ! -d "$TEMPDIR" ] ; then
        echolog '$2 does not exist. Aborting.' "$TEMPDIR"
        return 1
    fi

    return 0
}


/usr/bin/pkginfo -qi SUNWesora
[ $? -ne 0 ] && exit 0

BASEDIR=`/usr/bin/pkgparam SUNWescom BASEDIR`
. ${BASEDIR}/SUNWsymon/sbin/es-common.sh
set_basedir
set_db_env
. ${BASEDIR}/lib/sbin/db-common.sh
db_setupEnvironmentForPatch >/dev/null 2>&1

[ $? -ne 0 ] && exit 0   # expected error.

install_oracle_patches

exit 0

