#!/bin/sh
####
# NAME
#	copy-if-changed - copy source file to destination if the source file
#	  is differ from destination.
# VERSION
#	$Id$
# CHANGELOG
#	$Log$
# USAGE
#	copy-if-changed src-file dst-file
# COPYRIGHT
#  Copyright (C) 2000,2001 Steel Wheels Project.
#  This file is a apart of the papaya utilities. 
#  If you need the information of copyright of this file, see COPYING
#  file distributed with file or see http://www.asahi-net.or.jp/~em7t-hmd
#  web page.

SRC=$1 
DST=$2 

message(){
	echo "copy-if-changed: $1" >&2 ;
}

error(){
	message "[ERROR] $1" ;
	exit 1 ;
}

copy_file(){
	if cp $1 $2 ; then
		message "copying was done." ;
	else
		error "coping was failed." ;
	fi
}

if test "X$SRC" = "X" ; then
	error "source file name is not given." ;
fi

if test ! -f $SRC ; then
	error "source file \"$SRC\" is not exist." ;
fi

if test "X$DST" = "X" ; then
	error "destination file name is not given." ;
fi

if test -f $DST ; then
	if diff $SRC $DST > /dev/null ; then
		message "there are no difference, copying was skipped." ;
	else
		copy_file $SRC $DST ;
	fi
else
	copy_file $SRC $DST ;
fi

exit 0 ;

