summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/netdiff.pod2
-rwxr-xr-xsrc/netdiff34
2 files changed, 21 insertions, 15 deletions
diff --git a/docs/netdiff.pod b/docs/netdiff.pod
index fa9fbb7..0408990 100644
--- a/docs/netdiff.pod
+++ b/docs/netdiff.pod
@@ -10,7 +10,7 @@ A simple script to diff two files via the network.
ClusterSSH onto two hosts at the same time and run on both hosts the same command like:
- netdiff HOSTNAME FILENAME
+ netdiff HOSTNAME PATH
Where HOSTNAME can be the hostname of the first or the second host. Depending on this the script will decide to be the client or the server role.
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}