#!/bin/sh
#
#    check_pdtok pdtinfofl 
#
#	check_pdtok is used to check products nok files whether all
#	the packages associated with this product are installed, if
#	so, then move products.nok to products.ok. If not, then leave
#	products.nok there.
#	
#############################################################################
#############################################################################
#
#	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

if [ -z "$Proot" ]; then  
    echo "$0 environment not initialized" 				1>&2
    exit 1 
fi
export Proot

tmp=$Proot/install/tmp
pkgs=$Proot/install/pkgs
pdts=$Proot/install/pdts
history=$Proot/install/tmp/install.history

pdtinfofl=$1 ; shift

sort -u +1 -2 $pdtinfofl | \
while read pkgname pdtname platform FMrelease ; do
	installed=true
        pdtRoot="${pdts}/${pdtname}_${platform}_${FMrelease}"
	test -s ${pdtRoot}.nok || continue
	packages=`sed -n '2,$p' ${pdtRoot}.nok | awk '{ print $1}' | sort -u`
	for package in $packages ; do
	    pkgRoot="${pkgs}/${package}"
	    test -s ${pkgRoot}.ok || installed=false
	done    
	test $installed = "true" && {\
          mv ${pdtRoot}.nok ${pdtRoot}.ok
          echo "$pdtname  $platform $FMrelease installed successfully" >> $history
         }
done 
exit 0
