#!/bin/sh

if [ $# -ne 2 ]
then
    echo "Usage: $0 <directory-path> <machine-type>"
    exit 1
fi

if [ -z "$2" ]
then
    echo "Usage: $0 <directory-path> <machine-type>"
    exit 1
fi

if [ ! -d "$1" ]
then

    echo "$0: Warning - Directory $1 does not exist."
    exit 1

fi

MACHINE_TYPE="$2"
source "/etc/conf.d/upgrade"

# Drop the priority otherwise it almost brings an EAM to a halt until finished.
nice -n 5 rsync \
    --super \
    --verbose --stats --human-readable --progress --itemize-changes \
    --recursive --times \
    --links --perms \
    --delete --delete-delay --force \
    ${RSYNC_ADDITIONAL_OPTS} \
    --port "${RSYNC_PORT}" "rsync://${RSYNC_HOST}/${RSYNC_MODULE}/${MACHINE_TYPE}/" "${1}/${MACHINE_TYPE}"
