summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul C. Buetow (mars.fritz.box) <paul@buetow.org>2014-06-20 09:45:00 +0200
committerPaul C. Buetow (mars.fritz.box) <paul@buetow.org>2014-06-20 09:45:00 +0200
commitfe9477450a96d0e731126375b523b229088d2b1e (patch)
treeab5420dd1479e5e9bd8c6329ddb2b2163ac287cc /src
parent37966ff1cc5f3c94a5f749fcfd8d4c64754d58c4 (diff)
theoretically it also works with directories now
Diffstat (limited to 'src')
-rwxr-xr-xsrc/netdiff34
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}