#!/bin/bash

# Program to merge contents of one directory into another directory while
# eliminating identical files.  diff is used to check if files are identical.
# Non-identical files with the same name are preserved in each directory.
# 
# Written by:  Chris Studholme
# Last Update: 8-Jan-1999
# Copyright:   GPL (http://www.fsf.org/copyleft/gpl.html)

if [ ! \( -d "$1" -a -d "$2" \) ]; then
	echo "Usage:"
	echo "  `basename $0` source-dir dest-dir"
	exit 1
fi

for i in "$1"/*; do
if [ -f "$i" ]; then
	if [ -f $2/`basename "$i"` ]; then
		if diff "$i" "$2"/`basename "$i"` >/dev/null; then
			mv "$i" "$2"
		fi
	else
		mv "$i" "$2"
	fi
fi
done
