#!/bin/bash
#
# Copyright (c) International Business Machines  Corp., 2005
# Author: Avantika Mathur (mathurav@us.ibm.com)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

reverse=0
while getopts "n" args $OPTIONS
do
	case "$args" in
        n)      reverse=1
		shift
                ;;
 	esac
done

if [ $reverse -eq 1 ]
then
	echo Check No Propagation $*
else
	echo Check Propagation $*
fi

dir1="$1"
shift

for dir2 in "$@"
do
	# compare adjacent pairs of directory trees

	echo "Checking \"$dir1\" \"$dir2\""
	diff -r "$dir1" "$dir2" 2> /dev/null

	if [ $? -ne 0 ]
	then
		if [ $reverse -eq 1 ]
		then
			echo Successful
			echo "---------"
			exit 0
		else
			echo "FAILED"
			echo "---------"
                	exit 1
		fi
        fi
        dir1="$dir2"
done

if [ $reverse -eq 1 ]
then
	echo FAILED
	echo "---------"
	exit -1
else
	echo Successful
	echo "---------"
	exit 0
fi