#sccs	"@(#)tools:qset	1.7"

#
# Name
# 	qset - Perform qinstall's, check that all is happy, and then 
#		 set the dates of all binaries to January 1, 1970.
#	
# Synopsis
#	qset arg1 .. argN 
#
#	qset -pr protofile arg1 .. argN
#
#	qset -a 
#
#	Where arg1 .. argN are the product names to be operated on
#	by the qinstall.   Protofile is the pathname to the 
#	specific protofile to be used as input to the qinstall's.
#	The "-a" option is used for a standard release to use a
#	hardcoded set of args and the standard mstr.proto usually
#	found in the directory $SRC.
#
# Description
#	Qset performs a previously manual process which confirms
#	that the state of the installed product is consistant with
#	what its supposed to be.   This is defined either in
#	a local proto file or $SRC/mstr.proto.
#	After checking for the existence of all files in the product
#	and changing their permissions and ownerships accordingly,
#	the time of last modification is changed to January 1, 1970.
#
#	Reports are generated if problems result, with the
#	output of the qinstall generating a report everytime.
#
# Files
#	./product_name.process_id
#	./trbl.product_name
#
# 
PRODUCT="FND DEV DOC EDITOR CMB PHONE ATE REPLAY"

if [ ! "$1" ]
then
		echo "USAGE: $0 [-pr protofile] arg1 .. argN
		echo "   or: $0 [-a]
		exit 1
fi
if [ -n "$1" -a "$1" = "-pr" ]
then

	shift
	PO="$1"
	shift

elif [ "$1" = "-a" ]
then
	AUTOMATIC="TRUE"
	PO="$SRC/mstr.proto"
elif [ "$1" = "-*" -o "$1" = "help" -o "$1" = "-h" ]
then
		echo "USAGE: $0 [-pr protofile] arg1 .. argN
		echo "   or: $0 [-a]
		exit 0
else
	PO="$SRC/mstr.proto"
fi

LOCALPATH=`pwd`
PROC=$$
PT=`eval echo $PO`

if [ "$AUTOMATIC" != "TRUE" ]
then
	while [ $1 ]
	do

		echo ""
		echo "Doing qinstall on $1"
		qinstall -c -s $PT $LOCALPATH/$1 

		echo "Checking existence of files"
		qinstall -c -e -o $PT $LOCALPATH/$1 > $1.$PROC 2>&1 

		grep $1 $1.$PROC > trbl.$1
		if [ -s trbl.$1 ]
		then
			echo "Check trbl.$1 for incorrectly installed product $1."
			exit 9
		else
			rm -f trbl.$1
			echo "Setting dates"
			find $1 -print -exec touch 0101101070 {} \; > /dev/null 2>&1 
			echo "Don't forget to remove $1.$PROC."
			shift
		fi
	done
else
	for ELEMENT in $PRODUCT
	do

		echo
		echo "Doing qinstall on $ELEMENT"
		qinstall -c -s $PT $LOCALPATH/$ELEMENT 

		echo "Checking existence of files"
		qinstall -c -e -o $PT $LOCALPATH/$ELEMENT > $ELEMENT.$PROC 2>&1 

		grep $ELEMENT $ELEMENT.$PROC > trbl.$ELEMENT
		if [ -s trbl.$ELEMENT ]
		then
			echo "Check trbl.$ELEMENT for incorrectly installed product $ELEMENT."
		else
			rm -f trbl.$ELEMENT
			echo "Setting dates"
			find $ELEMENT -print -exec touch 0101101070 {} \; > /dev/null 2>&1 
			echo "Don't forget to remove $ELEMENT.$PROC."
		fi
	done
fi
