diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/netdiff | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/netdiff b/src/netdiff index 8c2d6b6..9bba61f 100755 --- a/src/netdiff +++ b/src/netdiff @@ -6,42 +6,48 @@ declare -r VERSION='VERSION_DEVEL' declare -i RC=0 -declare -r SERVER="${1}" ; shift -declare -r FILE="${1}" ; shift -declare -i PORT="${1}" ; shift +declare -r SERVER="${1}" ; shift +declare -r PATH="${1}" ; shift +declare -i PORT="${1}" ; shift usage () { cat <<USAGE This is NetDiff ${VERSION}. Usage: - netdiff SERVER FILE [PORT=1234] [DIFF OPTS] + netdiff SERVER PATH [PORT=1234] [DIFF OPTS] USAGE } -[ -z "${FILE}" ] && usage && exit 0 +[ -z "${PATH}" ] && usage && exit 0 if [[ -z "${PORT}" || ${PORT} == 0 ]]; then PORT=1234 - declare -r DIFF_DEFAULT_OPTS=-u + declare -r DIFF_DEFAULT_OPTS='--unified --recursive' fi -declare -r TMPFILE=$(mktemp) +declare -r TMPPATH=$(mktemp --directory) +set -e pipefail -if [[ "${SERVER}" == "$(hostname)" || "${SERVER}" == "$(hostname -f)" ]]; then - nc -l -p ${PORT} < "${FILE}" > $TMPFILE +if [[ "${SERVER}" == "$(hostname)" || + "${SERVER}" == "$(hostname --fqdn)" ]]; then + tar -cf - . --directory "${PATH}" | + nc -l -p ${PORT} | + tar -xf - --directory ${TMPPATH} RC=$? else sleep 0.1 - nc ${SERVER} ${PORT} < "${FILE}" > $TMPFILE + tar -cf - . --directory "${PATH}" | + nc ${SERVER} ${PORT} | + tar -xf - --directory ${TMPPATH} RC=$? fi -if [ $RC -ne 0 ]; then +if [ ${RC} -ne 0 ]; then echo 'Could not copy file via the network' RC=2 # Default trouble exit status of diff else - diff $@ ${FILE} ${TMPFILE} ${DIFF_DEFAULT_OPTS} + diff $@ "${PATH}" ${TMPPATH} ${DIFF_DEFAULT_OPTS} RC=$? fi -[ -f $TMPFILE ] && rm $TMPFILE -exit $RC +[ -f ${TMPPATH} ] && rm -rf ${TMPPATH} +exit ${RC} |
