#!/bin/ksh


# Copyright (c) 2005 by Sun Microsystems, Inc.
# All rights reserved

patch_manifest_files() {
        cd $ROOTDIR/var/sadm/pkg
        ## restore all r.manifest files
        for mf_file in `/bin/ls */save/pspool/*/install/r.manifest.${PatchNum} 2> /dev/null` ; do
		typeset pkg=`echo $mf_file | awk -F/ '{print $1}'`
        	mv $mf_file $pkg/save/pspool/$pkg/install/r.manifest
                typeset  orig_file=$pkg/save/pspool/$pkg/install/r.manifest
                typeset pkgmap_file=$pkg/save/pspool/$pkg/pkgmap
                typeset  manifest_sum=$(/usr/bin/sum $orig_file | awk '{print $1}')
                typeset  manifest_sz=$(/usr/bin/wc -c $orig_file | awk '{print $1}')
                /usr/bin/nawk -v pi="$manifest_sz" -v pm="$manifest_sum" '
                   $3 ~ /r\.manifest/ {
                        printf("%s %s %s %s %s %s\n", $1, $2, $3, pi, pm, $6)
                   }
                   $3 !~ /r\.manifest/ {
                        print
                   }' $pkgmap_file > $pkgmap_file.$$ || exit 1
                /usr/bin/mv -f ${pkgmap_file}.$$ ${pkgmap_file}     || exit 1
 
 
        done
}

## Main

patch_manifest_files

exit 0
