#!/bin/csh -f
#
# Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 
#
#   NAME
#     installob
#
#   DESCRIPTION
#     Oracle Secure Backup easy installation program
#
#   MODIFIED   (MM/DD/YY) 
#   kdayal     06/16/10 - Made change to set any_solaris flag in case of
#                         solarisx86 platform 
#   jwadleig   04/27/10 - remove solaris driver install
#   jwadleig   03/24/09 - clean up query for what to install
#   jwadleig   03/16/09 - Big 8335592: Fix query to be single system centric
#   asathyam   12/03/08 - Bug 7407987: Fix empty obconfig files
#   jwadleig   11/11/08 - Merge from 10.2 -- Increase maximum OSB lun to 128 for AIX
#   asathyam   04/20/08 - Fix the installer for AIX:- Tell user to uninstall 
#                         prior to installing on AIX
#   jwadleig   09/28/07 - add note to user about linux using /dev/sg devices
#   jwadleig   08/15/07 - fix bug 6152160  disable remote and batch install.. 
#                         leave code intact for now.
#   jwadleig   06/26/07 - remove code checking for quick restore installation
#   jwadleig   07/31/06 - Add support for linux86_64 and linuxia64
#   rvullika   03/28/06 - Support OSB upgrade with a new option "-n" 
#                         to installhere, some text changes
#   rvullika   03/07/06 - fix bug 5074329 
#   rvullika   01/25/06 - fix bug 4967707 and tighten the OSB install detection
#   rvullika   11/07/05 - some text fix, fixed a bug where we were accessing 
#                         rbadmindir[3] without making sure it existed
#   rvullika   09/07/05 - fixed a bug - when determining if a machine was ob
#                         admin or not we accessed obadmindir[3] without making
#                         sure that obadmindir was set. 
#   rvullika   08/12/05 - Call the new osbcvt to do database conversion
#   jwadleig   07/15/05 - Remove "Media Management" from titles.
#   rvullika   07/12/05 - Remove references to reliaty support email/phone 
#                         number (bug 4486205)
#   tdziedzi   05/18/05 - Product name change 
#   rvullika   04/28/05 - (Bug 4334532) Get the admin directory location from 
#                         /etc/obconfig or /etc/rbconfig (for Reliaty Backup)
#   rvullika   04/21/05 - s/Oracle Backup Installation Guide/
#                         Oracle Backup Media Management Installation Guide 
#   rvullika   04/14/05 - fix some user text
#   rvullika   03/03/05 - Fixed some text displayed to user
#   rvullika   02/16/05 - remove the use of "SCSI" from user facing text
#   rvullika   02/01/05 - fix bug 4149961
#   pmaseedu   01/11/05 - change "administrative host" to "administrative server"
#                         in user-facing text
#   rvullika   01/19/05 - Do not set install_gui to TRUE for remote admin
#   rvullika   12/14/04 - Add new media server option for local install
#   gstabler   11/16/04 - widened linux adapter number to 4 bits.
#   rvullika   11/04/04 - fix ob64 driver install
#   rvullika   10/29/04 - fix local OB client install
#   rvullika   10/18/04 - cleanup unsupported architectures
#   rvullika   10/12/04 - replace linux86-lfs with linux32
#   tdziedzi   09/17/04 - Update PDF document names 
#   rvullika   09/13/04 - Fix bug # 3517250
#   tdziedzi   08/30/04 - Remove license-related post install text 
#   rvullika   06/24/04 - Support for migration from rb to ob 
#   rvullika   06/11/04 - Add solaris64
#   tdziedzi   05/18/04 - Executables name change 
#   tdziedzi   03/05/04 - Update vendor/product name, copyright info 
#
# ******************************************************************************
#  Old changes (pre ade migration):
#     07/11/03 jrw  remove obsi references.
#     03/11/03 pfg  client only install mods.
#     10/25/02 jrw  Mirapoint eval device configuration for admin host re-enabled.
#     09/30/02 jrw  reduce dialog.
#     08/15/02 jrw  don't install solaris driver if Mirapoint eval.
#     07/01/02 jrw  don't ask webcheck questions for remote installs.  rather, always
#                   install web software on admins, never on media servers or clients.
#                   always default to "no" for locally attached devices.  Remove
#                   rbinventory function.
#     06/18/02 jrw  don't tell the user the name of the admin host, as it's no longer
#                   defined by installrb.  Move guichecksub into external webcheck.sh.
#                   Revise welcome mat.
#     06/15/02 jrw  update copyright/IP notice.
#     06/10/02 gms  undid next change;
#     07/07/02 gms  .drv.<arch> for all.
#     05/14/02 pfg  fixed bad filename on rand file.
#     04/07/02 pfg  up'ed the ssl certificate expiration from the default, 30 days
#                   to 730 days, aka 2 years.
#                   Create random file for rbopenssl use.
#     03/08/02 gms  install solaris driver only once; removed interauth logic.
#     02/11/02 pfg  rbopenssl mods.
#     01/30/02 gms  default SCSI stuff; install solaris driver before running sol_bus.sh.
#     01/10/01 gms  suggest rbcvt.
#     12/19/01 gms  fixed check for web server & verbiage.
#     12/17/01 gms  User's Guide now Installation Guide.
#     12/05/01 gms  removed obsolete dev queries (dte, error rate, etc.).
#     12/03/01 gms  v3 mods.
#     08/01/01 pfg  remove tape install support.
#     06/27/01 jrw  support linux86-lfs.
#     09/11/00 jrw  set dft to "would you like to edit <ndf>" to "no".
#     03/17/00 jrw  correct message about OBSI installation.
#     02/13/00 jrw  update for Alpha Linux.
#     01/17/00 jrw  remove 3 y/o falderall about converting pre-2.1 index files.
#     11/24/99 jrw  initialize 'linux' local variable.  Show solaris SCSI busses.
#                   Fix trouble-talking-with line length.
#     11/03/99 gms  prompt for dte number for drives in remote handlers.
#     09/13/99 gms  updated prompts in askdevsub.
#     08/26/99 gms  fixed double (e) option in "You may install as..." list.
#     08/15/99 jrw  support solx86.
#     08/12/99 gms  support remote drives.
#     07/19/99 gms  linux server.
#     04/06/99 jrw  support 8 devices/host.
#     01/03/99 jrw  fix qrparameters update logic for qr dir.
#     07/05/98 jrw  update for HP-UX 11.
#     05/18/98 jrw  fix spelling.
#     01/28/98 gms  fixed references to 2.1.
#     01/16/98 jrw  install obsi a/r.  Make install method 'b' the default.
#     11/25/97 gms  make sure target file system is large enough.
#     11/24/97 gms  nuked Option a.
#     08/15/97 gms  new phone number.
#     07/28/97 gms  use name-instance for rs6000 scsi buses.
#     06/24/97 gms  use '/' as separator in $drives.
#     05/21/97 gms  check for existence of /etc/qrconfig before using.
#     04/07/97 gms  mods for hpvxfs.
#     05/21/96 gms  limit logical unit numbers to 0-3 in askdevsub;
#                   print convert_index prompt at end.
#     04/17/96 gms  fixed scsi bus prompt.
#     04/08/96 gms  moved error rate query logic.
#     04/08/96  mj  don't post 2.1 upgrade text if indices.cur exists or no index files     
#     04/05/96  mj  unmatched double quote
#     04/02/96  mj  refinement of verbage
#     03/27/96  mj  Add verbage about index file conversion 
#     03/19/96  mj  Add verbage about backing up admin directory when upgrading
#     01/31/95 gms  merged in patch 6 changes.
#     01/30/95 gms  fixed scsi bus nomenclature for hpux at 10.x.
#     12/18/95 gms  loosened up scsi bus # checking (for hppa, hp68 bus paths).
#     11/02/95 gms  fixed changes of 12/16/94 & 10/26/95 for remote targets.
#     11/02/95 jrw  mods for HP-UX 10.0.
#     10/26/95 gms  fixes for solaris bus nomenclature.
#     04/17/95 jrw  make 'don't move qrdir' dft.  update qrparameters more carefully.
#     03/16/95 gms  fixed next fix for (at least) hp's csh.
#     03/10/95 dec  make sure we don't move /bin or /usr/bin when
#                   attempting to move qr directory; change "setenv idir" to
#                   "set idir=" in moveqr
#     02/26/95 jrw  correct refs to last_admin_host.  Setup last_admin_host file
#                   properly when user, in option b, asks to change admin host.
#                   allow quit out of 'install host as' question and answer loop.
#     02/13/95 jrw  handle reinstall/update on admin host gracefully.
#     12/16/94 gms  handle hp800 scsi bus paths.
#     11/28/94 gms  added trace.
#     11/15/94 gms  support install trace -- -y option.
#     11/14/94 gms  merged /hp branch to mainline.
#     11/08/94 gms  merged mainline to /hp branch.
#     11/07/94 jrw  improve handling of 'customized qrparameters'.
#     11/04/94 gms  fixed read of QR_TGT_TMP_LIST (bug 674)
#     11/01/94 gms  fixed option b for hp800 (makedev before installdriver).
#     10/19/94 jrw  enable hp800 as server, admin.
#     10/18/94 jrw  use informal machine name for admin host.  Remove sgi-as-client-only
#                   restriction.
#     09/21/94 gms  swap installdriver/makedev order for hp800.
#     07/26/94 jrw  remove unsetenv dependencies for SCO.  Be sensitive to missing
#                   cwd definition on SCO.
#     07/22/94 jrw  offer the user a chance to update qrparameters.
#     07/13/94 mbc  unconditionally get a new copy of mextract.sh if we want to
#                   source it - it just makes the logic cleaner...
#     07/07/94 mbc  don't set QR_TMP if already exists...
#     06/29/94 mbc  fix text for gui modules when doing interactive/remotes
#     06/23/94 mbc  be even more graceful about ...
#     06/18/94 jrw  be more graceful about tolerating // (apollo net root rel) names.
#     05/27/94 jrw  give a better explanation about EXB-10 autochangers the first
#                   time we pose the question; don't ask it if any media handlers
#                   are defined.
#     05/11/94 jrw  report incorrect authorization, let user try again
#     03/14/94 kcl  check free space on remote systems using tgttmproom.sh,
#                   added QR_TGT_TMP_LIST & user query for same in "batch" mode.
#     03/02/94 gms  no more setqrtmp.sh (now in initinstall.sh).
#     02/25/94 jrw  s/fml_mach_name/f_mach_name/.
#     02/25/94 mbc  SunOS syntax corrections.
#     02/24/94 jrw  syntactic tweaks.  Support short names gracefully.
#     02/16/94 kcl  fixed bug in gui install query logic; changed qri => xqr
#     02/10/94 kcl  changed "../bin/hostinfo" to "../.bin.$my_mach_arch/hostinfo"
#     02/04/94 kcl  added prompts/response for QR_TMP and QR_TGT_TMP
#     02/03/94 mbc  new 'modes'.
#     02/03/94 kcl  /tmp => ${QR_TMP}
#     01/30/94 jrw  Correct move-qr-directory code.
#     09/30/93 jrw  Improve "current software loaded" information.
#     09/27/93 mbc  Error messages from 'ls' command with AIX 3.2.4+ is ok now.
#     09/09/93 mbc  Error messages from 'ls' command are only different for AIX 3.2
#     08/20/93 gms  added prompts for scsi luns.
#     08/03/93 mbc  Oops - HP csh needs a value for setenv.
#     07/19/93 mbc  New install process; ripped out the media restoration stuff,
#                   which is now found in 'mextract.sh'.
#     07/15/93 mbc  change hp8008 and hp8009 into a single hp800.
#     06/18/93 mbc  gui name change.
#     04/26/93 mbc  added decult, hp8008, hp8009.
#     04/14/93 mbc  gui.
#     04/05/93 jrw  change tape server to media server.
#     02/16/93 jrw  on retry from installdriver in interactive mode, return to
#                   the right place.
#     02/11/93 jrw  reintegrate media handler development branch into mainline.
#                   update location specifier to makedev.
#     01/04/93 gms  added sgi.
#     12/07/92 jrw  correct head command by replacing it with sed.
#     12/05/92 jrw  support media handler devices.
#     11/25/92 jrw  refer to pathnames explicitly when rsh'ing.  Get rid of -1
#                   following ls.
#     11/24/92 gms  check status from initinstall.
#     11/18/92 jrw  Make domain admin and server nodes possible.
#     10/29/92 jrw  Get rid of unsetenv target_os_name before tgtmachinfo call.
#     09/25/92 jrw  correct showwhich label placement.
#     09/24/92 jrw  correct move operation.
#     09/21/92 gms  s/ez/installqr/.
#     09/10/92 jrw  made some Jimm Parsons requested improvements.  (Show option
#                   to display default device configs; floppy ejection; better
#                   error tolerance.)
#     09/08/92 jrw  accomodate tar-extract that replaces this program while it's
#                   running.  (What a pain!)
#     08/28/92 jrw  original coding.


goto maine


####################################################################################################
#  failcheck -- report a failure and retry the operation if the user asks
#
#  usage:
#       set failcheckret = <return-label>
#       goto failcheck
####################################################################################################

failcheck:

    echo " "
    echo "Sorry; the installation failed unexpectedly.  If the problem is obvious,"
    echo "please correct it.  (The error message is displayed above.)"
    echo " "
    echo -n "Would you like to retry this now [yes]? "
    set ayenay_dft = yes
    source $idir/ayenay.sh
    set st = $status
    unset ayenay_dft
    if ($st) goto $failcheckret
    echo " "
    echo "If you need help, please contact Oracle Support"
    echo "and we'll be happy to assist you."
    exit (1)

####################################################################################################
#  kernelmovesub -- renames the kernel if the user directs
#
#  usage:
#       set mach_name = <machine-name-of-interest>
#       set kernelmoveret = <return-label>
#       goto kernelmovesub
####################################################################################################

kernelmovesub:

    echo ""

    unset have_new_kernel
    if ($?my_ob_kerpath) then
        if (-e $my_ob_kerpath) set have_new_kernel
        endif

    if ($?have_new_kernel) then
        set reboot_list = ($reboot_list $mach_name)
        set os_move_list = ($os_move_list $mach_name)
        set my_preob_kerpath = "${my_kerpath}.preob"
        unset hp8_10
        if ($my_kerpath == "/stand/vmunix") set hp8_10
        echo "A new kernel has been generated on ${mach_name}.  Its name is ${my_ob_kerpath}."
        echo "This is a modified version of your existing kernel containing Oracle Secure Backup's"
        echo "high performance device driver."
        echo " "
        if (-e $my_preob_kerpath) then
            echo "Would you like to replace your existing kernel ($my_kerpath) with the new"
            echo -n "kernel now [yes]? "
        else
            echo "Would you like to rename your old kernel (to $my_preob_kerpath) and replace"
            echo -n "it with the new kernel now [yes]? "
            endif

        set ayenay_dft = yes
        source $idir/ayenay.sh
        set st = $status
        unset ayenay_dft

        if (! $st) then
            echo " "
            echo "When you're ready to proceed, perform the following commands:"
            if (! -e $my_preob_kerpath) then
                echo "    # mv $my_kerpath $my_preob_kerpath"
                if ($?hp8_10) echo "    # mv /stand/system /stand/system.preob"
                endif
            echo "    # mv $my_ob_kerpath $my_kerpath"
            if ($?hp8_10) echo "    # mv /stand/system.ob /stand/system"
            echo " "
            goto kmscheckval
            endif
        if (! -e $my_preob_kerpath) then
            if ($?showit) then
                echo '    #' mv $my_kerpath $my_preob_kerpath
                if ($?hp8_10) echo '    #' mv /stand/system /stand/system.preob
                endif
            if ($?doit) then
                mv $my_kerpath $my_preob_kerpath
                if ($?hp8_10) mv /stand/system /stand/system.preob
                endif
            endif

        if ($?showit) then
            echo '    #' mv $my_ob_kerpath $my_kerpath
            if ($?hp8_10) echo '    #' mv /stand/system.ob /stand/system
            endif
        if ($?doit) then
            mv $my_ob_kerpath $my_kerpath
            if ($?hp8_10) mv /stand/system.ob /stand/system
            endif
        set os_move_list[$#os_move_list] = ""
        echo " "
        endif


kmscheckval:
        endif

    goto $kernelmoveret

####################################################################################################
#  askdevsub -- setup device information for a host
#
#  usage:
#       set mode      = [server | admin]
#       set askdevret = <return-label>
#       set mach_name = <host-name-of-interest>
#       set mach_arch = <host-arch-of-interest>
#       set os_ver    = <host-os-version-of-interest>
#       set devtype   = d (to query for tape drives) or l (to query for tape libraries)
#
#       goto askdevsub
#
#  on return:
#       lun           = a list of logical units setup by this subroutine
#       scsi_adapter  = a list of host adapters for the corresponding units (linux only)
#       scsi_bus      = a list of scsi bus numbers for the corresponding units
#       scsi_target   = a list of scsi target ids for the corresponding units
#       scsi_lun      = a list of scsi luns for the corresponding targets
#       n             = the number of devices specified
####################################################################################################

askdevsub:

    unset linux
    unset hp800
    unset any_solaris
    set lun = ()
    set scsi_adapter = ()
    set scsi_bus = ()
    set scsi_target = ()
    set scsi_lun = ()
    set scsibustext = "address"
    if ($base_arch == hp800 || $base_arch == hppa) then
        if ($base_arch == hp800) set hp800
        echo $os_ver | grep '1[0-1]\.' >&/dev/null
        if ($status == 0) set scsibustext = "instance"
        endif
    if ($mach_arch == linux32 || $mach_arch == linux86_64 || $mach_arch == linuxia64) then
        set linux
    else if ($mach_arch == rs6000 ) then
        set scsibustext = "name-instance"
    else if ($mach_arch == solaris || $mach_arch == solaris64) then
        set scsibustext = "name-instance"
        set any_solaris
        if (! $?sol_bus_host) then
            set sol_bus_host = "$mach_name"
        else
            if ("$mach_name" != "$sol_bus_host") then
                set sol_bus_host = "$mach_name"
                unset sol_busses
                endif
            endif
        endif

    if ($mach_arch == ibm64) then
        set max_lun = 128
    else
        set max_lun = 7
        endif
     
    if ($?hp800) then
        source $idir/hp8buses.sh
        if ($status) goto failed
        endif

    if ($devtype == d) then
        set devtype_text  = "tape drive"
        set devtype_texts = "tape drives"
        set autosw = ()
        set erate = ()
        set location = ()
        set next_mh_pos = ()
    else
        set devtype_text  = "tape library"
        set devtype_texts = "tape libraries"
        endif

    if ($mode == admin || $devtype == l) then
        set ayenay_dft = no
        echo " "
        echo "Is $mach_name connected to any $devtype_texts that you'd like to use with"
        echo -n "Oracle Secure Backup [$ayenay_dft]? "
        source $idir/ayenay.sh
        set st = $status
        unset ayenay_dft

    else
        @ st = 1
        endif

    if ($st) then
        while (1)
            echo " "
            echo -n "How many Oracle Secure Backup $devtype_texts are attached to $mach_name [1]? "
            set answer = $<
            if ("$answer" == "") set answer = 1
            echo "$answer" | grep '[^0-9]' >&/dev/null
            if ($status == 0) then
                echo "Please enter an integer number."
            else
                if ($answer > 8) then
                    echo "Up to 8 $devtype_texts may be configured with this script."
                    echo "If you have more devices, please configure them using the makedev script."
                else
                    break
                    endif
                endif
            end
        @ n = $answer
    else
        @ n = 0
        endif


    if ($n > 0) then

        #  If we don't yet have solaris bus name info for the selected machine,
        #  get it here.
        #
        if ($?any_solaris && ! $?sol_busses) then
            set tmp = "$OB_TMP/obsol$$"
            if ("$my_mach_name" == "$mach_name") then
                prtconf -v >&$tmp
            else
                $rsh $mach_name /etc/prtconf -v >&$tmp
                set wclist = (`cat $tmp|wc`)
                if ($wclist[1] < 3) then
                    $rsh $mach_name /usr/sbin/prtconf -v >&$tmp
                    endif
                endif

            set wclist = (`cat $tmp|wc`)
            if ($wclist[1] < 3) then
                set sol_busses = ()
                echo "WARNING: couldn't get bus list from $mach_name:"
                cat $tmp
            else
                if ("$my_mach_name" == "$mach_name") then
                    set sol_busses = (`$idir/sol_bus.sh -q`)
                else
                    set sol_busses = (`$idir/../.bin.$my_mach_arch/hostinfo -P <$tmp`)
                    endif
                endif
            rm -f $tmp
            unset tmp
            endif


        unset use_dfts

        echo " "
        echo "Please describe each ${devtype_text} by answering the following questions."

        @ i = 1
        while ($i <= $n)
            if ($i == 1) then
                set which = first
            else if ($i == 2) then
                set which = second
            else if ($i == 3) then
                set which = third
            else if ($i == 4) then
                set which = fourth
            else if ($i == 5) then
                set which = fifth
            else if ($i == 6) then
                set which = sixth
            else if ($i == 7) then
                set which = seventh
            else if ($i == 8) then
                set which = eighth
                endif

            if (! $?use_dfts) then
                echo " "
                if ($n > 1) echo "For the $which ${devtype_text}:"
                endif


##########  get Logical unit number...

            @ dft_lun = $i - 1
            while (1)
                unset rmtdrv            # assume local drive
                if (! $?use_dfts) then
                    echo -n "    Oracle Secure Backup logical unit number [$dft_lun]: "
                    set answer = $<
                else
                    set answer = ""
                    endif

                if ("$answer" == "") then
                    set answer = $dft_lun
                    break
                    endif

                echo $answer | grep '[^0-9]' >&/dev/null
                if ($status == 0) then
                    echo "    Please enter an integer number."
                else
                    if ($answer >= 0 && $answer <= $max_lun) break
                    echo "    The logical unit number must be between 0 and [max_lun]."
                    echo "    (Please configure other units using install/makedev.)"
                    endif
                end

            set lun = ($lun $answer)
            set logical_unit = $answer


##########  get SCSI adapter number (linux only)...

            if ($?linux) then
                while (1)
                    if (! $?use_dfts) then
                        echo -n "    Host SCSI adapter number 0-15 [0]: "
                        set answer = $<
                    else
                        set answer = ""
                        endif
                    if ("$answer" == "") then
                        set answer = 0
                        endif
                    echo "$answer" | grep '[^0-9]' >&/dev/null
                    if ($status == 0) then
                        echo "    Please enter an integer number."
                    else
                        if ($answer < 0 || $answer > 15) then
                            echo "    Adapter number must be 0-15."
                        else
                            break
                            endif
                        endif
                    end
                set scsi_adapter = ($scsi_adapter $answer)
                endif


##########  get SCSI bus number...

            source $idir/setdevdfts.sh
            if ($?hp800) then
                set dft_scsi_bus    = $hp8buses[1]
                set dft_mh_scsi_bus = $hp8buses[1]
            else if ($?any_solaris) then
                if ($#sol_busses > 0) then
                    set dft_scsi_bus    = $sol_busses[1]
                    set dft_mh_scsi_bus = $sol_busses[1]
                    endif
                endif
            unset logical_unit

            if ($devtype == l) then
                set dft_scsi_bus = $dft_mh_scsi_bus
                set dft_scsi_target = $dft_mh_scsi_target
                endif

            if ($?hp800) then
                while (1)
                    if ($#hp8buses == 1) then
                        echo "    NOTE: only one scsi bus configured at ${hp8busesf}; using it."
                        set answer = $hp8buses[1]
                        break
                        endif
                    if (! $?use_dfts) then
                        echo -n "    SCSI bus $scsibustext (${hp8busesf}) [$dft_scsi_bus]: "
                        set answer = $<
                    else
                        set answer = ""
                        endif

                    if ("$answer" == "") then
                        set answer = $dft_scsi_bus
                        break
                        endif
                    unset busok
                    foreach xbus ($hp8buses)
                        if ($answer == $xbus) then
                            set busok
                            break
                            endif
                        end
                    if (! $?busok) then
                        echo "    You must specify ${hp8busesf}."
                    else
                        break
                        endif
                    end
                unset busok xbus
            else
                if (! $?use_dfts) then
                    unset shown_it
                    if ($?any_solaris) then
                        if ($#sol_busses > 1) then
                            set shown_it
                            echo -n "    SCSI bus $scsibustext (one of: $sol_busses) [$dft_scsi_bus]: "
                            endif
                        endif
                    if (! $?shown_it) echo -n "    SCSI bus $scsibustext [$dft_scsi_bus]: "
                    set answer = $<
                else
                    set answer = ""
                    endif

                if ("$answer" == "") then
                    set answer = $dft_scsi_bus
                    endif
                endif

            set scsi_bus = ($scsi_bus $answer)


##########  get SCSI target id...

            while (1)
                if (! $?use_dfts) then
                    echo -n "    SCSI target ID [$dft_scsi_target]: "
                    set answer = $<
                else
                    set answer = ""
                    endif

                if ("$answer" == "") then
                    set answer = $dft_scsi_target
                    break
                    endif
                echo "$answer" | grep '[^0-9]' >&/dev/null
                if ($status == 0) then
                    echo "    Please enter an integer number."
                else
                    break
                    endif
                end

            set scsi_target = ($scsi_target $answer)


##########  get SCSI LUN...

            while (1)
                if (! $?use_dfts) then
                    echo -n "    SCSI lun 0-7 [0]: "
                    set answer = $<
                else
                    set answer = ""
                    endif

                if ("$answer" == "") then
                    set answer = 0
                    break
                    endif
                echo "$answer" | grep '[^0-7]' >&/dev/null
                if ($status == 0) then
                    echo "    Please enter 0 to 7."
                else
                    break
                    endif
                end

            set scsi_lun = ($scsi_lun $answer)

            @ i = $i + 1
            end


#  Be sure our user has his or her head screwed on tightly:

        if (! $?use_dfts) then
            echo " "
            echo -n "Is the information you entered correct [yes]? "
            set ayenay_dft = yes
            source $idir/ayenay.sh
            set st = $status
            unset ayenay_dft
            if (! $st) goto askdevsub
            endif
        endif

    goto $askdevret

####################################################################################################
#
#  main program starts here
#
####################################################################################################

maine:

#   following is temporary, until we call initinstall.sh... but don't override if
#   user has already set it.

if (! $?OB_TMP) setenv OB_TMP "/tmp"

# To prevent us from overwriting ourselves, we move this script to a temp location,
# and exec from there.

if (! $?WE_MOVED) setenv WE_MOVED 0
if ("$WE_MOVED" != "0") then
    set iob = ${OB_TMP}"/`basename $0`"
    rm -f $iob
    cp $0 $iob
    chmod 755 ${OB_TMP}/installob
    setenv WE_MOVED twinkee
    exec $iob
    exit (0)
    endif

set sep = '-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -'
unset quiet
unset showit
unset rb_installed
unset rb_admin_installed
setenv install_gui FALSE

set   doit
set   reboot_list = ()
set   os_move_list = ()

# min_tmp_space is given in KB
set min_tmp_space = 16000

set myargs = ( $argv )
setenv OBTRACE 0
while ($#argv > 0)
    if ("$argv[1]" == "-quiet") then
        set quiet
    else if ("$argv[1]" == "-test") then
        set r_testing
        setenv R_TESTING 1
    else if ("$argv[1]" == "-mira") then
        set mira
        setenv MIRA 1
        set mirahost =  "$argv[2]"
        setenv MIRAHOST "$argv[2]"
        set miraid   =  "$argv[3]"
        setenv MIRAID   "$argv[3]"
        shift
        shift
    else if ("$argv[1]" == "-x") then
        set showit
    else if ("$argv[1]" == "-s") then
        set showit
        unset doit
    else if ("$argv[1]" == "-y") then
        setenv OBTRACE 1
        if (-f trenter) then
            trenter installob $myargs
        else if (-f install/trenter) then
            install/trenter install/installob $myargs
            endif
    else
        echo "Unknown command line option, $argv[1]."
        goto failed
        endif
    shift
    end


#  Say hi!

if (! $?quiet) then
    echo " "
    echo "Welcome to installob, Oracle Secure Backup's installation program."
    echo ""
    echo "For most questions, a default answer appears enclosed in square brackets."
    echo "Press Enter to select this answer."
    echo " "
    echo -n "Please wait a few seconds while I learn about this machine..."
    if ($OBTRACE) echo ""
    endif


#  Common initialization:

if (! $?installobinit) then
    if ($?r_testing && -f /ccs/rd/qr/install/initinstall.sh) then
        source /ccs/rd/qr/install/initinstall.sh
        set st = $status
    else 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 " "
        echo " "
        echo "No initinstall.sh program exists in either '.' or './install'.  Be"
        echo "sure to run the Oracle Secure Backup Easy Install program with your current"
        echo "directory set to the Oracle Secure Backup directory for this host."
        goto failed
        endif
    if ($st) goto failed
    endif

#  Get machine information.

source $idir/mymachinfo.sh
unset hp800
if ($my_base_arch == hp800) set hp800
unset any_solaris
if (($my_base_arch == solaris) || ($my_base_arch == solaris64) || ($my_base_arch == solarisx86_64)) set any_solaris
set last_admin = $my_mach_name


#  See if the Oracle Secure Backup parameters file has been customized.  If not, remind
#  the user that he or she should, at least, review it...

set ctmp = `grep -i <$obparameters "^[ 	]*customized[ 	][ 	]*obparameters:[ 	]"`
if ($#ctmp == 3) then
    if ($ctmp[3] == yes) then
        set obcustomized
    else
        set obnotcustomized
        endif
    endif
unset ctmp


if ($?ob_kernel_path) then
    set my_ob_kerpath = "$ob_kernel_path"
    set my_kerpath    = "$kernel_path"
    endif

#  See if Oracle Secure Backup (or a portion of it) has already been installed on
#  this host.
#  Note : 
#      There is a chance that a zero byte obconfig file could be present. In that case
#      discard the file and rewrite the contents.

if (-f /etc/obconfig) then
    #Check if empty /etc/obconfig is present, if yes delete it
    if (-z /etc/obconfig) then
        rm -rf /etc/obconfig
    else
        set ob_dir = `grep -i < /etc/obconfig "^[       ]*ob[        ][      ]*dir:[         ]"`
        if (-d $ob_dir[3]/bin && -d $ob_dir[3]/etc) set ob_installed
        set obadmindir = `grep -i < /etc/obconfig "^[       ]*admin[        ][      ]*dir:[         ]"`
        if ($#obadmindir >= 3) then
            if (-e $obadmindir[3]/state/general/vol-sequence && $?ob_installed) set ob_admin_installed
        endif
    endif
endif

#  See if Reliaty Backup is already installed on this host

if (-f /etc/rbconfig) then
    set rbdir = `grep -i < /etc/rbconfig "^[ 	]*rb[ 	][ 	]*dir:[ 	]"`
    if (-d $rbdir[3]/bin && -d $rbdir[3]/etc) then
        set rb_installed = 1
    else
        set rb_installed = 0
        endif
    set rbadmindir = `grep -i < /etc/rbconfig "^[ 	]*admin[ 	][ 	]*dir:[ 	]"`
    if ($#rbadmindir >= 3) then 
        if (-e $rbadmindir[3]/state/general/vol-sequence && $?rb_installed) then
            set rb_admin_installed = 1
        else
            set rb_admin_installed = 0
            endif
        endif
    endif

set ob_driver_ins = no
if ($?kernel_path) then
    nm $kernel_path | grep ob_driver_version >/dev/null
    if ($status == 0) set ob_driver_ins = yes
else
    set ob_driver_ins = unknown
    endif


if (! $?quiet) echo " done."


#  User 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.  Please"
        echo "change your user identity to 'root' and re-run this program."
        goto failed
        endif
    endif


#  If obparameters hasn't been customized, let the user know...

if (! $?obcustomized && ! $?quiet) then
    echo ""
    echo "Have you already reviewed and customized $obparameters for your"
    echo -n "Oracle Secure Backup installation [yes]? "
    set ayenay_dft = yes
    source $idir/ayenay.sh
    set st = $status
    unset ayenay_dft
    if ($st) then
        if ($?obnotcustomized) then
            /bin/ed - $obparameters >/dev/null <<!
1
/^[ 	]*customized[ 	][ 	]*obparameters:[ 	]/
s,:.*,: yes,
w
q
!
            endif
    else
        echo -n "Would you like to do this now [yes]? "
        set ayenay_dft = yes
        source $idir/ayenay.sh
        set st = $status
        unset ayenay_dft
        if ($st) then
            echo ""
            echo "After you've reviewed and updated $obparameters, re-run installob."
            goto done
            endif
        endif
    endif


#  See if we've got any direction from obparameters as to whether to prompt about
#  the Oracle Secure Backup directory being in a non-recommended place:

set ask_about_ob_dir
set ctmp = `grep -i <$obparameters "^[ 	]*ask[ 	][ 	]*about[ 	][ 	]*ob[ 	][ 	]*dir:[ 	]"`
if ($#ctmp == 5) then
    if ($ctmp[5] == no) then
        unset ask_about_ob_dir
        endif
    endif


#  If we're not in /usr/local/oracle/backup, complain:

set obdir = "/usr/local/oracle/backup"
set ob_dbdir = "$obdir/admin/state/general"
unset moved
set dir_name = "$obdir"
source $idir/iscwd.sh
unset dir_name

if ($?cwd) then
    set local_cwd = "$cwd"
else
    set local_cwd = "`pwd`"
    endif

set node_rel_cwd = "$local_cwd"
if ("$local_cwd" =~ //*) then
    set node_rel_cwd = `echo "$local_cwd" | sed -e 's,//[^/][^/]*\(/.*\)$,\1,'`
    endif

if ($?fail) then
    unset fail

#  Make sure we aren't trying to install in /, /usr. /usr/local.  That would be Bad.
#  (and an easy mistake to make)

    if (("$node_rel_cwd" == "/") || ("$node_rel_cwd" == "/usr") ||("$node_rel_cwd" == "/usr/local")) then
        echo "$sep"
        echo " "
        echo "You are attempting to install Oracle Secure Backup in $node_rel_cwd"
        echo "on $my_mach_name.  Please create a separate Oracle Secure Backup"
        echo "directory (Oracle recommends $obdir),"
        echo "and extract the Oracle Secure Backup software into that directory."
        echo "See the Oracle Secure Backup Installation Guide for more information."
        goto failed
        endif

#  Make sure we aren't try an "in-place" upgrade from RB. That could cause problems 
#  during uninstall of RB

if (-f /etc/rbconfig) then
    if (("$node_rel_cwd" == "$rbdir[3]") && ($?rb_installed)) then
        echo "$sep"
        echo " "
        echo "An existing Reliaty Backup installation was found on $my_mach_name."
        echo "You are attempting an \'in-place\' upgrade of Reliaty Backup to"
        echo "Oracle Secure Backup on $my_mach_name. This type of upgrade is not supported."
        echo "Please create a separate Oracle Secure Backup directory"
        echo "(Oracle recommends $obdir),"
        echo "and extract the Oracle Secure Backup software into that directory."
        echo "You can choose to migrate the admin directory from the existing Reliaty"
        echo "Backup installation to the new Oracle Secure Backup installation."
        echo "See the Oracle Secure Backup Installation Guide for more information."
        goto failed
        endif
    endif

checkmove:

    if ($?ask_about_ob_dir && ! $?mira) then
        echo " "
        echo "Oracle recommends that you install Oracle Secure Backup in"
        echo "$obdir.  Doing so will make operation of this software correspond"
        echo "with its Reference Manual.  (Oracle Secure Backup currently resides in"
        echo "$node_rel_cwd on this machine, $my_mach_name.)  Would you"
        echo -n "like to move it to $obdir now [no]? "
        set ayenay_dft = no
        source $idir/ayenay.sh
        set st = $status
        unset ayenay_dft
    else
        set st = 0
        endif

    if ($st) then

        set stuff_to_move = (.* *)
        shift stuff_to_move
        shift stuff_to_move


        #  This little embarrasing piece of code keeps us from tar'ing this
        #  directory recursively.

        @ i = 1
        while ($i <= $#stuff_to_move)
            if ($stuff_to_move[$i] == usr   || \
                $stuff_to_move[$i] == local || \
                $stuff_to_move[$i] == oracle    || \
                $stuff_to_move[$i] == backup) set stuff_to_move[$i]
            @ i = $i + 1
            end


        set ob_home = "$obdir"
        if (-d $obdir) then
            echo " "
            echo "An Oracle Secure Backup directory already exists at $obdir.  You may --"
            echo "    (a) delete $obdir and replace it with this Oracle Secure Backup"
            echo "        directory, $node_rel_cwd (be careful\!);"
            echo "    (b) merge this Oracle Secure Backup directory into ${obdir}, thereby"
            echo "        updating the software while preserving any existing databases;"
            echo "    (c) change to $obdir and run this installation program from"
            echo "        there; or,"
            echo "    (d) abort the installation now."
            echo " "
            echo -n "Which would you like to do? "

            while (1)
                set answer = $<
                if ("$answer" == "") goto checkmove
                if ("$answer" == a || "$answer" == b || "$answer" == c || "$answer" == d) break
                echo -n "Please choose one of a - d: "
                end


            if ($answer == a) then
                if ($?showit) echo '    #' rm -rf $obdir
                if ($?doit)   rm -rf $obdir

                if ($status) then
                    echo "Can't delete the Oracle Secure Backup directory from $obdir."
abenderr:
                    echo "The error is described above.  If possible, correct the error and re-run this"
                    echo "program.  Else, please contact Oracle Support and we'll"
                    echo "be happy to assist you."
                    goto failed
                    endif


moveobd:

                echo " "
                echo -n "Moving the Oracle Secure Backup directory tree..."
                if (! -e /usr) mkdir /usr
                if (! -e /usr/local) mkdir /usr/local
                if (! -e /usr/local/oracle) mkdir /usr/local/oracle
                if (! -e /usr/local/oracle/backup) mkdir /usr/local/oracle/backup

                mv $stuff_to_move /usr/local/oracle/backup >&/dev/null
                if ($status) then
                    if ($?showit) echo "tar -cf - $stuff_to_move | (cd $obdir; tar -xf -)"
                    tar $stuff_to_move | (cd $obdir; tar -xf -)
                    if ($status) then
                        echo "Can't move or copy Oracle Secure Backup tree.  Please correct this problem"
                        echo "(the error message is above) and re-run this program."
                        goto failed
                        endif

                    endif

                set idir = "$obdir/install"
                set moved
                echo " done."

            else if ($answer == b) then
                echo " "
                echo -n "Merging the Oracle Secure Backup directory tree..."

                if ($?showit) echo "tar -cf - $stuff_to_move | (cd $obdir; tar -xf -)"
                tar -cf - $stuff_to_move | (cd $obdir; tar -xf -)
                if ($status) then
                    echo " "
                    echo "Can't merge the new Oracle Secure Backup tree into $obdir."
                    goto abenderr
                    endif

                set idir = "$obdir/install"
                set moved
                echo " done."

            else if ($answer == c) then
                set idir = "$obdir/install"
                set moved

            else if ($answer == d) then
                echo " "
                echo "When you're ready to proceed, re-run this program to continue the installation."
                goto done
                endif

        else
            goto moveobd        # just move; don't ask any more ?'s
            endif

    else
        set ob_home = "$node_rel_cwd"
        endif


    if (! $?mira) then
        echo " "
        echo -n "Verifying that installation parameters are correct..."
        endif

    set tmp = ${OB_TMP}"/obpar$$"
    set lowerchars = "abcdefghijklmnopqrstuvwxyz"
    set upperchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set lc_os_name = `echo $my_os_name | tr $upperchars $lowerchars`
    sed -e 's,^\('$lc_os_name'[ 	][ 	]*ob[ 	][ 	]*dir:[ 	][ 	]*\).*$,\1'$ob_home',' $obparameters >$tmp
    diff $obparameters $tmp >&/dev/null
    set st = $status
    if (! $?mira) echo " done."
    if ($st) then
        if (! $?mira) echo -n "Updating $obparameters..."
        mv $tmp $obparameters
        if (! $?mira) echo " done."
    else
        rm -f $tmp
        endif
    echo " "

    if ($?moved) then
        echo -n "Just a moment while I change to $obdir..."
        cd $obdir
        exec install/installob -quiet
        endif
    endif


# -- See if the proposed Oracle Secure Backup directory is remotely mounted via nfs.  If so,
#    stop the music.

$idir/isnfs.sh `pwd`
if ($status == 1) then
    echo "$sep" ; echo " "
    echo "WARNING: Your proposed Oracle Secure Backup directory lives on an NFS-mounted"
    echo "    filesystem.  We STRONGLY RECOMMEND AGAINST using this configuration"
    echo "    for administrative servers.  The reason for this is that Oracle Secure Backup"
    echo "    uses record locking for data stored in the administrative directory."
    echo "    We have found remote record locking to be sufficiently unreliable"
    echo "    in certain configurations to make this recommendation."
    echo ""
    echo -n "Would you like to abort the installation [yes]? "
    set ayenay_dft = yes
        source $idir/ayenay.sh
    set st = $status
        unset ayenay_dft

    if ($st) then
        echo "Oracle Secure Backup installation aborted."
        goto failed
        endif
    endif



#  Ask user how he'd like to proceed.

pickone:
##################################################################################
#
#  disable the batch mode option   Leaving the code here just in case someone
#  decides that they really want this functionality    --- joew 8/15/07

goto skip_batch

if ($?mira) then
    set install_method = a
else
    echo " "; echo "$sep"
    echo " "
    echo "You can choose to install Oracle Secure Backup in one of two ways:"
    echo "    (a) interactively, by answering questions asked by this program, or"
    echo "    (b) in batch mode, by preparing a network description file"
    echo " "
    echo "Use interactive mode to install Oracle Secure Backup on a small number"
    echo "of hosts.  Use batch mode to install Oracle Secure Backup on any number"
    echo "of hosts."
    echo " "
    echo -n "Which installation method would you like to use (a or b) [a]? "
    
    while (1)
        set install_method = $<
        if ("$install_method" == "") then
            set install_method = a
            break
            endif
        if ("$install_method" == a || "$install_method" == b) break
        echo -n "Please choose a or b: "
        end
    
    switch ( $install_method )
        case a:
            set install_method = interactive
            breaksw
        case b:
            set install_method = batch
            breaksw
        endsw
    endif
    

#  If by using a network description file, invoke an editor with which
#  he or she can create one.

if ($install_method == batch) then
    echo " "; echo "$sep"

edit_ndf:

    echo " "
    while (1)
        echo -n "Enter the name of a network description file to create or use: "
        set ndf = $<

        if ("$ndf" == "") goto pickone

        if (! -e "$ndf") then

            echo -n "This is a new file; OK to proceed [yes]? "
            set ayenay_dft = yes
            source $idir/ayenay.sh
            set st = $status
            unset ayenay_dft
            if (! $st) continue

            echo -n "Creating a template network description file..."
            sed <$idir/obndf >$ndf -e '/^  /d'
            if ($status) then
                echo "Can't create ${ndf}."
                continue
                endif

            ed - $ndf <<done >&/dev/null
1
/h o s t/
.+2,\$d
w
q
done

            echo " done."
            echo " "
            echo "Follow the instructions in the commentary at the beginning of the template"
            echo "to fill in the network description file.  When you are ready to proceed,"
            echo "save the file and exit the editor."
            break
            endif

        if (-f "$ndf") then
            echo -n "This file exists; would you like to edit it [no]? "
            set ayenay_dft = no
            source $idir/ayenay.sh
            set st = $status
            unset ayenay_dft
            if (! $st) then
                echo " "; echo "$sep"
                goto ndfpick
                endif

            echo " "
            echo "Follow the instructions in the commentary at the beginning of the template"
            echo "to update the network description file.  When you are ready to proceed,"
            echo "save the file and exit the editor."
            break
            endif

        echo "The pathname $ndf exists but isn't a file."
        end


    if (! $?EDITOR) set EDITOR = vi
    echo " "
    echo "Press return to enter the default editor ($EDITOR).  Or, type the name of an"
    echo -n "alternate editor to use, then press return: "
    set answer = $<
    if ("$answer" != "") set EDITOR = "$answer"

reedit:
    $EDITOR $ndf

    if ($status) then
        echo " "; echo "$sep"; echo " "
        echo "The editor aborted with a non-zero exit code.  Would you like to choose"
        echo -n "another network description file (instead of $ndf) [no]? "
        set ayenay_dft = no
        source $idir/ayenay.sh
        set st = $status
        unset ayenay_dft
        if ($status) goto edit_ndf

    else
        echo " "; echo "$sep"
        endif

ndfpick:

    echo " "
    echo "The installation requires a temporary work area on each host with enough free"
    echo "disk space to stage the various components specified for that host in $ndf."
    echo "All staged files will be cleaned up afterwards, returning the disk space."
    echo ""
    echo "Please enter a list of one or more directory pathnames that I can test on each"
    echo "host to be installed. On each host I will use the first directory in the list"
    echo "found to have the necessary space. If none of the directories on a given host"
    echo "have the space required, that host will be skipped -- this will be noted with a"
    echo "message. Please separate multiple pathnames with a space (enter 'q' to quit)"

    echo -n "   [${OB_TGT_TMP_LIST}] : "
    set answer = $<

    if ("$answer" == "q" || "$answer" == "Q") exit (0)

    if ("$answer" != "") setenv OB_TGT_TMP_LIST " $answer "

    echo " "
    echo "I'm ready to begin the installation using ${ndf}.  You may --"
    echo "    (a) install Oracle Secure Backup on each host listed in ${ndf}, except"
    echo "        those already having the current version of Oracle Secure Backup installed;"
    echo "    (b) install Oracle Secure Backup on each host listed in ${ndf}, and"
    echo "        forcibly update those that already have Oracle Secure Backup installed;"
    echo "    (c) install Oracle Secure Backup on a subset of those hosts named in"
    echo "        ${ndf}; or"
    echo "    (d) abort the installation now."
    echo " "
    echo -n "Which would you like to do? "
    while (1)
        set answer = $<
        if ("$answer" == a || "$answer" == b || "$answer" == c || "$answer" == d) break
        echo -n "Please choose one of a - d: "
        end

    set force = ""
    set hostlist = ('-h')

    if ($answer == c) then
        echo " "
        echo "Please enter a list of host names on which to install Oracle Secure Backup."
        echo "Be sure to specify the host names as they appear in ${ndf}."
        echo "Enter a blank line following the last one."
        while (1)
            echo -n ": "
            set ans = `echo $<`
            if ($#ans < 1) break
            set hostlist = ($hostlist $ans)
            end

        if ($#hostlist < 2) then
            echo "You entered no host names\!"
            goto ndfpick
            endif

        @ i = $#hostlist - 1
        if ($i == 1) then
            echo -n "1 host"
        else
            echo -n "$i hosts"
            endif
        echo -n " entered; OK to proceed [yes]? "
        set ayenay_dft = yes
        source $idir/ayenay.sh
        set st = $status
        unset ayenay_dft
        if (! $st) goto ndfpick
        unset ans
        set answer = c
        endif


    if ($answer == a || $answer == b || $answer == c) then
        if ($answer == b || $answer == c) set force = "-f"
        if ($#hostlist < 2) set hostlist

        echo " "; echo "$sep"; echo " "
        echo "Beginning the installation now.  This will take a minute or two for each host,"
        echo "slightly longer for those whose kernel must be updated."
        echo " "

        if ($?showit) echo '    #' $idir/installnet $ndf $force $hostlist
        if ($?doit) then
            $idir/installnet $ndf $force $hostlist
            set st = $status
            endif

        echo " "; echo "$sep"; echo " "
        if ($st) then
            echo "Please review the output (above) to learn where the installation encountered"
            echo "problems.  Then, correct those problems and re-run this program.  If the"
            echo "cause of the problem is not obvious, please contact Oracle Support and we'll"
            echo "be happy to assist you."
            echo " "
            echo -n "Would you like to edit $ndf now and retry the installation [yes]? "
            set ayenay_dft = yes
            source $idir/ayenay.sh
            set st = $status
            unset ayenay_dft
            if (! $st) then
                echo " "
                echo "Please re-run this program when you're ready."
                goto failed
                endif
            goto reedit
            endif

        echo "The software installation is complete.  For each media server, be sure to"
        echo "reboot the machine if its kernel was rebuilt."
        echo " "
        echo "Once you do this, Oracle Secure Backup will be ready for your use."
        goto done

    else
        echo " "
        echo "When you're ready to proceed, re-run this program to continue the installation."
        goto done
        endif

    endif       # batch mode installation

skip_batch:

#  Fall through for interactive mode installation.  If Oracle Secure Backup isn't installed yet on
#  this host, do that:

set intertype    = ()           # installation type
set interdriver  = ()           # 1 if driver installed
set interhost    = ()           # on these hosts
set interos      = ()           # running these os's
set interkerpath = ()           # with these kernel pathnames


if ($?mira) then
    unset ob_installed
    unset ob_admin_installed
    goto evalnotinst
    endif

echo " "; echo "$sep"; echo " "
unset ayenay_dft
unset force_ayenay_yes
if (! $?ob_installed) then
    if ($?ob_was_installed) then
        echo "Oracle Secure Backup must be re-installed on this machine due to the software"
        echo -n "update from distribution media.  "
        set install_verb = "re-install"
    else
        echo "Oracle Secure Backup is not yet installed on this machine."
        set install_verb = "install"
        endif

    if ($?OLD_DIALOG) then
        echo -n "Is it OK to $install_verb it now [yes]? "
    else
        set force_ayenay_yes
        endif
    set ayenay_dft = yes
    unset install_verb
else
    echo "Oracle Secure Backup is already installed on this machine ($my_mach_name)."
    echo -n "Would you like to re-install it preserving current configuration data[no]? "
    set ayenay_dft = no
    endif

unset did_local_install
unset no_local_install

if ($?force_ayenay_yes) then
    set st = 1
else
    source $idir/ayenay.sh
    set st = $status
    endif

unset ayenay_dft
unset osb_upgrade
if (! $st) then
    echo " "
    if (! $?ob_installed) then
        echo "When you're ready to proceed, re-run this program."
        goto done
    else
        set no_local_install
        chmod 755 $idir/../.bin.$my_mach_arch/hostinfo
        chmod 4755 $idir/../.bin.$my_mach_arch/obt
        chmod 4755 $idir/../.bin.$my_mach_arch/obtool
        chmod 4755 $idir/../.bin.$my_mach_arch/obtar
        endif

#  Here if our user answered the question with a 'yes'.  If we asked whether he or
#  she wanted to re-install, unset the 'ob_installed' flags to offer consistent info
#  to the latter parts of this code.

else if ($?ob_installed) then
    set osb_upgrade = 1
    unset ob_installed
    # no need to cleanup the hostid file here. If it exists, we leave it asis. 
    # We will assume that the users wanted to save the db dir from the previous
    # install. 
    endif

evalnotinst:

if (! $?no_local_install) then
    set guiislocal
    source $idir/webcheck.sh
    unset guiislocal


startinstall:

    set pscmd    = '/bin/ps'
    set psopt    = '-e'

    switch ($my_os_name)
        case ULTRIX:
        case SunOS:
            set psopt = '-ax'
            breaksw
        default:
            breaksw
        endsw

# Query the user to whether they want to install an admin server, media server
# or a client 

    echo " "
    echo "Choose from one of the following options. The option you choose defines"
    echo "the software components to be installed. "
    echo " "
    echo "Configuration of this host is required after installation completes."
    echo " "
    echo "You can install the software on this host in one of the following ways:"
    echo "    (a) administrative server, media server and client"
    echo " "
    echo "    (b) media server and client"
    echo " "
    echo "    (c) client"
    echo " "
    echo "If you are not sure which option to choose, please refer to the Oracle "
    echo -n "Secure Backup Installation Guide. (a,b or c) [a]? "
    while (1)
        set install_type = $<
        if ("$install_type" == "") then
            set install_type = a
            break
            endif
        if ("$install_type" == a || "$install_type" == b || "$install_type" == c) break
        echo -n "Please choose a, b or c: "
        end

    switch ( $install_type )
        case a:
            set ins_mode = "admin"
            breaksw
        case b:
            set ins_mode = "server"
            breaksw
        case b:
        default:
            set ins_mode = "client"
            breaksw
        endsw

    if ($?rb_installed) then
        echo " "
        echo "An installation of Reliaty Backup has been detected on this host."
        echo "If you have not already backed up your Reliaty Backup installation,"
        echo "Oracle recommends that you do so now. As a part of the migration the Oracle"
        echo "Secure Backup installer will disable any startup scripts used by Reliaty Backup."
        echo "This is required to prevent the contention for port 400 by the Reliaty Backup"
        echo "and Oracle Secure Backup service daemons."
        echo -n "Do you wish to proceed? [yes]"
        set ayenay_dft = yes
        source $idir/ayenay.sh
        set st = $status
        unset ayenay_dft
        if (! $st) then
            echo "Terminating the installation of Oracle Secure Backup."
            exit(1)
        else 
            if (("$ins_mode" == "admin") && ($?rb_admin_installed)) then
                echo " "
                echo "Would you like to migrate the admin directory from Reliaty Backup"
                echo "to Oracle Secure Backup? [yes]"
                set ayenay_dft = yes
                source $idir/ayenay.sh
                set st = $status
                unset ayenay_dft
                if ($st) then
# Make sure that Reliaty Backup daemons are not running
                    set daemons = (rbserviced rbhttpd rbtar rbrobotd rbndmpd rbixd rbscheduled rbnotify rbexec rbtool )
                    set num_daemons = 0
                    foreach daemon ($daemons)
                        set pids = (`$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $1 }'` )
                        foreach pid ($pids)
                            echo "Reliaty Backup daemon $daemon (process id = $pid) is running."
                            @ num_daemons += 1
                            end
                        end

                    if ($num_daemons > 0) then
                        echo "Please terminate all the Reliaty Backup daemons and:"
                        echo "1. log in as (or 'su' to) root"
                        echo "2. cd to $cwd"
                        echo "3. run install/installob"
                        exit(1)
                        endif

# Perform the data migration from RB to OSB
                    source $idir/osbcvt
                    endif
# Perform cleanup of RB startup scripts
                set uninstallrb = 1
                source $idir/updaterc.sh
                endif 
            endif 
        endif 
    
    if (! $?mira) echo " "
    echo "Beginning the installation.  This will take just a minute and will produce"
    echo "several lines of informational output."

    if ($?showit) echo '    #' $idir/installhere $ins_mode -f
    if ($?doit)   then
        if ($?osb_upgrade) then
            $idir/installhere $ins_mode -f -n
        else
            $idir/installhere $ins_mode -f
            endif
        set st = $status
        if ($st) then
            set failcheckret = sifcr
            goto failcheck

sifcr:
            echo " "; echo "$sep"
            goto startinstall
            endif
        set did_local_install
        endif

else
    set ins_mode = `cat $idir/.intertype`
    set interdriver = `cat $idir/.interdriver`
    if ($ins_mode != client) then
        echo "Would you like to configure (or re-configure) any Oracle Secure Backup"
        echo -n "devices that are attached to $my_mach_name [no]? "
        set ayenay_dft = no
        source $idir/ayenay.sh
        set st = $status
        unset ayenay_dft
        endif
    endif


set intertype   = $ins_mode
set interdriver = ($interdriver 0)
set interhost   = ($interhost   $my_mach_name)
set interos     = ($interos     $my_os_name)
set mode        = $ins_mode

if ((! $?ob_installed) || $st) then
    if ($?my_kerpath) then
        set interkerpath = ($interkerpath $my_kerpath)
    else
        set interkerpath = ($interkerpath "none")
        endif

inter0adr:
    set mode      = $ins_mode
    @ n = 0
    @ mh_n = 0
    if ($my_mach_arch == linux32 || $my_mach_arch == linux86_64 || $my_mach_arch == linuxia64) then
        if ($mode != client && $mode != gclient) then
            echo " "
	    echo "****************************** N O T E ******************************"
	    echo "On Linux systems Oracle recommends that you answer no to the next two"
	    echo "questions. The preferred mode of operation on Linux systems is to use"
	    echo "the /dev/sg devices for attach points as described in the 'ReadMe'"
	    echo "and in the 'Installation and Configuration Guide'."
	    echo " "
	    endif
        endif


    if ($mode != client && $mode != gclient) then
        set mach_name = $my_mach_name
        set mach_arch = $my_mach_arch
        set base_arch = $my_base_arch
        set os_ver    = "$my_os_ver"
        set askdevret = inter1adr
        set devtype   = l
        unset mh_n mh_lun mh_scsi_target md_scsi_adapter mh_scsi_bus mh_scsi_lun
        goto askdevsub
        endif


inter1adr:
    if ($mode != client && $mode != gclient) then
        set mh_n = $n
        set mh_lun = ($lun)
        set mh_scsi_adapter = ($scsi_adapter)
        set mh_scsi_target = ($scsi_target)
        set mh_scsi_lun = ($scsi_lun)
        set mh_scsi_bus = ($scsi_bus)
        set devtype   = d
        set askdevret = inter2adr
        goto askdevsub
        endif


inter2adr:
    @ total_n = $n + $mh_n
    if ($mh_n > 0) then
        set lun = ($lun $mh_lun)
        set scsi_adapter = ($scsi_adapter $mh_scsi_adapter)
        set scsi_target = ($scsi_target $mh_scsi_target)
        set scsi_lun    = ($scsi_lun $mh_scsi_lun)
        set scsi_bus    = ($scsi_bus $mh_scsi_bus)
        endif

    if ($total_n > 0) then
        echo " "; echo "$sep"; echo " "
        echo "Beginning device driver configuration and device special file creation."
        echo " "

        if ($?hp800 || $?any_solaris) goto optionbmd
optionbid:
        if ($?showit) echo '    #' $idir/installdriver
        if ($?doit)   $idir/installdriver
        set st = $status

        if ($st != 0 && $st != 2) then
            set failcheckret = inter0adr
            goto failcheck
        else
            set interdriver[$#interdriver] = 1
            endif

        if ($?hp800) goto optionbend
optionbmd:
        @ i = 1
        while ($i <= $total_n)
            set cmd = "$idir/makedev -u $lun[$i] -f -d -t $scsi_target[$i] -l $scsi_lun[$i] -b $scsi_bus[$i]"
            if ($?linux) then
                set cmd = "$cmd -a $scsi_adapter[$i]"
                endif

            if ($i > $n) set cmd = "$cmd -li"

            if ($?showit) echo '    #' $cmd
            if ($?doit)   $cmd

            if ($status) then
                echo "Could not make a character special file for logical device $i."
                echo "(The error message is found above.)  If the problem is obvious,"
                echo "please correct it and retry the installation on $my_mach_name."
                echo " "
                echo "Continuing..."
                echo " "
                endif

            @ i = $i + 1
            end
        if ($?hp800) goto optionbid
optionbend:
        echo " "; echo "$sep"; echo " ";
        echo "NOTE: You must configure the new devices via the Web interface or via"
        echo "      the command line using the obtool 'mkdev' command."
        endif


#  If we didn't do a complete install on this machine, at least update the
#  symbolic links it uses.

    if (! $?no_local_install && ! $?did_local_install) then

        set guiislocal
        source $idir/webcheck.sh
        unset guiislocal


        if ($install_gui == TRUE) then
            set ins_mode = "gadmin"
        else
            set ins_mode = "admin"
            endif

        if ($?cwd) then
            set local_cwd = "$cwd"
        else
            set local_cwd = "`pwd`"
            endif

        $idir/makelinks.sh $ins_mode $local_cwd -abbrev 
        unset local_cwd
        endif

    set mach_name = "$my_mach_name"
    set kernelmoveret = inter1kmr
    goto kernelmovesub


inter1kmr:

    endif

#write install mode to a file to be used for re-install 
echo $intertype > $idir/.intertype
#write interdriver value to a file
echo $interdriver > $idir/.interdriver

#########################################################
#
#  skip all the remote install for now.  leaving the code
#  here just in case someone decides they need this 
#  functionality back  --- joew 8/15/07
#

    goto reminstexit

#  Take care of interactively installing remote hosts:


    if ($?mira) goto reminstexit

reminstloop:

    echo "$sep"; echo " "
    echo -n "Would you like to install Oracle Secure Backup on any other machine [yes]? "
    set ayenay_dft = yes
    source $idir/ayenay.sh
    set st = $status
    unset ayenay_dft

    if (! $st) goto reminstexit

    while (1)
        echo " "
        echo "NOTE: You must be able to run rsh as root to install Oracle Secure Backup on a remote machine."
        echo " "
        echo "Enter the name of a host onto which you'd like to install Oracle Secure Backup"
        echo -n ": "
        set host = $<
        if ("$host" == "") goto reminstloop

        echo -n "Just a moment while I learn about $host..."
        if ($OBTRACE) echo ""

        unset error
        source $idir/tgtmachinfo.sh
		echo "done."
        if ($?error) then
            echo "ERROR: Trouble talking with ${host}:"
            echo "    $error"
            goto reminstloop
            endif

        unset reboot_if_drives
        if ($?ob_kernel_path) set reboot_if_drives

        if ("$my_f_mach_name" == "$target_f_mach_name") then
            echo " "
            echo "You selected this machine, $my_mach_name, on which Oracle Secure Backup"
            echo "is already installed.  Please choose again."
            continue
            endif

        if ("$host" != "$target_mach_name" && "$host" != "$target_f_mach_name") then
            echo " "
            echo "Note: $host's formal name is $target_mach_name; do you still want to"
            echo -n "install on this host [yes]? "
            set ayenay_dft = yes
            source $idir/ayenay.sh
            set st = $status
            unset ayenay_dft
            if (! $st) continue
            endif

        if (! -d .etc.$target_mach_arch) then
            echo " "
            echo "No Oracle Secure Backup software is available for machine architecture $target_mach_arch."
            goto reminstabort
            endif


        unset canbeserver
        if (-d .drv.$target_mach_arch)        set canbeserver

        set install_host_as = c

        if (! $?canbeserver) then
            set mode = client
            set selection_level = none
        else
            set selection_level = full
            endif

        if ($selection_level != none) then
            set possible_answers = (c)
            echo " "
            echo "You may install $host as --"
            if ($selection_level == full) then
                set possible_answers = (a b $possible_answers)
                echo "    (a) administrative server"
                echo "        (the host will also be able to act as a media server or client)"
                echo "    (b) media server"
                echo "        (the host will also be able to act as a client)"
                endif
            echo "    (c) client"
            echo " "

            echo -n "Which would you like (one of $possible_answers; q to quit) [c]? "

            while (1)
                set install_host_as = $<

                if (   "$install_host_as" == "" \
                    || "$install_host_as" == q  \
	               ) break

                echo "$possible_answers" | grep $install_host_as >&/dev/null
                if ($status == 0) break

                echo -n "Please choose one of $possible_answers; q to quit [c]: "
                end

            endif

        unset possible_answers selection_level


        # if we were asked to stop working on this host, do so

        if ($install_host_as == q) continue


        # always install the GUI for administrative servers; don't give the user
        # the opportunity to choose

        setenv install_gui FALSE


        if ($install_host_as == a) then
            if ($install_gui == TRUE) then
                set mode = gadmin
            else
                set mode = admin
                endif

        else if ($install_host_as == b) then
            if ($install_gui == TRUE) then
                set mode = gserver
            else
                set mode = server
                endif

        else
            if ($install_gui == TRUE) then
                set mode = gclient
            else
                set mode = client
                endif
            endif


		# find what the story is wrt free space on the target machine...

		echo ""
        echo -n "Looking for an acceptable temporary work area on $target_mach_name..."
        if ($OBTRACE) echo ""
		set tmproom_query_user
		source $idir/tgttmproom.sh
                set st = $status
                echo ""
		if ( $st != 0 ) then
                    echo "skipping installation on $target_mach_name..."
                    continue
                else
		    echo "Using $OB_TGT_TMP for temporary work area on $target_mach_name"
                    endif

        # make sure target file system is large enough...
        echo ""
        echo -n "Making sure target file system has enough space..."
        set target_dir_info = `grep -i <$obparameters "^[ 	]*${target_os_name}[ 	][ 	]*ob[ 	][ 	]*dir:[ 	]"`
        if ($#target_dir_info < 4 && "$target_os_name" == "ULTRIX") then
            set target_dir_info = `grep -i <$obparameters "^[ 	]*decult[ 	][ 	]*ob[ 	][ 	]*dir:[ 	]"`
            endif
        if ($#target_dir_info < 4) then
            echo ""
            echo "    ERROR: no entry in $obparameters for operating system ${target_os_name}"
            set st = 1
            goto reminstabort
            endif
        if ($OBTRACE) echo ""
        set dir_name = $target_dir_info[4]
	source $idir/tgtobroom.sh
        set st = $status
        echo ""
	if ($st != 0) then
	    echo "skipping installation on $target_mach_name..."
	    goto reminstabort
            endif
        break
        end

    @ n = 0
    @ mh_n = 0

    if ($target_mach_arch == linux32 || $target_mach_arch == linux86_64 || $target_mach_arch == linuxia64) then
        if ($mode != client && $mode != gclient) then
            echo " "
	    echo "****************************** N O T E ******************************"
	    echo "On Linux systems Oracle recommends that you answer no to the next two"
	    echo "questions. The preferred mode of operation on Linux systems is to use"
	    echo "the /dev/sg devices for attach points as described in the 'ReadMe'"
	    echo "and in the 'Installation and Configuration Guide'."
	    echo " "
	    endif
        endif

    if ($mode != client && $mode != gclient) then
        set mach_name = "$host"
        set mach_arch = "$target_mach_arch"
        set base_arch = "$target_base_arch"
        set os_ver    = "$target_os_ver"
        set devtype   = l
        set askdevret = inter1radr
        unset mh_n mh_lun mh_scsi_target mh_scsi_lun mh_scsi_bus
        goto askdevsub
        endif


inter1radr:
    if ($mode != client && $mode != gclient) then
        set mh_n = $n
        set mh_lun = ($lun)
        set mh_scsi_target = ($scsi_target)
        set mh_scsi_lun = ($scsi_lun)
        set mh_scsi_bus = ($scsi_bus)
        set devtype   = d
        set askdevret = inter2radr
        goto askdevsub
        endif


inter2radr:
    @ total_n = $n + $mh_n
    if ($mh_n > 0) then
        set lun = ($lun $mh_lun)
        set scsi_target = ($scsi_target $mh_scsi_target)
        set scsi_lun = ($scsi_lun $mh_scsi_lun)
        set scsi_bus    = ($scsi_bus $mh_scsi_bus)
        endif

    if ($total_n == 0) then
        set devinfo = "no devices"
    else if ($total_n == 1) then
        set devinfo = "1 device"
    else
        set devinfo = "$total_n devices"
        endif


reminstvfy:

    echo " "; echo "$sep"; echo " "
    if ($mode == admin || $mode == gadmin) then
        echo "I'm ready to install Oracle Secure Backup on $host as an administrative server."
        echo "It will support $devinfo through Oracle Secure Backup's high performance"
        echo "device driver."

    else if ($mode == server || $mode == gserver) then
        echo "I'm ready to install Oracle Secure Backup on $host as a media server."
        if ($n == 0) then
            echo "Although this machine is a media server, you've configured no devices"
            echo "for use through Oracle Secure Backup's high performance device driver."
        else
            echo "It will support $devinfo through Oracle Secure Backup's high performance"
            echo "device driver."
            endif

    else
        echo "I'm ready to install Oracle Secure Backup on $host as a client."
        endif


    echo "The work area on $host to be used for temporary install files is ${OB_TGT_TMP}."

    echo " "
    echo -n "OK to proceed [yes]? "
    set ayenay_dft = yes
    source $idir/ayenay.sh
    set st = $status
    unset ayenay_dft

    if (! $st) then

reminstabort:

        echo " "
        echo "Installation of Oracle Secure Backup on $host is aborted."
        goto reminstloop
        endif


#  Build a drive specification that's acceptable following the -D flag:

    if ($mode == admin || $mode == gadmin) set last_admin = $host
    set drives = ""
    @ i = 1
    while ($i <= $total_n)
        if ("$drives" != "") set drives = "$drives/"
        set drives = "${drives}${lun[$i]}"
        set drives = "${drives}:t=${scsi_target[$i]}:l=${scsi_lun[$i]}:b=${scsi_bus[$i]}"
        if ($i > $n) set drives = "${drives}:d=li"
        @ i = $i + 1
        end

    if ("$drives" != "") set drives = (-D "$drives")

    if ($?showit) echo '    #' $idir/installhost $mode $host -f -a $last_admin $drives
    if ($?doit)   $idir/installhost $mode $host -f -a $last_admin $drives

    set st = $status
    if ($st == 2) @ st = 0
    if ($st) then
        echo " "
        echo "The installation on $host failed; an error message appears above."
        echo "If the cause of the error is obvious, please correct it and retry the"
        echo "installation on $host.  Else, contact Oracle Support and we'll be happy"
        echo "to assist you."

    else
        set intertype    = ($intertype    $mode)
        set interdriver  = ($interdriver  0)
        set interhost    = ($interhost    $host)
        set interos      = ($interos      $target_os_name)

        if ($?kernel_path) then
            set interkerpath = ($interkerpath $kernel_path)
        else
            set interkerpath = ($interkerpath "none")
            endif

        if ($?reboot_if_drives && "$drives" != "") then
            set reboot_list = ($reboot_list $host)
            set os_move_list = ($os_move_list $host)
            endif
        if ("$drives" != "") set interdriver[$#interdriver] = 1
        endif


    goto reminstloop    # this used to be a while loop, but the 'goto's' used to
                        # call subprograms aborted the loop, confusing the c-shell
                        # when we 'went to' the return statement.


reminstexit:

unset any_servers
echo "Installation summary:"
if ($#intertype == 0) then
    echo "    Oracle Secure Backup was not installed on any machines during this session."
    goto done
else
    echo " "
    echo "    Installation  Host                OS          Driver     OS Move    Reboot"
    echo "        Mode      Name                Name      Installed?  Required?  Required?"
    echo " "
    @ i = 1
    while ($i <= $#intertype)
        set list = ($intertype[$i] $interhost[$i] $interos[$i])
        if ($interdriver[$i]) then
            set any_servers
            set list = ($list yes no no)
            @ k = $#list - 1
            @ j = 1
            while ($j <= $#os_move_list)
                if ("$interhost[$i]" == "$os_move_list[$j]") then
                    set list[$k] = yes
                    break
                    endif
                @ j = $j + 1
                end
            @ j = 1
            while ($j <= $#reboot_list)
                if ("$interhost[$i]" == "$reboot_list[$j]") then
                    set list[$#list] = yes
                    break
                    endif
                @ j = $j + 1
                end
        else
            set list = ($list no no no)
            endif

        echo $list | awk '{ printf "    %-14s%-20s%-10s%-12s%-11s%-6s\n", $1, $2, $3, $4, $5, $6 } '

        @ i = $i + 1
        end
    echo " "
    unset list i j
    endif

if (! $?any_servers) then
    if ($?mira) echo "$sep"
    echo -n "Oracle Secure Backup is now ready for your use.  "
    if (! $?mira) echo ""

else
    echo "$sep"
    echo "Oracle Secure Backup will be ready for your use after you do the following:"
    @ i = 1
    while ($i <= $#intertype)
        if ($intertype[$i] != client) then
            echo ""
            echo "    On ${interhost[$i]}:"

            @ j = 1
            while ($j <= $#reboot_list)
                if ("$interhost[$i]" == "$reboot_list[$j]") break
                @ j = $j + 1
                end

            @ k = 1
            while ($k <= $#os_move_list)
                if ("$interhost[$i]" == "$os_move_list[$k]") break
                @ k = $k + 1
                end

            unset doblank
            if ($k <= $#os_move_list) then
                echo "            # mv $interkerpath[$i] $interkerpath[$i].preob"
                echo "            # mv $interkerpath[$i].ob $interkerpath[$i]"
                set doblank
                endif

            if ($j <= $#reboot_list) then
                if ($?doblank) echo ""
                echo "        Reboot $interhost[$i]."
                set doblank
                endif

            echo "        No further action is needed; Oracle Secure Backup is ready for your use on"
            echo "        $interhost[$i]."
            endif

        @ i = $i + 1
        end
    echo ""
    endif


#  More info for Mirapoint eval:
#
if ($?mira) then
    echo "To continue:"
    echo "  . point your web browser at https://$my_mach_name"
    echo '  . log in using the user name "admin" and no password'
    echo ""
    echo "To make your Mirapoint Message Server accessible, you must also --"
    echo "  . set the NDMP password:"
    echo "        do so using the Web tool's Configure/Hosts page (start by selecting the"
    echo '        Message Server from the Hosts list box, then clicking "Edit")'
    echo "  . configure Message Server-attached devices:"
    echo "        if a tape drive or library is connected directly to your Message Server,"
    echo "        discover devices using the Web tool's Configure/Devices page"
    echo ""
    echo "On-line documentation is available; see --"
    echo "  . Oracle Secure Backup User's Guide                   $cwd/doc/obadm.pdf"
    echo "  . Oracle Secure Backup Command Line Interface Guide   $cwd/doc/obref.pdf"
    echo "  . UNIX-format manual pages                            $cwd/man"
    echo "  . Late-breaking news                                  $cwd/README"
    echo ""
    echo "Oracle Technical Support is available to provide additional assistance."
    endif

echo ""

done:
set st = 0
done2:
if ($OBTRACE) $idir/trexit installob $st
exit ($st)

failed:
set st = 1
goto done2
