#sccs	"@(#)fndetc/convert:uaconvert	1.3"

# uaconvert 
# This shell will merge a new release ua file (e.g., Office)
# with an old file by keeping all of the new release file
# and appending the objects (i.e., Name=) that were found
# in the old file but are not in the new release 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:  uaconvert 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.$$
export TNAME
cp $1 ${UA}/$TNAME

# get a list of "Name=" objects from newfile ...

grep '^Name' $2 | cut -d= -f2 -s > /tmp/names

#   remove those objects from the old file - now in $UA/$TNAME ...

while read NAME
do
	uaupd -r "$NAME" $TNAME
done < /tmp/names

#   and remove any renamed objects from the old file.  Allow the use
#   of comments by starting the line with a '#'.

while read NAME
do
	fCOMMENT=`expr "$NAME" : "#"`
	if [ "$fCOMMENT" = "0" ]
	then	uaupd -r "$NAME" $TNAME
	fi
done < RENAMED

# now add the unique Objects left in the oldfile to the newfile

cat ${UA}/$TNAME >> ${UA}/$FNAME

if [ $# -eq 3 ]
then 
	echo "new Release file updated with:"
	grep '^Name' $1 | cut -d= -f2 -s 
fi

rm -f /tmp/names
rm -f ${UA}/$TNAME
