diff options
| author | Paul C. Buetow (mars.fritz.box) <paul@buetow.org> | 2014-06-20 01:11:09 +0200 |
|---|---|---|
| committer | Paul C. Buetow (mars.fritz.box) <paul@buetow.org> | 2014-06-20 01:11:09 +0200 |
| commit | 8634cef386a7d786f038424c95f0a9b59028ac35 (patch) | |
| tree | 99332ea22e222464d12fd76440a126a203228487 | |
| parent | 02e1ef1f60d6606be65e458fbe62e38de525ca3b (diff) | |
initial works
| -rwxr-xr-x | src/netdiff | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/netdiff b/src/netdiff index 1e756f6..4d56372 100755 --- a/src/netdiff +++ b/src/netdiff @@ -1,5 +1,45 @@ -#!/bin/bash +#!/usr/bin/env bash + +# NetDiff (c) Paul C. Buetow (2014) +# http://netdiff.buetow.org declare -r VERSION='VERSION_DEVEL' +declare -i RC=0 + +declare -r SERVER="${1}" ; shift +declare -r FILE="${1}" ; shift +declare -i PORT="${1}" ; shift + +usage () { + cat <<USAGE +This is NetDiff ${VERSION}. Usage: + netdiff SERVER FILE [PORT=1234] [DIFF OPTS] +USAGE +} + +[ -z "${FILE}" ] && usage && exit 0 +if [[ -z "${PORT}" || ${PORT} == 0 ]]; then + PORT=1234 + declare -r DIFF_DEFAULT_OPTS=-u +fi + +declare -r TMPFILE=$(mktemp) + +if [[ "${SERVER}" == "$(hostname)" || "${SERVER}" == "$(hostname -f)" ]]; then + nc -l -p ${PORT} < "${FILE}" > $TMPFILE + RC=$? +else + sleep 0.1 + nc ${SERVER} ${PORT} < "${FILE}" > $TMPFILE + RC=$? +fi + +if [ $RC -ne 0 ]; then + echo 'Could not copy file via the network' +else + diff $@ ${FILE} ${TMPFILE} ${DIFF_DEFAULT_OPTS} +fi + +[ -f $TMPFILE ] && rm $TMPFILE +exit $RC -echo "This is version $VERSION of the example netdiff project." |
