#!/bin/sh
#
# delete_fls pkgname ...
#
#
#############################################################################
#
#	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
#
#############################################################################

test -z "$Rm" 	&& Rm=/bin/rm;		export Rm

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

useXargs=`( xargs true </dev/null && echo true ) 2>/dev/null`
if [ "X$useXargs" = 'Xtrue' ]; then
    rmFls="xargs $Rm -f"
    rmDirs="xargs rmdir"
else
    rmFls="while read fname; do $Rm -f \$fname; done"
    rmDirs="while read fname; do rmdir \$fname; done"
fi


cd $Proot 
for pkgname in $rmPkgs; do
    invFl=./install/pkgs/$pkgname.inv
    if [ -f $invFl ]; then
        # delete files, (directories end in slash)
	awk '/[^\/]$/ {print $NF}' $invFl | eval $rmFls 2>/dev/null

        # now  delete empty directories (bottom up)
	awk '/\/$/ {print $NF}'	$invFl | sed -n 's@/$@@p' | sort -r |\
	    eval $rmDirs 	2>/dev/null
    else
	echo "Unable to locate inventory file: $pkgname.inv" 	1>&2
    fi
done 

exit 0
