From 766b3ec86cf27c199505abe8468ceff201eed994 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 29 Jul 2017 17:11:39 +0200 Subject: syncrepo.sh: Use function instead of array for rsync command Signed-off-by: Florian Pritz --- syncrepo.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/syncrepo.sh b/syncrepo.sh index a8ae0ff..682ec79 100755 --- a/syncrepo.sh +++ b/syncrepo.sh @@ -11,8 +11,8 @@ home="/srv" target="${home}/repo" tmp="${home}/tmp" lock='/var/lock/syncrepo.lck' -# NOTE: You'll probably want to change this or remove the --bwlimit setting in -# the rsync call below +# NOTE: You'll probably want to change this or set it to 0 to disable the limit +# The default unit is KiB (see man rsync /--bwlimit for more) bwlimit=4096 # NOTE: most people reading this very likely need to change this since # rsync.archlinux.org requires you to be a tier 1 mirror @@ -25,21 +25,30 @@ lastupdate_url="http://rsync.archlinux.org/lastupdate" exec 9>"${lock}" flock -n 9 || exit -if stty &>/dev/null; then - VERBOSE="-h -v --progress" -fi +rsync_cmd() { + local -a cmd=(rsync -rtlH --safe-links --delete-after ${VERBOSE} "--timeout=600" "--contimeout=60" -p \ + --delay-updates --no-motd "--temp-dir=${tmp}") + + if stty &>/dev/null; then + cmd+=(-h -v --progress) + fi + + if ((bwlimit>0)); then + cmd+=("--bwlimit=$bwlimit") + fi + + "${cmd[@]}" "$@" +} -rsync_cmd=(rsync -rtlH --safe-links --delete-after ${VERBOSE} "--timeout=600" "--contimeout=60" -p \ - --delay-updates --no-motd "--bwlimit=$bwlimit" "--temp-dir=${tmp}") # if we are called without a tty (cronjob) only run when there are changes if ! tty -s && [[ -f "$target/lastupdate" ]] && diff -b <(curl -s "$lastupdate_url") "$target/lastupdate" >/dev/null; then # keep lastsync file in sync for statistics generated by the Arch Linux website - "${rsync_cmd[@]}" "$source/lastsync" "$target/lastsync" + rsync_cmd "$source/lastsync" "$target/lastsync" exit 0 fi -"${rsync_cmd[@]}" \ +rsync_cmd \ --exclude='*.links.tar.gz*' \ --exclude='/other' \ --exclude='/sources' \ -- cgit v1.2.3-24-g4f1b