diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-07-29 17:11:39 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-07-29 17:11:39 +0200 |
commit | 766b3ec86cf27c199505abe8468ceff201eed994 (patch) | |
tree | 774ed05a6f773048f7eb60ea3f43fd8454b537e3 | |
parent | 9cf83395a0caf21bdbf79129fb31ed0f0d2db562 (diff) | |
download | bin-766b3ec86cf27c199505abe8468ceff201eed994.tar.gz bin-766b3ec86cf27c199505abe8468ceff201eed994.tar.xz |
syncrepo.sh: Use function instead of array for rsync command
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-x | syncrepo.sh | 27 |
1 files 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' \ |