From a37134881c4192415fd13c2981393eed3bf393ad Mon Sep 17 00:00:00 2001 From: Simon Paillard Date: Mon, 29 Apr 2013 23:52:14 +0200 Subject: Move reusable code to function rsync_protocol --- bin/ftpsync | 14 ++++---------- etc/common | 9 +++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bin/ftpsync b/bin/ftpsync index 23d7eb0..db8ad55 100755 --- a/bin/ftpsync +++ b/bin/ftpsync @@ -290,21 +290,15 @@ RSYNC=${RSYNC:-rsync} RSYNC_FILTER=${RSYNC_FILTER:-"--filter=protect_Archive-Update-in-Progress-${MIRRORNAME} --filter=protect_${TRACE} --filter=protect_Archive-Update-Required-${MIRRORNAME}"} # limit I/O bandwidth. Value is KBytes per second, unset or 0 is unlimited RSYNC_BW=${RSYNC_BW:-0} +RSYNC_PROTOCOL=$(rsync_protocol) # Set the delete method to --delete-delay if protocol version is 30 or # greater (meaning rsync 3.0.0 or greater is used). Use --delete-after # otherwise. -RSYNC_DELETE_METHOD=${RSYNC_DELETE_METHOD:-auto} -if [ "xautox" = "x${RSYNC_DELETE_METHOD}x" ]; then +if [ 30 -le $RSYNC_PROTOCOL ]; then + RSYNC_DELETE_METHOD=delay +else RSYNC_DELETE_METHOD=after - - RSYNC_VERSION="$(${RSYNC} --version)" - if [[ $RSYNC_VERSION =~ (protocol[ ]+version[ ]+([0-9]+)) ]]; then - if [ 30 -le ${BASH_REMATCH[2]} ]; then - RSYNC_DELETE_METHOD=delay - fi - fi - unset RSYNC_VERSION fi # Default rsync options for *every* rsync call diff --git a/etc/common b/etc/common index 0501240..de3cfac 100644 --- a/etc/common +++ b/etc/common @@ -232,3 +232,12 @@ savelog() { done mv "${torotate}" "${torotate}.0" } + +# Return rsync version +rsync_protocol() { + RSYNC_VERSION="$(${RSYNC} --version)" + if [[ $RSYNC_VERSION =~ (protocol[ ]+version[ ]+([0-9]+)) ]]; then + echo ${BASH_REMATCH[2]} + fi + unset RSYNC_VERSION +} -- cgit v1.2.3