#!/bin/ksh

#
# This script will revise '/var/sadm/pkg/SUNWjwbc/pkginfo',
# which have wrong information.
#

ROOTDIR=/

rm_patch_num () {
    PatchNum=$1; shift
    PatchedPkgs=$*
    for pkg in $PatchedPkgs; do
	Pkginfo=$ROOTDIR/var/sadm/pkg/$pkg/pkginfo

	existsInPI=$(pkgparam -R $ROOTDIR $pkg "PATCH_INFO_$PatchNum")
	if [[ -n "$existsInPI" ]]; then
	    sed -e "/PATCH_INFO_$PatchNum/d" ${Pkginfo} > ${Pkginfo}.new
	    mv ${Pkginfo}.new ${Pkginfo}
	fi

	listOfPatches=$(pkgparam -R $ROOTDIR $pkg PATCHLIST)
	existsInPL=$(echo $listOfPatches | grep $PatchNum)
	if  [[ -n "$existsInPL" ]]; then
	    sed -e "/$PatchNum/s///" ${Pkginfo} > ${Pkginfo}.new
	    mv ${Pkginfo}.new ${Pkginfo}
	fi
	chmod 644 ${Pkginfo}
    done
}

rm_patch_num 109071-02 SUNWjwbc

exit 0
