#!/bin/sh
#								RogerBrobst
# delete_pkgs pkginfofl
#
#	foreach line in pkginfofl
#	    run package install program (??.exe) with phase=PRE_DELETE
#	    if ok_status then 
#		delete all leaves in inventory file
#	        run pkg install program with phase=POST_DELETE
#	        delete the misc install files associated with the package
#	    fi
#	end
#
#############################################################################
#
#	Copyright (C) Cadence Design Systems, Inc. All rights
#	reserved.  Unpublished -- rights reserved under the
#	copyright laws of the United States of America.
#
#			RESTRICTED RIGHTS LEGEND
#	Use, duplication, or disclosure by the Government is subject
#	to restrictions as set forth in subparagraph (c)(l)(ii) of 
#	the Rights in Technical Data and Computer Software clause 
#	at DFARS 52.227-7013.
#
#			Cadence Design Systems, Inc.
#			555 River Oaks Parkway
#			San Jose, CA 95134	USA
#
#############################################################################
BOURNE=/bin/sh
XTERMPATH=/usr/bin/X11
XTERMBIN=xterm
XTERMOPTS="-T 'SoftLoad 6.0 Console' -fn 9x15  -sl 200 -g 80x40+0+0 -bg \#e0e0e0 -fg \#800000 -sb -e ${BOURNE} softload_GUI"
sysPATH=/bin:/usr/bin:/usr/ucb:$XTERMPATH

jsr=''

OSvendor=hppa
OSarchs=$OSvendor
Archtype() {
    echo $OSvendor
}


test -z "$Rm" && Rm=/bin/rm;		export Rm
if [ -z "$Proot" -o -z "$bin_dir" ]; then  
    echo "$0 environment not initialized" 				1>&2
    exit 1 
fi
export Proot

pkginfofl=$1
test $# -gt 0 && shift $#	#precaution against interaction w/sh fnxn args


( 
    cd $Proot 

    ARCHTYPE=`$jsr Archtype`;		export ARCHTYPE
    TIMESTAMP=`date`;			export TIMESTAMP

    phase=
    PKGNAME=
    export phase PKGNAME

    while read pkgdesc pkgname discard; do
	pkgdesc=`echo $pkgdesc | tr '~' ' ' `
	pkgRoot=./install/pkgs/$pkgname
	PKGNAME=$pkgname


	if [ -s $pkgRoot.exe ]; then
	    phase=PRE_DELETE  $pkgRoot.exe < /dev/tty || {
		echo "deletion of $pkgname aborted"
		continue
	    }
	fi

	echo "Deleting: $pkgdesc         ($pkgname) "
	$Rm $pkgRoot.ok 					2> /dev/null
	$BOURNE $bin_dir/delete_fls $pkgname			2> /dev/null

	if [ -s $pkgRoot.exe ]; then
	    phase=POST_DELETE $pkgRoot.exe < /dev/tty
	fi

	if [ -f ./install/tmp/$pkgname.inv ]; then 
	    $Rm $pkgRoot.inv 					2> /dev/null
	fi
	mv  $pkgRoot.* ./install/tmp				2> /dev/null
    done < $pkginfofl
)

exit 0
