#!/bin/csh -f
#
# Copyright (c) 1992, 2012, Oracle and/or its affiliates. All rights reserved. 
#
#   NAME
#     makedev
#
#   DESCRIPTION
#     Make device special files for an Oracle Secure Backup device
#
#   MODIFIED   (MM/DD/YY) 
#   jwadleig   01/30/12 - Bug 13599438: remove check for /lib/ld-linux.so.2
#   asathyam   10/08/09 - Merge changes done in 10.3.0.1 AIX series, after
#                         10.3.0.1 of Linux was frozen.
#                         Bug 8475329 provide support for AIX 6.1 and greater
#   jwadleig   11/11/08 - merge from 10.2 -- expand AIX support for FC 
#   jwadleig   09/29/06 - fix support for hp64
#   rvullika   05/27/05 - Add support for hpux-64 and aix64
#   jrward     06/15/05 - remove last user-visible mention of autochangers
#   tdziedzi   05/18/05 - Product name change 
#   rvullika   05/09/05 - fix bug 4337770
#   gstabler   04/11/05 - bug 4293915: allow solaris LUNs up to 7.
#   gstabler   11/16/04 - widened linux host to 4 bits.
#   rvullika   10/18/04 - Cleanup unsupported platforms
#   rvullika   10/12/04 - replace linux86-lfs with linux32
#   rvullika   10/06/04 - solaris 2.7/5.7 fixes
#   rvullika   09/10/04 - fix solaris64 support
#   rvullika   07/06/04 - fixed comment for previous transaction 
#   rvullika   06/16/04 - add solaris64 support
#   tdziedzi   05/18/04 - Executables name change 
#   tdziedzi   03/05/04 - Update vendor/product name, copyright info 
#
# ******************************************************************************
#  Old changes (pre ade migration):
#     02/12/03 gms  allow luns up to 7 on linux; fixed error handling in bus while.
#     06/15/02 jrw  update copyright/IP notice.
#     12/17/01 gms  User's Guide now Installation Guide.
#     12/03/01 gms  v3 mods.
#     08/03/01 pfg  remove remote device configuration.
#                   remove calls to setuplm.sh.
#     06/27/01 jrw  support linux86-lfs.
#     08/22/00 gms  support only 10.20 and above for hp-ux.
#     06/18/00 jrw  remove hp68.
#     05/01/00 gms  removed dte # limitation.
#     03/31/00 gms  fixed adapter # handing for linux.
#     02/13/00 jrw  support Alpha Linux.
#     11/20/99 jrw  volunteer a list of Solaris SCSI bus names.
#     11/10/99 gms  allow target ids up to 15 where allowable.
#     10/28/99 gms  prompt for dte # for drive in remote handler.
#     09/24/99 gms  fixed typo.
#     09/13/99 gms  updated unit and mh unit prompts.
#     08/21/99 jrw  remove sgi4.
#     08/15/99 jrw  support solx86.
#     08/06/99 gms  support remote drives.
#     07/20/99 gms  set error rate only if user so says (and only for drives!).
#     07/19/99 gms  support linux (prompt for adapter #).
#     02/26/99 adp  support Linux with glibc.
#     01/29/99 jrw  support Linux.
#     01/03/99 jrw  update phraseology.
#     12/14/98 gms  accept iotype arg if hpvxfs also.
#     11/09/98 gms  support auspex version 1.9.
#     09/09/98 gms  allow -m for hppa (to override new major of 203).
#     09/08/98 gms  capture args, etc. in trace file.
#     07/31/98 gms  fix NCR 3.0.2 problem when "Pentium" does not appear as
#                   last token of uname string.
#     07/05/98 jrw  slight variable name change to support HP-UX 10+ uniformly across
#                   all installation tools.
#     02/17/98 gms  accomodate hp-ux 11.x
#     02/05/98 gms  allow for "09" as major hp-ux version.
#     07/28/97 gms  use name-instance for rs6000 scsi bus.
#     04/16/97 gms  use hp8iotype (set by hp8buses.sh) to determine iotype.
#     04/07/97 gms  mods for hpvxfs.
#     03/20/97 gms  support 3.0 NCRs.
#     03/13/97 gms  merged qr2.2.1_branch to mainline.
#     02/21/97 gms  support -iotype arg (hp800 only).
#     02/14/97 gms  make sure we have SOMETHING for scsi bus.
#                   also, prevent setlmcmd.sh from removing "in autochanger".
#     08/27/96 jrw  permit SCSI bus numbers up to 127 for sgi.
#     06/21/96 gms  fixed scsi bus prompt for HP-UX.
#     04/19/96 jrw  support ncr86 pentiums.
#     01/26/96 gms  support hp800 at 10.x
#     01/02/96 gms  removed "-e" from grep on erate (-e doesn't exist on solaris).
#     12/15/95 gms  added error rate stuff.
#     11/21/95 gms  accept bus path (not just 0-3) for hppa bus.
#     11/03/95 gms  set mach_name, mach_arch for setdevdfts.sh.
#     11/02/95 jrw  updates for -UX 10.0.
#     10/23/95 gms  accept -y for all platforms; moved rs6000's -y to -z.
#     07/18/95 jrw  expand path to support AIX 4.1.
#     07/14/95 jrw  add sgi4.
#     04/12/95 jrw  add IRIX* support (IRIX64, for example).
#     03/21/95 gms  fixed -y recognition.
#     01/25/94 gms  define my_mach_arch for setdevdfts.sh
#     12/15/94 gms  handle HP800 bus addressing.
#     11/28/94 gms  added trace.
#     10/11/94 gms  allow units up to 31.
#     09/21/94 gms  no major for any flavor of hp800.
#     09/01/94 gms  added sgi.
#     07/27/94 gms  fixed ncr86 scsi bus handling.
#     07/19/94 gms  added hp800.
#     05/13/94 gms  merged ncr branch to mainline.
#     05/09/94 gms  added ncr86 handling.
#     03/02/94 gms  call initinstall.sh (inc. setqrtmp.sh).
#     02/28/94 jrw  support Auspex.
#     02/24/94 jrw  apply no-query option to all questions that might be asked when
#                   invoked by qrcf__config_device.  Correct SunOS4 specific error.
#     02/03/94 kcl  /tmp => ${QR_TMP}
#     01/19/94 gms  show protection for solaris add_drv cmd.
#     01/05/94 gms  for solaris, show devlinks cmd if -n
#     12/07/93 gms  added Solaris support. move platform-specific stuff to
#                   md_$arch.sh files.
#     11/12/93 gms  allow 4 scsi buses for rs6000. again.
#     11/11/93 jrw  don't query user if unit # was read from cmd line and is bad.
#     11/11/93 gms  allow 4 scsi buses for rs6000.
#     11/10/93 jrw  don't setup lm databases if -X on cmdline.  This is used when
#                   makedev is invoked by another program, such as a qrcf_ function.
#                   Also, change old -l (location in media handler) option to -L.
#     08/31/93 gms  need parens around '<<' in xunit calcs.
#     08/20/93 gms  emit domain lun warning iff lun != 0.
#     08/13/93 gms  added scsi lun support.
#     07/28/93 jrw  remove LM-specific database entries if user reconfigures a
#                   device to be outside of a media handler.
#     07/27/93 jrw  don't ask superfluous questions if autochanger flag spec'ed.
#                   Also, accept yes/y and no/n for autochanger questions and do
#                   the right things.  This fixes bugs 459 and 460.  Also, removed
#                   superfluous endif that was playing havoc w/ flow of control.
#     07/09/93 gms  rearranged bits for 4-bus sparc support.
#     07/02/93 gms  for rs6000, see if another device is already using our
#                   scsi target. remove such device if the user says to.
#     06/01/93 jrw  correct autochanger flag setup in database file for real;
#                   setuplm.sh does this now.  s/tools/idir/.
#     05/30/93 jrw  s/autochanger:/in autochanger:/
#     05/29/93 jrw  fix bug 420; make us not prompt for dte info if -d is
#                   present on command line.
#     05/27/93 gms  only call setdevdfts.sh for units 0-3.
#     04/28/93 gms  recognize hp-ux 9.x -- different device files required.
#     02/18/93 gms  fixed mkdev calls for rs6000 -- "-t wsh" for handlers.
#     02/11/93 jrw  merge qr.mh into main line.  Create wsh database files.
#                   accept -in and -dte command line options.  Prompt user
#                   for this info if not in default mode and data were not
#                   supplied on the command line.
#     01/05/93 gms  added /usr/bsd for sgi.
#     12/04/92 jrw  support media handlers with -mh option.
#     12/03/92 gms  fixed calc of xunit, nxunit for hp.
#     11/17/92 gms  fixed -a arg for rs6000.
#     10/23/92 gms  avoid 'expr substr' -- unsupported on sys5.
#     09/08/92 gms  fixed root check for sys5.
#     06/26/92 gms  generalized apollo "arch" -- works for either 68k or 88k;
#                   fixed chown for hp (chown/chgrp)
#     06/22/92 gms  bullet-proofed user-input checks; added domain support;
#                   make sure device files owned & protected properly.
#     06/11/92 gms  added 9000/400.
#     06/03/92 gms  set path.
#     05/29/92 jrw  correct if stmt used in hp-ux case.
#     05/07/92 jrw  don't mention tfile on the same line as testing $?trace
#                   also, make sure setting uname[5] will work.
#     04/28/92 jrw  fixed 'device file not replaced' error to remove
#                   -n following echo.
#     04/27/92 jrw  added -N option, for, Please, NO QUERIES!
#                   this makes the auto network install work much better.
#
#   Usage: [ see usage below ]


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 makedev $argv
    else if (-f install/trenter) then
        install/trenter makedev $argv
        endif
    endif

############################################################
#
#  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."
        set st = 1
        endif
    if ($st) goto done
    endif

    set path = (. install /usr/ucb /usr/sbin /usr/bin /sbin /bin /usr/etc /etc /usr/bsd)

    set dflt_unit        = 0
    set dflt_devtype     = d
    set dflt_mh          = 0
    set tmp              = ${OB_TMP}/ob$$
    set trcfile          = ${OB_TMP}/makedev$$
    set st               = 1
    set maxunit          = 31               # also defined in valdrives.sh
    set maxlun           = 1                # for most platforms
    @ nunits             = $maxunit + 1
    set maxtarg          = 6
    set scsibustext      = "SCSI bus number"
    set noglob
    set trtab            = (0 1 2 3 4 5 6 7 8 9 a b c d e f)
    unset iotype
    if (! $?indent) set indent = ""
    unset arch base linux
    onintr interrupted

    echo -n "makedev run on " >$trcfile
    date >>$trcfile
    echo "args: $argv" >>$trcfile

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

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

############################################################
#
#   Make sure we've got the correct machine type and os rev.
#   If it's a sun, be prepared for a missing uname...
#

    if ( -f /bin/uname ) then
        /bin/uname -a >$tmp
        if ( $status ) then
            echo "${indent}ERROR: uname failed -- cannot determine machine architecture"
            goto failed
            endif
        set uname = `cat $tmp`
    else
        strings /vmunix | grep SunOS >$tmp
        if ( $status ) then
            echo "${indent}ERROR: cannot determine machine architecture"
            goto failed
            endif
        set uname = `cat $tmp`
        while ($#uname < 5)     # we'll need this to avoid subscript error
            set uname = ($uname unknown)
            end
        set uname[5] = `arch -k`
        endif

    set os_name = $uname[1]


#  For NCR UNIX machines, the uname string has 6 tokens; it requires special
#  handling:

    if ($#uname >= 6) then
        if ($uname[6] =~ 386/486* || $uname[6] =~ i486* || $uname[6] =~ Pentium*) then
            set os_name = "NCR-UNIX"
            endif
        endif

    if ($uname[1] =~ IRIX*) then
        set os_name = IRIX
        endif

    if ( $#uname < 5 ) then
        unset echo
        echo "${indent}ERROR: uname did not furnish machine type"
        goto failed
        endif
    set mach_type = $uname[5]

#  Parse the uname string based on what OS we saw:

    unset arch hp8bus solaris rs6000 solaris_busses
    set maxbus = 1
    switch ( $os_name )

        #  Handle Sun machines:
        case SunOS :
            if ( { (echo $mach_type | grep -i '[as]u[sn][hp4]'  >/dev/null) } ) set arch = sparc
            set drv = .drv.sparc      # source dir for driver
            set maxbus = 3            # sparc supports 4 scsi buses
            if ( $uname[3] =~ 5*) then
                if ($uname[5] != i86pc) then
                    set arch = solaris
                    endif
                if (-x /usr/bin/isainfo || -x /bin/isainfo) then
                    set isainfo=`isainfo -vk`
                    if ($isainfo[1] =~ 64* && $uname[3] != 5.7) then
                        set arch = solaris64
                        endif
                    endif
                set maxtarg = 15
                set maxlun = 7
                set solaris
                set nomaj
                set solaris_busses = (`$idir/sol_bus.sh -q`)
                endif
            breaksw

        #  Handle HP machines:
        case ( HP-UX | hp-ux ) :
            unset hpux11_plus
            set os_ver = ( `echo $uname[3] | sed -e "s/^[~a-zA-Z.]*\([0-9]*\).\([0-9]*\)/\1 \2/"`)
            if ( $#os_ver < 1 ) set os_ver = (8)
            if ( $#os_ver < 2 ) set os_ver = ($os_ver 0)
            set scsibustext = "SCSI bus path"

            if ($os_ver[1] < 11) then
                echo "${indent}ERROR: HP-UX version 11.1 or later is required."
                goto failed
            else
                if ($os_ver[1] >= 11) then
                    set hpux11_plus
                    set nomaj
                    set maxbus  = 255       # hp 10.0 supports 256 bus instances
                    set maxtarg =  15       # and wide scsi
                    set maxlun  =   7       # and many luns
                    set scsibustext = "SCSI bus instance"
                    endif
                endif
            set os_mode
            if (-x /usr/bin/getconf) then
                set os_mode = `/usr/bin/getconf KERNEL_BITS`
                endif
            if ( $mach_type == ia64) then
                set arch = hp64ia
            else if ( ( $os_ver[1] >= 11) && ($os_ver[2] >= 1) ) then
                if ($os_mode == 64) then
                    set arch = hp64pa
                    endif
                endif

            set drv = .drv.$arch      # source dir for driver
            breaksw

        #  And Big Blue:
        case AIX :
        set os_mode
        set os_ver = $uname[4].$uname[3]
        set scsibustext = "SCSI bus name"
#       Determine if 32-bit or 64-bit, we only support 64-bit variant
        if ( -x /usr/bin/getconf ) then
            set os_mode = `/usr/bin/getconf KERNEL_BITMODE`
            endif
        if ( $os_mode == 64  && \
           ((( $uname[4] >= 5 ) && ( $uname[3] >= 2 )) || \
           (( $uname[4] >= 6 ) && ( $uname[3] >= 1 )))) then
            set arch = ibm64
            endif

            set drv = .drv.$arch      # source dir for driver
            set maxbus = 3            # aix supports 4 scsi buses
	    set maxtarg = 16777215    # aix FC target ids can be large 2^^24-1
	    set maxlun = 7    
            set nomaj
            breaksw

        #  linux:
        case Linux :
            @ n_uname = $#uname - 1
            set arch = linux32            
            set nomaj
            set maxtarg = 15
            set maxlun  = 7
            set mach_type = "$uname[$n_uname]"
            set linux
            breaksw

        endsw

    if ( ! $?arch ) then
        echo "${indent}ERROR: makedev not supported for $os_name running on $mach_type"
        goto failed
        endif

    if ( ! $?base) then
        set base = $arch
        endif

set mach_arch = $arch               # expected by setdevdfts.sh
set base_arch = $base
set mach_name = "`hostname`"        # in case setdevdfts.sh runs hp8buses.sh

echo "mach_arch: $mach_arch" >>$trcfile
echo "base_arch: $base_arch" >>$trcfile
echo "mach_name: $mach_name" >>$trcfile

############################################################
#
#   look for usage request...

    echo "$argv" >$tmp
    grep  "\-h" $tmp >&/dev/null
    if ( $status == 0 ) goto usage
    grep  "\?" $tmp >&/dev/null
    if ( $status == 0 ) then
usage:
        unset echo
        echo "Usage:   makedev [option ... ]"
        echo ""
        echo "makedev uses the information from the command line and/or from"
        echo "responses to prompts to create a device special file for an"
        echo "Oracle Secure Backup tape device or a SCSI-2 tape library."
        echo "makedev will prompt for any unspecified args. You can ask for help"
        echo "at any prompt by typing '?'."
        echo ""
        if ($?linux) echo "    -a <a>    host adapter number"
        echo -n "    -b <b>    $scsibustext "
        if ($?hp8bus) then
            echo "($hp8busesf)"
        else if ($?hp7bus) then
            echo "(201)"
        else
            echo "<b>, b=0-${maxbus}"
            endif
        echo "    -t <t>    SCSI target id <t>, t=0-6} (0-14 if wide scsi; default is 4)"
        if ($arch != domain) then
            echo "    -l <l>    SCSI logical unit number (lun) <l>, l=0-$maxlun (default is 0)"
            endif
        echo "    -li       Make a SCSI-2 tape library device (not a drive)"
        echo "    -dr       Make a drive device (default)"
        echo "    -d        Use default values for unspecified options (for all but unit)"
        if (! $?nomaj) then
            echo "    -m <m>    Major device number"
            endif
        if ($arch == hp800) then
            echo "    -iotype 'sio' or 'wsio'  Overrides default iotype"
            endif
        echo "    -n        Do not actually create file -- just show cmd"
        echo "    -f        Force -- automatically replace existing device file"
        echo "    -N        Avoid (with no query) replacing existing device file"
        echo "    -x        Turns on echo"
        echo "    -y        Trace progress through install scripts"
        if ($arch == rs6000) then
            echo "    -z        Trace configuration methods (RS/6000 only)"
            endif
        echo "    -h, ?     Print usage ('?' is also available on individual prompts)"
        echo ""
        goto done
        endif

############################################################
#
#   see where we are...

    set root = .                    # default for trace file
    if ( -f ../.wrapper ) set root = ..

############################################################
#
#   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."
            set st = 1
            goto done
            endif
        endif

############################################################
#
#   before continuing, make sure we have the platform-specific
#   make file for this guy...

    if (($base == solx86) || ($base == solaris64)) then
        set mdfile = $idir/md_solaris.sh
    else if ($base == linux32) then
        set mdfile = $idir/md_linux86-glibc.sh
    else if (($base == hp64ia) || ($base == hp64pa)) then
        set mdfile = $idir/md_hppa.sh
    else if ($base == ibm64) then
        set mdfile = $idir/md_rs6000.sh
    else
        set mdfile = $idir/md_${base}.sh
        endif
    if (! -f $mdfile) then
        echo "${indent}ERROR: file $mdfile does not exist."
        echo "${indent}       makedev cannot continue for this platform."
        goto failed
        endif

############################################################
#
#   parse args

    unset unit
    unset adapter
    unset bus
    unset target
    unset lun
    unset major
    unset noexec
    unset use_dflts
    unset force
    unset trace
    unset devtype

    set i = 1
    while ($i <= $#argv)
        switch ( $argv[$i] )

            case -a :
                if (! $?linux) goto dflt
                @ i = $i + 1
                if ( $i <= $#argv ) then
                    if ( "$argv[$i]" !~ -* ) then
                        set adapter = $argv[$i]
                        breaksw
                        endif
                    endif
                echo "${indent}ERROR: -a option requires a host adapter number"
                goto failed

            case -li :
                set devtype = m
                breaksw

            case -dr :
                set devtype = d
                breaksw

            case -u :
                @ i = $i + 1
                if ( $i <= $#argv ) then
                    if ( "$argv[$i]" !~ -* ) then
                        set unit = $argv[$i]
                        set unit_from_cmdline
                        breaksw
                        endif
                    endif
                echo "${indent}ERROR: -u option requires a unit number 0-${maxunit}"
                goto failed

            case -t :
                @ i = $i + 1
                if ( $i <= $#argv ) then
                    if ( "$argv[$i]" !~ -* ) then
                        set target = $argv[$i]
                        breaksw
                        endif
                    endif
                echo "${indent}ERROR: -t option requires a target id 0-${maxtarg}"
                goto failed

            case -l :
                @ i = $i + 1
                if ( $i <= $#argv ) then
                    if ( "$argv[$i]" !~ -* ) then
                        set lun = $argv[$i]
                        breaksw
                        endif
                    endif
                echo "${indent}ERROR: -l option requires a target lun 0-$maxlun"
                goto failed

            case -X :
                set nolm
                breaksw

            case -b :
                @ i = $i + 1
                if ( $i <= $#argv ) then
                    if ( "$argv[$i]" !~ -* ) then
                        set bus = $argv[$i]
                        breaksw
                        endif
                    endif
                echo "${indent}ERROR: -b option requires a $scsibustext"
                goto failed

            case -d :
                set use_dflts
                breaksw

            case -f :
                set force
                breaksw

            case -m :
                @ i = $i + 1
                if ($?nomaj && $base_arch != hppa) then
                    echo "${indent}WARNING: major device number not required for this platform; ignored."
                    breaksw
                    endif
                if ( $i <= $#argv ) then
                    if ( "$argv[$i]" !~ -* ) then
                        set major = $argv[$i]
                        breaksw
                        endif
                    endif
                echo "${indent}ERROR: -m option requires a major device number"
                goto failed

            case -n :
                set noexec
                breaksw

            case -x :
                breaksw

            case -N :
                set noquery
                breaksw

            case -y :
                breaksw

            case -z :
                if ( $arch == rs6000 ) then
                    set trace
                    set tfile = ./makedev.trc
                    setenv WST_DEBUG $tfile
                    rm -f $tfile >&/dev/null
                    echo -n "Trace of makedev, " >$tfile
                    date >>$tfile
                    echo "" >>$tfile
                    echo "Command line was:  makedev $argv" >>$tfile
                    echo "" >>$tfile
                else
                    echo "${indent}WARNING: trace option not supported on this machine type -- ignored"
                    endif
                breaksw

            case -iotype :
                if ($arch != hp800 && $arch != hpvxfs) then
                    echo "${indent}ERROR: -iotype applies only to HP 9000/800 machines"
                    goto failed
                    endif
                @ i = $i + 1
                if ( $i > $#argv ) then
                    set iotype "junk"   
                else
                    set iotype = $argv[$i]
                    endif
                if ("$iotype" == "spt") set iotype = "sio"
                if ("$iotype" != "wsio" && "$iotype" != "sio") then
                    echo "${indent}ERROR: -iotype requires arg 'sio' or 'wsio'."
                    goto failed
                    endif
                breaksw
dflt :
            default :
                echo "${indent}ERROR: makedev: $argv[$i] unrecognized arg"
                echo "${indent}    type 'makedev -h' for usage info"
                goto failed

            endsw

        @ i = $i + 1
        end

############################################################
#
#   get values for unspecified args, validate those that were specified...

### unit number...
    while (1)
        if ( ! $?unit ) then
            if ($?noquery) then
                echo "${indent}ERROR: Need a logical unit number, but query suppressed."
                goto failed
                endif

            echo -n "Enter logical unit number 0-${maxunit} [$dflt_unit]: "
            set unit = $<
            if ( "$unit" == "?"  || "$unit" == "\?" ) then
                echo "   The Oracle Secure Backup device driver supports up to $nunits tape and"
                echo "   SCSI-2 tape library units, each numbered 0 to ${maxunit}. The unit number of a"
                echo "   given drive or tape library is typically appended to the name of"
                echo "   the special file for the device, as in 'obt0' for drive unit 0."
                unset unit
                continue
                endif
            endif

        if ( "$unit" == "" ) set unit = $dflt_unit
        echo $unit | grep : >&/dev/null
        expr $unit + 1 >&/dev/null
        if ( $status || ($unit > 31) ) then
            echo "${indent}ERROR: unit number must be 0-${maxunit}"
            unset unit
            if ($?unit_from_cmdline) goto failed
            continue
            endif
        echo "unit: $unit" >>$trcfile
        break
        end

############################################################
#
#   before we can setup the default bus address, etc., we must know whether we're
#   dealing with a media handler or a drive; learn that now, either by setting
#   the default device type, or by querying the user

    if ( $?use_dflts ) then
        if (! $?devtype) set devtype = $dflt_devtype
        endif

    while (1)
        if ( ! $?devtype ) then

            if ($?noquery)${indent} then
                echo "${indent}ERROR: Need a device type, but query suppressed."
                goto failed
                endif

            echo    "Enter 'd' if this device is a tape drive or 'l' if a SCSI-2 addressable"
            echo -n "    tape library [$dflt_devtype]: "
            set devtype = $<
            if ( "$devtype" == "?" || "$devtype" == "\?" ) then
                echo "   The device type selects whether the device you are configuring is a"
                echo "   tape drive or a tape library."
                unset devtype
                continue
                endif
            if ( "$devtype" == "" ) set devtype = $dflt_devtype
            echo "devtype: $devtype"  >>$trcfile
            if ( "$devtype" != d && "$devtype" != l ) then
                echo "${indent}ERROR: device type must be 'd' or 'l'"
                unset devtype
                continue
                endif
            endif
        echo "devtype: $devtype" >>$trcfile
        break
        end

    if ($devtype == d) then
        set devtype_text = "drive"
    else
        set devtype_text = "SCSI-2 tape library"
        endif

############################################################
#
#   we know enough now to setup the default bus and SCSI target id lists.
#   use the common 'setdevdfts.sh' program to do this.

    set dflt_target = ()
    set dflt_bus    = ()
    @ logical_unit = 0

    while ($logical_unit < 4)
        source $idir/setdevdfts.sh
        if ($devtype == l) then
            set dflt_target = ($dflt_target $dft_mh_scsi_target)
            set dflt_bus =    ($dflt_bus $dft_mh_scsi_bus)
        else
            set dflt_target = ($dflt_target $dft_scsi_target)
            set dflt_bus =    ($dflt_bus $dft_scsi_bus)
            endif
        @ logical_unit = $logical_unit + 1
        end

    unset logical_unit dft_scsi_bus dft_scsi_target dft_mh_scsi_bus dft_mh_scsi_target
    @ uix = $unit + 1


### see if we can use defaults for the rest...
    if ( $?use_dflts ) then
        if ($?linux && ! $?adapter) set adapter = 0
        if ( $unit < 4 ) then
            if ( ! $?target )      set target      = $dflt_target[$uix]
            if ( ! $?bus ) then
                if ($?hp8bus) then
                    if ($#hp8buses == 1) then
                        set bus = $hp8buses[1]
                        if (! $?iotype) set iotype = $hp8iotype[1]
                        endif
                else
                    set bus = $dflt_bus[$uix]
                    endif
                endif
        else
            if ( ! $?target ) echo "NOTE: no default SCSI target address is available"
            if ( ! $?bus )    echo "NOTE: no default $scsibustext is available"
            endif

        if ( ! $?lun ) set lun = 0
        endif


### Host adapter number...
    if ($?linux) then
        while (1)
            if ( ! $?adapter ) then
                if ($?noquery) then
                    echo "${indent}ERROR: Need a host adapter number, but query suppressed."
                    goto failed
                    endif
                echo -n "Enter host adapter number 0-15 [0]: "
                set adapter = $<
                if ( "$adapter" == "" ) set adapter = 0
                if ( "$adapter" == "?"  || "$adapter" == "\?" ) then
                    echo "   The SCSI host adapter number is the number (starting at 0) of the host"
                    echo "   adapter to which the device being defined is attached."
                    echo "   To determine this number, you may 'cat /proc/scsi/scsi'" 
                    echo "   to obtain a list of where your SCSI devices are attached."
                    unset adapter
                    continue
                    endif
                echo "$adapter" | grep '[^0-9]' >&/dev/null
                if ($status == 0) then
                    echo "${indent}ERROR: Adapter number must be an integer."
                    unset adapter
                    continue
                    endif
                 if ( $adapter < 0 || $adapter > 15 ) then
                    echo "${indent}ERROR: Adapter number must be 0-15."
                    unset adapter
                    continue
                    endif
                endif
            break
            end
        echo "adapter: $adapter" >>$trcfile
        endif


### SCSI bus number...
    set dbus = ""
    set showbus = ""

    if ($?solaris_busses) then
        if ($#solaris_busses > 0) then
            set dbus = "$solaris_busses[1]"
            set showbus = " [${solaris_busses[1]}]"
            endif
    else if ($unit < 4) then
        set dbus = $dflt_bus[$uix]
        set showbus = " [$dbus]"
        endif
    while (1)
        if ( ! $?bus ) then
            if ($?noquery) then
                echo "${indent}ERROR: Need a $scsibustext, but query suppressed."
                goto failed
                endif

            if ($?hp8bus) then
                if ($#hp8buses == 1) then
                    echo "NOTE: only one scsi bus configured at ${hp8busesf}; using it."
                    set bus = $hp8buses[1]
                    if (! $?iotype) set iotype = $hp8iotype[1]
                    break
                    endif
                if ($?hpux10_plus) then
                    echo -n "Enter $scsibustext (${hp8busesf}): "
                else
                    echo -n "Enter SCSI bus address (${hp8busesf}): "
                    endif
            else if ($?solaris && $?solaris_busses) then
                if ($#solaris_busses > 1) then
                    echo "The following SCSI busses are installed on ${mach_name}: $solaris_busses"
                    endif
                echo -n "Enter SCSI bus name${showbus}: "
            else if ($?ibm64 || $?solaris) then
                echo -n "Enter SCSI bus name-instance${showbus}: "
            else if ($os_name == HP-UX || $os_name == hp-ux || $os_name == AIX) then
                echo -n "Enter ${scsibustext}${showbus}: "
            else
                echo -n "Enter $scsibustext 0-${maxbus}${showbus}: "
                endif

            set bus = $<
            if ( "$bus" == "" ) set bus = $dbus
            echo "bus: $bus" >>$trcfile
            if ( "$bus" == "") then
                echo "   No default SCSI bus for this unit."
                unset bus
                continue
                endif
            if ( "$bus" == "?"  || "$bus" == "\?" ) then
                if ($?hp8bus) then
                    if ($?hpux11_plus) then
                        echo "   Ths SCSI bus address is the card instance number of the scsi bus"
                        echo "   as shown by /usr/sbin/ioscan. You must pick one of the instances"
                        echo "   displayed in the above list."
                    else
                        echo "   Ths SCSI bus address is the H/W path of the scsi bus as"
                        echo "   shown by /etc/ioscan. You must pick one of the paths"
                        echo "   displayed in the above list."
                        endif
                else if ($?solaris || $?ibm64) then
                    echo "   Ths SCSI bus address is name and instance number of the adapter"
                    echo "   for the bus to which $devtype_text unit $unit is connected."
                    echo "   For example, '$dbus' is typically the first SCSI bus."
                    if ($?solaris) then
                        echo "   /usr/sbin/prtconf can be used to obtain a complete"
                        echo "   listing of the system configuration."
                    else
                        echo "   lsdev -C can be used to obtain a complete"
                        echo "   listing of the system configuration."
                        endif
                else
                    echo "   The $scsibustext refers to the $scsibustext"
                    echo "   to which $devtype_text unit $unit is connected."
                    endif
                unset bus
                continue
                endif
            endif

        if ($?hp8bus) then
            unset busok
            set i = 1
            foreach xbus ($hp8buses)
                if ($bus == $xbus) then
                    set busok
                    if (! $?iotype) set iotype = $hp8iotype[$i]
                    break
                    endif
                @ i += 1
                end
            if (! $?busok) then
                echo -n "${indent}ERROR: "
                if ("$bus" != "") echo -n "SCSI bus $bus is not configured. "
                if ($#hp8buses == 1) then
                    echo ""
                else
                    echo "You must specify ${hp8busesf}."
                    endif
                unset bus xbus busok
                continue
                endif
            unset xbus busok
            endif

        echo "bus: $bus" >>$trcfile
        break
        end




### target id...
    if ($unit < 4) then
        set dtarg = $dflt_target[$uix]
        set showtarg = " [$dtarg]"
    else
        set dtarg = ""
        set showtarg = ""
        endif
    while (1)
        if ( ! $?target ) then

            if ($?noquery) then
                echo "${indent}ERROR: Need a SCSI target id, but query suppressed."
                goto failed
                endif

            echo -n "Enter SCSI target id 0-${maxtarg}${showtarg}: "
            set target = $<
            if ( "$target" == "?" || "$target" == "\?" ) then
                echo "   The target id is the SCSI bus address for $devtype_text unit $unit."
                echo "   Valid SCSI target ids range from 0 to ${maxtarg}. The id you enter must match"
                echo "   the id selected on $devtype_text unit $unit."
                unset target
                continue
                endif
            endif
        if ( "$target" == "" ) set target = $dtarg
        expr $target + 1 >&/dev/null
        if ( $status ) then
            echo "${indent}ERROR: Bad number entered"
            unset target
            continue
            endif
        if ( $target > $maxtarg ) then
            echo "${indent}ERROR: target id must be 0-${maxtarg}"
            unset target
            continue
            endif
        echo "target: $target" >>$trcfile
        break
        end

### lun...
    while (1)
        if ($?lun) then
            if ($arch == domain && $lun != 0) then
                echo "WARNING: multiple luns not supported on Domain;"
                echo "         lun will be forced to 0."
                set lun = 0
                endif
        else if ($arch == domain) then
            set lun = 0
        else

            if ($?noquery) then
                echo "${indent}ERROR: Need a SCSI logical unit number, but query suppressed."
                goto failed
                endif

            echo -n "Enter SCSI logical unit number (lun) 0-$maxlun [0]: "
            set lun = $<
            if ( "$lun" == "?" || "$lun" == "\?" ) then
                echo "   The lun is the SCSI logical unit number for this device."
                echo "   Supported SCSI luns are 0-${maxlun}."
                unset lun
                continue
                endif
            endif

        if ( "$lun" == "" ) set lun = 0
        echo $lun | grep '^[0-9]*$' >&/dev/null
        if ($status) unset lun
        if ($?lun) then
            if ($lun > $maxlun) unset lun
            endif

        if (! $?lun) then
            echo "${indent}ERROR: lun must be 0-$maxlun"
            continue
            endif
        echo "lun: $lun" >>$trcfile
        break
        end


### major device number...
    if ( $?nomaj ) goto igmaj
    while (1)
        if ( ! $?major ) then
            set mname = $root/$drv/major_device_number      # expected loc of major number
            if ( -f $mname ) then
                cat $mname >$tmp
                if ( $status ) then
                    echo "${indent}ERROR: couldn't read $mname"
                else
                    set major = `cat $tmp`
                    if ( `expr $major \> 0 \& $major \< 140` ) break
                    endif
            else
                echo "${indent}WARNING: the file $mname could not be found"
                if (! $?noquery) then
                    echo "${indent}   You will have to manually enter the major device number."
                    endif
                echo "${indent}   (It should be found in $drv/major_device_number in"
                echo "${indent}   your Oracle Secure Backup directory if you have run installdriver.)"
                endif

            if ($?noquery) then
                echo ""
                echo "${indent}   Use Oracle Secure Backup's installation tools to install the device driver"
                echo "${indent}   into your operating system's kernel; refer to the Oracle Secure Backup"
                echo "${indent}   Installation Guide for details."
                goto failed
                endif


            echo -n "Enter major device number: "
            set major = $<
            echo "major: $major" >>$trcfile
            if ( "$major" == "?"  || "$major" == "\?" ) then
                echo "   The major device number is one of the two numbers"
                echo "   used to identify the Oracle Secure Backup devices"
                echo "   to your operating system. The major device number"
                echo "   was printed out by 'installdriver' when you rebuilt"
                echo "   the kernel for your machine. That number should"
                echo "   be entered here."
                unset major
                continue
                endif
            endif
        if ( "$major" == "" ) then
            echo "${indent}ERROR: major device number must be entered"
            unset major
            continue
            endif
        echo $major >$tmp
        grep <$tmp '[^0-9]' >/dev/null
        if ($status == 0) then
            echo "${indent}ERROR: major device number must a decimal number"
            unset major
            continue
            endif
        break
        end
igmaj:

############################################################
#
#   generate device numbers and commands based on machine type...
#   (note: from here on, everything is pretty platform-dependent,
#   so continue in platform-specific file.)

    unset is_hp ndname ncmd
    source $mdfile
    set st = $status
    if ($st) goto failed

    if ($?cmd) then
        echo "cmd: $cmd" >>$trcfile
        endif
    if ($?ncmd) then
        echo "ncmd: $ncmd" >>$trcfile
        endif

done:
    rm -f $tmp
    if ($OBTRACE) $idir/trexit makedev $st
    exit ($st)

failed:
    set st = 1
    goto done

interrupted:
    set st = 9
    goto done

