#!/bin/sh
#
# program update
#
#  this script copies the latest version of
#    fromdir/files to todir
#
USAGE="update fromDir toDir"

if [ $# -ne 2 ]
then
    echo $USAGE
    exit 1
elif [ ! -d $1 ]
then
    echo $USAGE
    exit 2
elif [ ! -d $2 ]
then
    echo $USAGE
    exit 3
fi
FROMLIST=$(/bin/ls -A $1) # I could have used `ls -A $1`
for ENTRY in $FROMLIST
do
    if [ ! -d ${1}/${ENTRY} ]
    then
        if [ ! -e ${2}/${ENTRY} ]
        then
            echo "Creating: ${ENTRY}"
            /bin/cp ${1}/${ENTRY} ${2}/${ENTRY}
        elif [ ${1}/${ENTRY} -nt ${2}/${ENTRY} ]
        then
            echo "Updating: ${ENTRY}"
            /bin/cp ${1}/${ENTRY} ${2}/${ENTRY}
        fi
    fi
done
exit 0     
