#!/bin/csh -f
#
# Copyright (c) 1992, 2013, Oracle and/or its affiliates. All rights reserved. 
#
#   NAME
#     uninstallhere
#
#   DESCRIPTION
#     uninstall local host
#
#   MODIFIED   (MM/DD/YY) 
#   jcobau     04/30/13 - Bug 16744848 - "errsum: Command not found" is 
#                         displayed when uninstalling product.
#   jcobau     04/17/13 - Bug 14108975 - obconfig file is retained after uninstall
#                         and keep data.
#   jwadleig   03/15/12 - Bug 12775775 & 13829629 remove AIX specific files from lib
#   tdziedzi   01/18/12 - Add php.ini
#   jwadleig   07/28/11 - Fix crle for solarisx86_64 
#   tdziedzi   06/28/11 - Fix crle invocation to specify both default and
#                         trusted directories in a single command
#   tdziedzi   06/23/11 - Eliminate use of $ORIGIN and RPATH/RUNPATH
#   kdayal     06/16/10 - Add Solarisx86_64 and
#                         clean up code related to removing ob driver... for solaris
#   kdayal     06/02/10 - Bug 9358857 remove libapr-1.so.0 libaprutil-1.so.0
#   jwadleig   12/11/09 - Backport 8397441 for 10.3.0.2
#                         Bug-8397441 remove driver when uninstalling solaris64
#   jwadleig   10/29/09 - backport Bug 8594742 - only remove OSB components from
#                         backup dir.
#   asathyam   10/12/09 - Bug 8472913:- Allow for preservation of local config
#                         [DB] directory as per the user's request.
#   asathyam   10/09/09 - Merge changes done in HP 10.3.0.1 after 10.3.0.1 of
#                         Linux was frozen
#                         Remove "lib" entries from /usr/lib/hpux64 in HP.
#   jwadleig   10/02/09 - more work on bug 8539351 linux32 would not uninstall.
#   jwadleig   07/22/09 - Bug 8595351 -- setup link for libobk.so on linux64 systems 
#   jwadleig   12/29/08 - fix solaris shared library uninstall
#   jwadleig   12/08/08 - Bug-7612196 need to stop observiced first to have an
#                         oderly shutdown before we blast everyone.
#   tdziedzi   05/07/08 - Solaris shared object support
#   jwadleig   04/18/08 - bug 6980585 prevent deletion of admin dir one level up during
#                         uninstall
#   jwadleig   08/15/07 - fix bug 6279024 -- cleaning up /usr/tmp
#   jwadleig   09/29/06 - fix support for hpux 64
#   rvullika   07/31/06 - fix bug 5381589 - intermittent errors on solaris64 
#                         uninstall
#   rvullika   05/10/06 - Save the "db dir" when users asks to save admin dir
#   jwadleig   03/10/06 - update /etc/ld.so.conf on uninstall
#   tdziedzi   03/03/06 - Add obproxyd to daemon list 
#   rvullika   01/29/06 - save OSB home when asked by the user
#   rvullika   01/26/06 - (bug 4950684) observiced wasn't getting 
#                         terminated on a solaris64 uninstall
#   rvullika   09/27/05 - fix the bin, etc, lib links cleanup logic
#   tdziedzi   05/18/05 - Product name change 
#   rvullika   04/29/05 - (Bug 4334532) get admin directory information from
#                         /etc/obconfig
#   rvullika   11/05/04 - Fix /usr/tmp cleanup
#   rvullika   11/04/04 - Fix driver uninstall
#   rvullika   11/02/04 - Fix daemon cleanup on solaris
#   tdziedzi   09/14/04 - Remove libobk.so and co. on uninstall 
#   rvullika   07/14/04 - Fix bin/etc link removal
#   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.
#    07/11/02 jrw  improve daemon stop logic.
#    05/31/02 jrw  remove rbsmd.
#    04/10/02 gms  removed rbl.
#    03/08/02 gms  removed authorize.
#    02/18/02 jrw  rename notifier to rbnotify.
#    12/04/01 gms  v3 mods.
#    09/14/00 gms  stop rbndmpd.
#    01/03/99 jrw  update phraseology.
#    04/17/98 jrw  quote argument to "-d" to accommodate HP C shell bug.
#    02/13/98 jrw  rename obsi dir.
#    02/12/98 jrw  use proper ps command and options.  Ignore 'no match' errors
#                  on certain removes.
#    01/21/98 jrw  stop rbsmd daemon; remove obsi.
#    08/14/97 gms  added -osv arg.
#    08/11/97 gms  gonzo updates.
#    03/21/95 gms  fixed -y recognition.
#    11/28/94 gms  added trace.
#    05/27/94 jrw  change 'home' to 'rb dir'.
#    02/16/94 kcl  rbi => rbrmgr (by using setlists.sh)
#    02/01/94 jrw  added rbcontrol.
#    01/20/94 mbc  add gui modules, rbconsole, rbhosts and rbstat.
#    12/23/93 jrw  add rbscheduled.
#    08/03/93 jrw  add rbserviced.
#    11/12/92 jrw  add sensitivity to .shared file.  also, delete /bin/rbi,
#                  /bin/rbt.
#    06/29/92 gms  call unmk_rs6000.sh if aix; avoid driver warning on domain.
#    06/17/92 jrw  original coding.
#
#  Usage:
#    uninstallhere <args>
#
#  Args are...
#   -a <arch>           mach_arch of this machine (required)
#   -da                 delete admin dir (unless shared and not -ds)
#   -ds                 delete ob dir even if nfs-shared
#   -kp <path>          pathname of kernel if Oracle Secure Backup generated a new one
#   -o <os>             os_name for this machine (required)
#   -osv <ver>          os_ver for this machine (required)
#   -p <path>           pathname of obparameters file (required)
#   -rmt                remote -- invoked from remote uninstallob
#   -so                 show-only -- just display commands
#   -u <path>           pathname of local copy of updaterc.sh (required)
#   -x                  turn on echo
#   -y                  turn on OBTRACE
#
#  The plan:
#       1.  parse argument list, verify existence of params file
#       2.  remove links
#       3.  remove device special files
#       4.  remove /etc/obconfig
#       5.  remove ob dir, preserving admin subdir if not -da

############################################################
#
#  Look for trace arg and init some stuff...

    onintr interrupted
    if (! $?OBTRACE) then
        echo "$argv" | grep "\-y" >&/dev/null
        if ( $status == 0 ) then
            setenv OBTRACE 1
        else
            setenv OBTRACE 0
            endif
        endif
    if ($OBTRACE) echo "###### uninstallhere $argv"

    unset my_mach_arch nuke_admin nuke_osb my_os_name nuke_db
    unset my_os_ver obpa remote kernel_path so upd
    set OB_TMP    = "/tmp"
    set mtmp      = ${OB_TMP}"/obmi$$"
    set mach_name = "`hostname`"
    set cmd       = ""
    set blk       = ""
    set err       = "ERROR (uninstallhere):"
    set wrn       = "WARNING (uninstallhere):"
    set errsum    = 0

############################################################
#
#  Process arguments:

    while ($#argv)
        switch ($1)
            case -a :
                shift
                set my_mach_arch = "$1"
                breaksw
            case -da :
                set nuke_admin
                breaksw
            case -ds :
                set nuke_osb
                breaksw
            case -db :
                set nuke_db
                breaksw
            case -kp :
                shift
                set kernel_path = "$1"
                breaksw
            case -o :
                shift
                set my_os_name = "$1"
                breaksw
            case -osv :
                shift
                set my_os_ver = "$1"
                breaksw
            case -p :
                shift
                set obpa = "$1"
                breaksw
            case -rmt :
                set remote
                breaksw
            case -so :
                set cmd = "echo"
                set blk = "..."
                set so
                breaksw
            case -u :
                shift
                set upd = "$1"
                breaksw
            case -x :
                set echo
                breaksw
            case -y :
                breaksw
            default
                echo "$err unrecognized arg: $1"
                goto failed
            endsw
        shift
        end

#   Make sure we've got everything we need...

    if (! $?my_mach_arch) then
        echo "$err machine arch not specified"
        goto failed
        endif

    if (! $?my_os_name) then
        echo "$err os name not specified"
        goto failed
        endif

    if (! $?my_os_ver) then
        echo "$err os version not specified"
        goto failed
        endif

    if (! $?obpa) then
        echo "$err obparameters file not specified"
        goto failed
        endif

    if (! -r $obpa) then
        echo "$err can't read parameters file $obpa"
        goto failed
        endif

    if (! $?upd) then
        echo "$err updaterc.sh script not specified"
        goto failed
        endif

    if (! -x $upd) then
        echo "$err can't execute updaterc.sh script $upd"
        goto failed
        endif

    set pscmd = '/bin/ps'
    set psopt = '-aef'
    
    echo ""

############################################################
#
#   Get the name of the Oracle Secure Backup directory. first try
#   the local obconfig file. if that fails, fall back on
#   the obparameters file...

    if (! -r /etc/obconfig) then
        echo ""
        echo "$wrn The Oracle Secure Backup config file, /etc/obconfig,"
        echo "     could not be found. This may indicate that Oracle Secure Backup is not"
        echo "     installed on this host. We will attempt to continue, but you"
        echo "     should expect errors."
        echo ""
        unset obdir
        unset obcfok
    else
        set obcfok
        set obdir = `grep "ob dir" /etc/obconfig | awk '{ print $3 }'`
        if ($status || $obdir == "") then
            set dir_info = `grep -i <$obpa "^[ 	]*${my_os_name}[ 	][ 	]*ob[ 	][ 	]*dir:[ 	]"`
            if ($#dir_info < 4 && "$my_os_name" == "ULTRIX") then
                set dir_info = `grep -i <$obpa "^[ 	]*decult[ 	][ 	]*ob[ 	][ 	]*dir:[ 	]"`
                endif
            if ($#dir_info < 4) then
                echo "$err no entry in $obpa for operating system ${my_os_name}"
                goto failed
                endif
            set obdir = "$dir_info[4]"
            endif
        if ($?so) echo "... [ob dir is $obdir]"
        set obadmindir_info = `grep -i < /etc/obconfig "^[       ]*admin[        ][      ]*dir:[         ]"`
        if ($status || $#obadmindir_info < 3) then
            set obadmindir = $obdir/admin
        else
            set obadmindir = $obadmindir_info[3]
            endif
        endif

############################################################
#
#   Get the locations of the symbolic links we created during installl...

    unset bin_link etc_link lib_link lib64_link
    set link_info = `grep -i <$obpa "^[ 	]*${my_os_name}[ 	][ 	]*links*:[ 	]"`
    if ($#link_info < 3 && "$my_os_name" == "ULTRIX") then
        set link_info = `grep -i <$obpa "^[ 	]*decult[ 	][ 	]*links*:[ 	]"`
        endif

    if ($#link_info >= 3) then
        set bin_link = "$link_info[3]"
        endif
    if ($#link_info >= 4) then
        set etc_link = "$link_info[4]"
        endif
    if ($#link_info >= 5) then
        set lib_link = "$link_info[5]"
        endif
    if ($#link_info >= 6) then
        set lib64_link = "$link_info[6]"
        endif

############################################################
#
#   Get rid of any links in the bin dir. (go there first so we
#   don't have to worry about /bin or whatever being a link.)

    if ($?bin_link) then
        echo "Removing $bin_link links to Oracle Secure Backup components..."
        if ($?so) echo "$blk pushd $bin_link"
        pushd $bin_link >&/dev/null
        set list = ( `ls -l | grep "$obdir/bin" | awk '{ i = NF-2 ; print $i }'` )
        foreach file_name ( $list )
            $cmd $blk /bin/rm -f $file_name
            @ errsum += $status
            end
        popd >&/dev/null
        endif

#   Same treatment for /etc links...

    if ($?etc_link) then
        echo "Removing $etc_link links to Oracle Secure Backup components..."
        if ($?so) echo "$blk pushd $etc_link"
        pushd $etc_link >&/dev/null
        set list = ( `ls -l | grep "$obdir/etc" | awk '{ i = NF-2 ; print $i }'` )
        foreach file_name ( $list )
            $cmd $blk /bin/rm -f $file_name
            @ errsum += $status
            end
        popd >&/dev/null
        endif

#   Same treatment for /lib links...

    if ($?lib_link) then
        echo "Removing $lib_link links to Oracle Secure Backup components..."
        if ($?so) echo "$blk pushd $lib_link"
        pushd $lib_link >&/dev/null
        set list = ( `ls -l | grep "$obdir/lib" | awk '{ i = NF-2 ; print $i }'` )
        foreach file_name ( $list )
            $cmd $blk /bin/rm -f $file_name
            @ errsum += $status
            end
        popd >&/dev/null
        endif

#   Same treatment for /usr/lib64 links...  special case for linux64

    if ($my_mach_arch == linux86_64 && $?lib64_link) then
        echo "Removing $lib64_link links to Oracle Secure Backup components..."
        if ($?so) echo "$blk pushd $lib64_link"
        pushd $lib64_link >&/dev/null
        set list = ( `ls -l | grep "$obdir/lib" | awk '{ i = NF-2 ; print $i }'` )
        foreach file_name ( $list )
            $cmd $blk /bin/rm -f $file_name
            @ errsum += $status
            end
        popd >&/dev/null
        endif

#   In HPUX we need to remove symlinks created in /usr/lib/hpux64
    if ($my_mach_arch == hp64ia) then
        set system_path = "/usr/lib/hpux64"
        if ($?lib_link && "$lib_link" != "$system_path") then
            echo "Removing $system_path links to Oracle Secure Backup components..."
            if ($?so) echo "$blk pushd $system_path"
            pushd $system_path >&/dev/null
            set list = ( `ls -l | grep "$obdir/lib" | awk '{ i = NF-2 ; print $i }'` )
            foreach file_name ( $list )
                $cmd $blk /bin/rm -f $file_name
                @ errsum += $status
                end
            popd >&/dev/null
            endif
        endif

############################################################
#
#   Kill off any Oracle Secure Backup daemons that are running...
#   First we must ask observiced to stop and in turn let it do
#   it's job in stopping all the other daemons.  Then we will go
#   around and clean up any that still exsist.

    echo "Stopping Oracle Secure Backup observiced daemon..."
    set daemons = (observiced)

    #  Send each running daemon the TERM signal:
    #
    set k_any = 0
    foreach daemon ($daemons)
        if ("$psopt" == "-aef") then
            set pids = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $2 }'` )
        else
            set pids = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $1 }'` )
            endif
        foreach pid ($pids)
            $cmd $blk kill -TERM $pid >&/dev/null
            @ k_any += 1
            end
        end

    #  If we found any running daemons, give things a little time to quiesce, then hit each
    #  with the big hammer:
    #
    if ($k_any > 0) then
        echo "Waiting for daemons to stop..."
        if (! $?so) sleep 4
        foreach daemon ($daemons)
            if ("$psopt" == "-aef") then
                set pids = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $2 }'` )
            else
                set pids = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $1 }'` )
                endif
            foreach pid ($pids)

                echo "Forcing $daemon in pid $pid to stop."
                $cmd $blk kill -KILL $pid >&/dev/null
                @ errsum += $status
    
                # wait just a bit for him to go away...
                set i = 1
                while ($i < 10)
                    if ("$psopt" == "-aef") then
                        set pid2 = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | grep "$pid " | awk '{ print $2 }'` )
                    else
                        set pid2 = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | grep "$pid " | awk '{ print $1 }'` )
                        endif
                    if ($pid2 != $pid || $?so) break
                    sleep 1
                    @ i += 1
                    end

                if ($i >= 10) echo "It appears that $daemon in pid $pid never stopped."
                end
            end

        endif

    #  Now that observiced has had it's chance to stop all the daemons we will just check to 
    #  make sure they are all gone.  If not we will see if we can convince them to leave.
    #

    set daemons = (obscheduled obhttpd obtar obrobotd obndmpd obixd obnotify obexec obtool obproxyd obacslibd obacsssid)

    #  Send each running daemon the TERM signal:
    #
    set k_any = 0
    foreach daemon ($daemons)
        if ("$psopt" == "-aef") then
            set pids = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $2 }'` )
        else
            set pids = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $1 }'` )
            endif
        foreach pid ($pids)
            if ($k_any == 0) echo "Stopping any remaining Oracle Secure Backup daemons..."
            $cmd $blk kill -TERM $pid >&/dev/null
            @ k_any += 1
            end
        end

    #  If we found any running daemons, give things a little time to quiesce, then hit each
    #  with the big hammer:
    #
    if ($k_any > 0) then
        echo "Waiting for daemons to stop..."
        if (! $?so) sleep 4
        foreach daemon ($daemons)
            if ("$psopt" == "-aef") then
                set pids = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $2 }'` )
            else
                set pids = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | awk '{ print $1 }'` )
                endif
            foreach pid ($pids)

                echo "Forcing $daemon in pid $pid to stop."
                $cmd $blk kill -KILL $pid
                @ errsum += $status
    
                # wait just a bit for him to go away...
                set i = 1
                while ($i < 10)
                    if ("$psopt" == "-aef") then
                        set pid2 = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | grep "$pid " | awk '{ print $2 }'` )
                    else
                        set pid2 = ( `$pscmd $psopt | grep -v grep | grep "$daemon" | grep "$pid " | awk '{ print $1 }'` )
                        endif
                    if ($pid2 != $pid || $?so) break
                    sleep 1
                    @ i += 1
                    end

                if ($i >= 10) echo "It appears that $daemon in pid $pid never stopped."
                end
            end

        endif

    unset k_any pid pids daemon daemons i pid2

############################################################
#
#   Remove automatic startup of Oracle Secure Backup daemons...

    echo "Removing (if necessary) logic to start Oracle Secure Backup daemons at boot time..."
    set idir = "/"                  # dummy -- should never be used
    set uninstall
    set savetrace = $OBTRACE
    setenv OBTRACE 0                # updaterc.sh looks for idir if this is on
    $cmd $blk source $upd
    setenv OBTRACE $savetrace
    unset savetrace

############################################################
#
#  Now, remove our presence from /etc/ld.so.conf like we 
#  were never here...
    if ($my_mach_arch == linux32 || $my_mach_arch == linux86_64 || $my_mach_arch == linuxia64) then
        grep -q "$PWD/lib" /etc/ld.so.conf   
        if ($status == 0) then 
        echo "Updating /etc/ld.so.conf "
        grep -v "$PWD/lib" /etc/ld.so.conf >temp.conf
        cp temp.conf /etc/ld.so.conf
        rm temp.conf
        /sbin/ldconfig
        if ($status == 1) goto done
            endif
    else if ($my_mach_arch == solaris) then
        echo "Updating default and trusted library paths"

        set deflib = `crle | grep "Default Library Path"`
        echo "$deflib" | grep "$PWD" >& /dev/null
        if ($status == 0 && $#deflib == 5) then
            set deflib = `echo "$deflib[5]" | sed -e "s+:$PWD/.lib.solaris++"`
        else
            set deflib = ""
            endif

        set seclib = `crle | grep "Trusted Directories"`
        echo "$seclib" | grep "$PWD" >& /dev/null
        if ($status == 0 && $#seclib == 4) then
            set seclib = `echo "$seclib[4]" | sed -e "s+:$PWD/.lib.solaris++"`
        else
            set seclib = ""
            endif

        crle -l $deflib -s $seclib
    else if ($my_mach_arch == solaris64 || $my_mach_arch == solarisx86_64) then
        echo "Updating default and trusted library paths"

        set deflib = `crle -64 | grep "Default Library Path"`
        echo "$deflib" | grep "$PWD" >& /dev/null
        if ($status == 0 && $#deflib == 5) then
            set deflib = `echo "$deflib[5]" | sed -e "s+:$PWD/.lib.$my_mach_arch++"`
        else
            set deflib = ""
            endif

        set seclib = `crle -64 | grep "Trusted Directories"`
        echo "$seclib" | grep "$PWD" >& /dev/null
        if ($status == 0 && $#seclib == 4) then
            set seclib = `echo "$seclib[4]" | sed -e "s+:$PWD/.lib.$my_mach_arch++"`
        else
            set seclib = ""
            endif

        crle -64 -l $deflib -s $seclib
        endif


############################################################
#
#  Next, blast the local db dir and any of our stuff in the
#  temp dir...

    if ($?obcfok) then
        set dbdir = `grep "local db dir" /etc/obconfig | awk '{ print $4 }'`
        if ($status == 0) then
            if ($?nuke_db) then
                echo "Removing local system data ${dbdir}..."
                $cmd $blk /bin/rm -rf $dbdir
                if ($status) then
                    echo "$err unable to delete local system data $dbdir"
                    @ errsum += 1
                    endif
                endif
        else
            echo "$err unable to determine local system data - db dir not found"
            @ errsum += 1
            endif

        set tmpdir = `grep "temp dir" /etc/obconfig | awk '{ print $3 }'`
        if ($status == 0) then
            echo "Cleaning out ${tmpdir}..."
            if ($?so) echo "$blk pushd $tmpdir"
            pushd $tmpdir >&/dev/null
            set nonomatch
            set flist = (`echo ob*`)
            if ("$flist" == 'ob*') set flist = ()
            set glist = (`echo rws*`)
            if ("$glist" == 'rws*') set glist = ()
            set hlist = (`echo *.ob*`)
            if ("$hlist" == '*.ob*') set hlist = ()
            set flist = ($flist $glist $hlist)
            if ($#flist > 0) then
                foreach file_name ( $flist )
                    if (-f $file_name) then
                       $cmd $blk /bin/rm -f $file_name
                       endif
                    if ($status) then
                        echo "$err unable to delete Oracle Secure Backup file $file_name in temp dir"
                        @ errsum += 1
                        endif
                    end
                endif
            unset flist glist
            popd >&/dev/null
        else
            echo "$err unable to determine temp dir"
            @ errsum += 1
            endif
        endif

############################################################
#
#   Get rid of the device special files from the /dev directory.
#   While we're at it, nuke any architecture-specific pieces
#   of the driver.
#   In case of solaris, cleanup the 32 bit & 64 bit ob drivers
#   even when there are no device special files (in the case where
#   there are no real devices attached to the OB host.)
#   We use sgen. We do not support ob driver for solaris 
#   so clean up the code related to removing ob driver...
############################################################

    ls /dev | grep "rws[ht]" >&/dev/null
    if ($status == 0) then
        set nonomatch
        echo "Removing ob driver and device special files..."
        switch ($my_os_name)
            case solaris:
            case solaris64:
                set path  = (/usr/ccs/bin /usr/sbin $path)        # for nm, add_drv, rem_drv
                $cmd $blk rem_drv ob >&$mtmp
                @ errsum += $status
                grep busy $mtmp >&/dev/null
                if ($status == 0) echo "$wrn rem_drv reports ob driver is in use."
                $cmd $blk /bin/rm -f /usr/kernel/drv/ob*
                if (-d /usr/kernel/drv/sparcv9) then
                    $cmd $blk /bin/rm -f /usr/kernel/drv/sparcv9/ob*
                    endif
                @ errsum += $status
                $cmd $blk /bin/rm -f /dev/obt* /dev/obl*
                @ errsum += $status
                breaksw

            case SunOS:
            case IRIX:
            case NCR:
                $cmd $blk /bin/rm -f /dev/obt* /dev/obl*
                @ errsum += $status
                breaksw

            case HP-UX:
            case hp-ux:
                $cmd $blk /bin/rm -rf /dev/obt /dev/obl
                @ errsum += $status
                breaksw

            case AIX:
                $cmd $blk /bin/rm -f /dev/obt* /dev/obl*
                @ errsum += $status
                $cmd $blk /usr/lpp/obdd/lpp.cleanup
                breaksw

            endsw
        unset nonomatch
        endif

############################################################
#
#  Tell our user that he needs a new kernel if that is indeed the case...

    if ($?kernel_path) then
        echo ""
        echo "NOTE: To unlink Oracle Secure Backup's high performance device driver"
        echo "      from this host's operating system, replace the OS executable,"
        echo "      ${kernel_path}, with the one you saved during installation."
        echo "      (It is probably named ${kernel_path}.preob.) Then reboot"
        echo "      the machine."
        echo ""
        endif
############################################################ 
# 
#  Get rid of /etc/obconfig: 

    if ($?obcfok) then 
        if (($?nuke_osb && $?nuke_admin) || $?nuke_db) then 
           echo "Removing /etc/obconfig..." 
           $cmd $blk /bin/rm -f /etc/obconfig 
           @ errsum += $status 
        endif 

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

#
#  If we're deleting the entire Oracle Secure Backup tree except the admin directory,
#  be sure such a directory exists.  If not, nuke the whole thing.
#
    if ($?obdir) then
        if (-d "$obdir" && $?nuke_osb) then
            if ($?nuke_admin) then
                if (-d "$obadmindir") then
                     echo "Removing $obadmindir ..."
                     $cmd $blk /bin/rm -rf admin
                     @ errsum += $status
                     endif
                endif
#
#           here we are deleting everything in obdir except obadmindir if asked to preserve it
# 
            echo "Removing items from $obdir ..."
            $cmd $blk /bin/rm -rf apache samples tools.* install man help .lib.* .etc.* .bin.* .drv.* *.local .wrapper 
            @ errsum += $status

            $cmd $blk /bin/rm -f bin/ob* bin/hostinfo bin/php.ini device/ob_* etc/ob* lib/libfsp.so lib/libdisam.so lib/libndmpcommon.so lib/libqr.so lib/libnp.so lib/libobk.so
            @ errsum += $status
#
#           and a little solaris64 specific stuff
#
            if ($my_mach_arch == solaris64 || $my_mach_arch == solarisx86_64) then
                $cmd $blk /bin/rm -f  lib/libapr-1.so.0 lib/libaprutil-1.so.0 lib/libexpat.so.0
                @ errsum += $status
                endif
#
#           Bug 9358857: delete following lib explicitly for hp64ia 
#           Bug 12775775 & 13829629: also delete for AIX
#
            if ($my_mach_arch == hp64ia || $my_mach_arch == ibm64) then
               $cmd $blk /bin/rm -f  lib/libapr-1.so.0 lib/libaprutil-1.so.0
               @ errsum += $status
               endif
#
#           Bug 12775775 & 13829629: Don't forget the AIX specific file
#
            if ($my_mach_arch == ibm64) then
               $cmd $blk /bin/rm -f  lib/libobk.a 
               @ errsum += $status
               endif
#
#           set up the list of directories OSB uses and make sure they are empty before we
#           remove them
#
            set dlist = ("bin" "etc" "lib" "device") 
            foreach dirnam ( $dlist )
                if (`ls -1 $dirnam | wc -l` != 0) then
                     echo "WARNING: Cannot remove $obdir/$dirnam --  not empty"
                else
                    echo "Removing $obdir/$dirnam"
                    $cmd $blk rm -rf $dirnam
                    @ errsum += $status
                    endif
                end
             unset dlist
#
#           if we get here and the obdir is not empty we can't delete it no matter
#           what the user told us since they probably installed in an alternate
#           location which appears to contain non-OSB stuff and we don't dare delete it.
#
            set nents =  `ls -1 | wc -l`   
            if ($nents != 0) then
                if ($nents == 1 && -d "$obadmindir") then
                    echo "Saving $obadmindir"
                else
                    echo "WARNING: Cannot remove $obdir -- not empty"
                    endif
            else
                cd ../
                echo "Removing $obdir"
                $cmd $blk rm -rf $obdir
                @ errsum += $status
                endif
            unset nents
        else   # just remove the admin dir... preserve the rest
            if (-d "$obdir" && ! $?nuke_osb) then
                if ($?nuke_admin && -d "$obadmindir") then 
                    echo "Removing $obadmindir "
                    $cmd $blk /bin/rm -rf $obadmindir
                    @ errsum += $status
                    endif
                endif
            endif
        endif

    set st = 0

############################################################
#
#  Done. Announce success or failure and leave...

done:
    echo ""
    if ($st == 0) then
        if ($errsum == 0) then
            echo "Oracle Secure Backup has been successfully removed from ${mach_name}."
        else
            echo "One or more errors were encountered while removing Oracle Secure Backup from ${mach_name}."
            endif
    else
        if ($st != 9) echo "Fatal errors were encountered while removing Oracle Secure Backup from ${mach_name}."
        endif

    if ($OBTRACE) echo "###### uninstallhere exit status $st"
    sleep 1
    /bin/rm -f $mtmp >&/dev/null
    exit ($st)

failed:
    set st = 1
    goto done

interrupted:
    set st = 9
    goto done

