#!/bin/csh -f
#
# Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 
#
#   NAME
#     installdriver
#
#   DESCRIPTION
#     Install Oracle Secure Backup's device driver.
#
#   MODIFIED   (MM/DD/YY) 
#   jwadleig   04/27/10 - remove driver for solaris. now using sgen
#   jwadleig   11/11/08 - merge from 10.2 -- update for AIX user space driver
#   asathyam   01/29/08 - AIX related changes for 10.2
#   jwadleig   09/29/06 - update for hp-ux64
#   rvullika   12/28/05 - Fix solaris64 install
#   tdziedzi   05/18/05 - Product name change 
#   tdziedzi   05/18/04 - Executables name change 
#   tdziedzi   03/05/04 - Update vendor/product name, copyright info 
#
# ******************************************************************************
#  Old changes (pre ade migration):
#     06/15/02 jrw  update copyright/IP notice.  Remove apollo accommodations.
#     12/03/01 gms  v3 mods
#     07/19/99 gms  linux server.
#     01/20/98 gms  use correct script name for solaris.
#     04/07/97 gms  mods for hpvxfs.
#     03/13/97 gms  merged rb2.2.1_branch to mainline.
#     02/21/97 gms  support (for hp800) -iotype arg.
#     01/10/95 gms  avoid grep -e.
#     11/02/95 jrw  comment updates for -UX 10.0.
#     07/18/95 jrw  expand path for AIX 4.1.
#     03/21/95 gms  fixed -y recognition.
#     11/28/94 gms  added trace.
#     09/01/94 gms  added sgi.
#     05/13/94 gms  merged ncr branch to mainline.
#     05/09/94 gms  added ncr86.
#     03/02/94 gms  setrbtmp.sh now part of initinstall.sh.
#     03/02/94 mbc  Added common init stuff.
#     02/28/94 jrw  don't redo the work of machinfo.sh; we were trashing the
#                   Auspex machine distinction.
#     02/03/94 kcl  /tmp => ${QR_TMP}
#     12/07/93 gms  added Solaris support.
#     04/28/93 gms  no driver install needed for HP-UX 9.0x.
#     01/05/93 gms  added /usr/bsd for sgi.
#     09/08/92 gms  fixed whoami check for sys5.
#     06/23/92 gms  support domain.
#     06/11/92 gms  added 9000/400.
#     06/03/92 gms  set path.
#
#   Usage:
#
#       installdriver [-f] [-c <config_file>] [-x]
#
#   -c <config_file>  can be used to override use of the default
#                     config file ("GENERIC") (Sparcstations only).
#   -iotype <sio or wsio> override iotype picked by hostinfo (hp800 only)
#   -f                forces kernel rebuild even if it has the
#                     correct version of the driver.
#   -x                turns on echo
#   -y                trace install routines

if (! $?OBTRACE) then
    echo "$argv" | grep "\-y" >&/dev/null
    if ( $status == 0 ) then
        setenv OBTRACE 1
    else
        setenv OBTRACE 0
        endif
    endif
if ($OBTRACE) then
    if (-f trenter) then
        trenter installdriver $argv
    else if (-f install/trenter) then
        install/trenter installdriver $argv
        endif
    endif

#--- Perform the common initialization ----------------------------------------

if (! $?installobinit) then
	if (-f initinstall.sh) then
		source initinstall.sh
		set st = $status
	else if (-f install/initinstall.sh) then
		source install/initinstall.sh
		set st = $status
	else
		echo "ERROR: No initinstall.sh program exists in either '.' or './install'.  Can't continue."
        exit(1)
        endif

    if ($st) exit ($st)
    endif

    set path = (. install /usr/ucb /usr/sbin /usr/bin /sbin /bin /usr/etc /etc /usr/bsd)
    set tmp  = ${OB_TMP}/obt$$

############################################################
#
#   look for -x (echo) option right away...

    echo $argv | grep "\-x" >&/dev/null
    if ( $status == 0 ) set echo

############################################################
#
#   allow execution from either OB or OB/install...

    if ( -f install/installdriver ) then
        set idir = $cwd/install
    else if ( -f installdriver ) then
        set idir = $cwd
    else
        unset echo
        echo "ERROR: Yout current directory must be either"
        echo "       ob or ob/install to run this script."
        goto failed
        endif

onintr userquit

############################################################
#
#   Make sure we've got the correct machine type and os rev...
#

    source $idir/machinfo.sh
    if ($?error) then
        echo "ERROR: can't determine machine information for this host: $error"
        goto failed
        endif


#  Do any special handling per OS type:

    set script_name = $idir/make_${base_arch}.sh
    switch ( $os_name )

        case solaris :
        case solaris64 :
            echo "NOTE: No driver installation is required for Solaris."
            set st = 0
            goto done
            breaksw

        #  Handle HP machines:
        case HP-UX :
        case hp-ux :

            #  machinfo.sh determines whether driver installation in the OS is needed.
            #  It leaves kernel_leaf set if so, unset if not.
            if (! $?kernel_leaf) then
                echo "NOTE: driver installation is not required for HP-UX ${os_ver}."
                set st = 0
                goto done
                endif
            breaksw

        #  And Big Blue:  which is easy now that we are in user space
        #   
        case AIX :
        case aix :
            echo "NOTE: No driver installation is required for AIX."
            set st = 0
            goto done
            breaksw

        #  sgi also easy:
        case IRIX :
            echo "NOTE: No driver installation is required for SGI."
            set st = 0
            goto done
            breaksw

        #  ditto linux flavors...
        case Linux :
            echo "NOTE: No driver installation is required for Linux."
            set st = 0
            goto done
            breaksw

        #  If the machine is unknown to us, report the appropriate error:
        default :
            echo "ERROR: installdriver: $os_name -- unsupported machine type."
            goto failed
            breaksw
        endsw

############################################################
#
#   if a script doesn't exist for this machine type, assume
#   it can't be a server...

    if ( ! -f $script_name ) then
        unset echo
        echo "ERROR: installdriver: there is no driver install script --"
        echo "       $script_name -- for this machine type."
        echo "       This machine can not be an Oracle Secure Backup server."
        goto failed
        endif

############################################################
#
#   must be root...

whoami |& grep root >&/dev/null
if ($status) then
    id |& grep "uid=0" >&/dev/null
    if ($status) then
        echo "You must be logged in as 'root' to install Oracle Secure Backup."
        echo "Please change your user identity to 'root' and re-run this program."
        exit (1)
        endif
    endif

############################################################
#
#   do the install...

    $script_name $argv
    set st = $status

done:
    rm -f $tmp >&/dev/null
    if ($OBTRACE) $idir/trexit installdriver $st
    exit ($st)

failed:
    set st = 1
    goto done

userquit:
    unset echo
    echo "ERROR: installdriver interrupted from console."
    set st = 9
    goto done

############################################################

