#sccs	"@(#)fndetc/convert:offupdate	1.1"

# uafix 
# This shell will merge a new Release 3.0 ua file (e.g., Office)
# with an old file by keeping all of the new Release 3.0 file
# and appending the objects (i.e., Name=) that were found
# in the old file but are not in the new Release 3.0 file
#
# it requires 2 parameters, the oldfile and then the newfile names
#
# an optional third parameter forces "debug"mode which reports progress
# to the standard output and does not erase the /tmp files
#

UA=/usr/lib/ua
export UA

if [ $# -lt 2 ]; then
	echo "usage:  uathree oldfile newfile";
	exit 1;
fi

# uaupd takes only the relative path to /usr/lib/ua, therefore:

FNAME=`basename $2`

# TNAME is a temp name to move the old file to ua so uaupd can operate on it

TNAME=UATMP.$$
cp $1 ${UA}/$TNAME

# get a list of Release 3.0 "Name=" objects from newfile
grep '^Name' $2 | cut -d= -f2 -s > /tmp/names
# remove those Rel 3.0 objects from the oldfile - now in $UA/$TNAME
exec < /tmp/names
while read NAME
do uaupd -r "$NAME" $TNAME
done
# now add the unique Objects left in the oldfile to the newfile
cat ${UA}/$TNAME >> ${UA}/$FNAME
uaupd -r "Printer Queue" $FNAME
if [ $# -eq 3 ]; then 
	echo "new Release file updated with:"
	grep '^Name' $1 | cut -d= -f2 -s 
fi
rm  /tmp/names
rm ${UA}/$TNAME
