#!/bin/sh

# The environment variable $SRCHOME cannot be set during the installation
unset SRCHOME

AWK=/bin/awk
SED=/bin/sed
UNAME=/bin/uname

BUNDLE=crs

if [ `$UNAME` = "AIX" ]; then
   OSLEVEL=/bin/oslevel
   UNAME=/bin/uname
   CUT=/bin/cut

   if [ "hello$IGNOREOSLEVEL" = "hello" ]; then
        MAIN_VERSION=`$OSLEVEL -r | $CUT -d"-"  -f1`;
        MinorVersion1=`$OSLEVEL -r | $CUT -d"-"  -f2`;

        if [ $MAIN_VERSION -lt "5300" ]; then
                echo "\nrunInstaller needs minimum oslevel : "5300-05-06"\n";
                exit 0;
        fi

        if [ $MAIN_VERSION -eq "5300" ]; then
                if [ MinorVersion1 -lt "05" ]; then
                        echo "\nrunInstaller needs minimum oslevel : "5300-05-06"\n";
                        exit 0;
                else
                        if [ $MinorVersion1 -eq "05" ]; then
                                MinorVersion2=`$OSLEVEL -s | $CUT -d"-"  -f3`;
                                if [ $MinorVersion2 -lt "06" ]; then
                                        echo "\nrunInstaller needs minimum oslevel : "5300-05-06"\n";
                                        exit 0;
                                fi
                        fi
                fi
        fi
   fi
fi


if [ `$UNAME` = "SunOS" ]; then
   OCR_LOC=/var/opt/oracle/ocr.loc
else
   OCR_LOC=/etc/oracle/ocr.loc
fi

LOCALONLY=local_only
LOCAL=TRUE
SILENT=FALSE

CMDDIR=`dirname $0`

if [ "$CMDDIR" = "." ]; then
    CMDDIR=`pwd`;
fi

# Replace relative path with fully qualified path.
if [ ! "`echo $CMDDIR|grep '^/'`" ]; then
    CMDDIR=`pwd`/$CMDDIR;
fi

if [ x${PATH} != x ]; then
    PATH=/usr/bin:/usr/ccs/bin:$PATH:$CMDDIR/install
    export PATH 
else
    PATH=/usr/bin:/usr/ccs/bin:$CMDDIR/install
    export PATH
fi

# Determine whether there is an existing CRS or not.
# Local is value of local_only in ocr.loc.
# False means there is an existing CRS installation on the system.
if [ -r $OCR_LOC ]; then
    LOCAL=`$AWK -F= /$LOCALONLY/'{print $2}' $OCR_LOC |\
           $SED 'y/aeflrstu/AEFLRSTU/'`
fi

case "$BUNDLE" in
db)
# One-click: only if there is no cmd line argument and it's not on CRS node
if [ $# -gt 0 -o "$LOCAL" = "FALSE" -o \
     ! -r $CMDDIR/install/oneclick.properties ]; then
    $CMDDIR/install/.oui $*
else
    $CMDDIR/install/.oui -oneclick
fi
;;
client)
    $CMDDIR/install/.oui $* CLUSTER_NODES={}
;;
crs)
    $CMDDIR/install/.oui $* -formCluster
;;
dv)
    $CMDDIR/install/.oui $* -oneclick
;;
dbbundle)
    for arg in "$@"
        do 
            arg=`echo $arg | $SED 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
        if [ "$arg" = "-silent" ]; then
            SILENT=TRUE
            break
        fi
    done
        
    if [ "$SILENT" = "TRUE" ]; then
        $CMDDIR/install/.oui $*
    else
        $CMDDIR/install/.oui $* -oneclick -dbbundle
    fi
;;
*)
    $CMDDIR/install/.oui $*
;;
esac
