#!/bin/sh 
# rmdupsfrom1dir -- takes 2 directories as arguments,
#         any files in the first directory that are identical to the same file
#         named in the second directory are removed, and the first directory
#         too if it becomes empty
#
# AUTHOR:	Gary T. Leavens

[ -n "$echo" ] && set -x

USAGE="$0 old-dir new-dir"

# needs 2 arguments
if test $# -ne 2
then
	echo "$USAGE" >&2
	exit 1
fi

OLDDIR=$1
NEWDIR=$2

for d in "$OLDDIR" "$NEWDIR"
do
    if test \! -d "$d"
    then
	echo "$d does not exist or is not readable!" >&2
	exit 2
    fi
done

for f in `ls -1 $OLDDIR`
do
	if cmp --quiet "$OLDDIR/$f" "$NEWDIR/$f"
	then
	    rm -f "$OLDDIR/$f"
	fi
done

rmdir $OLDDIR
