scripts/sync: add --verbose flag and support syncing multiple machines
This commit is contained in:
80
scripts/sync
80
scripts/sync
@@ -2,33 +2,52 @@
|
||||
#!nix-shell -i bash -p bash -p rsync -p sane-scripts.sync-music
|
||||
|
||||
usage() {
|
||||
echo "sync all|desko|lappy|moby [passthrough flags ...]"
|
||||
echo "sync [flags ...] <host> [<host> ...] [passthrough flags ...]"
|
||||
echo "where:"
|
||||
echo " host: all|desko|lappy|moby"
|
||||
exit 1
|
||||
}
|
||||
|
||||
debug() {
|
||||
if [ -n "$SYNC_DEBUG" ]; then
|
||||
echo "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
ifExists() {
|
||||
local path="$1"
|
||||
shift
|
||||
local cmd="$@"
|
||||
if test -d "$path"; then
|
||||
debug "${cmd[@]}"
|
||||
${cmd[@]}
|
||||
else
|
||||
debug "skipping action because $path doesn't exist"
|
||||
fi
|
||||
}
|
||||
|
||||
syncHost() {
|
||||
local host=$1
|
||||
shift
|
||||
local syncFlags=("$@")
|
||||
case "$host" in
|
||||
(all)
|
||||
syncHost desko "${syncFlags[@]}"
|
||||
syncHost lappy "${syncFlags[@]}"
|
||||
syncHost moby "${syncFlags[@]}"
|
||||
;;
|
||||
(desko)
|
||||
test -d /mnt/servo/media/Music/Various.Artists && sane-sync-music --compat /mnt/servo/media/Music /mnt/desko/home/Music "${syncFlags[@]}"
|
||||
ifExists /mnt/servo/media/Music/Various.Artists \
|
||||
sane-sync-music --compat /mnt/servo/media/Music /mnt/desko/home/Music "${syncFlags[@]}"
|
||||
;;
|
||||
(lappy)
|
||||
test -d /mnt/servo/media/Music/Various.Artists && sane-sync-music --compress --compat /mnt/servo/media/Music /mnt/lappy/home/Music "${syncFlags[@]}"
|
||||
ifExists /mnt/servo/media/Music/Various.Artists \
|
||||
sane-sync-music --compress --compat /mnt/servo/media/Music /mnt/lappy/home/Music "${syncFlags[@]}"
|
||||
;;
|
||||
(moby)
|
||||
# copy photos/screenshots from moby to desko:
|
||||
rsync -arv --exclude servo-macros /mnt/moby/home/Pictures/ /mnt/desko/home/Pictures/from/moby/
|
||||
# copy books from servo to moby; delete old/untracked ones, but keep KOreader state files (sdr)
|
||||
test -d /mnt/servo/media/Books/Books && rsync -arv --delete --exclude '*.sdr' /mnt/servo/media/Books/ /mnt/moby/home/Books/local/servo/
|
||||
ifExists /mnt/servo/media/Books/Books \
|
||||
rsync -arv --delete --exclude '*.sdr' /mnt/servo/media/Books/ /mnt/moby/home/Books/local/servo/
|
||||
# copy music
|
||||
test -d /mnt/servo/media/Music/Various.Artists && sane-sync-music --compat /mnt/servo/media/Music /mnt/moby/home/Music "${syncFlags[@]}"
|
||||
ifExists /mnt/servo/media/Music/Various.Artists \
|
||||
sane-sync-music --compat /mnt/servo/media/Music /mnt/moby/home/Music "${syncFlags[@]}"
|
||||
;;
|
||||
(*)
|
||||
usage
|
||||
@@ -36,4 +55,43 @@ syncHost() {
|
||||
esac
|
||||
}
|
||||
|
||||
syncHost "$@"
|
||||
hosts=()
|
||||
passthruArgs=()
|
||||
parseArgs() {
|
||||
while [[ $# -ge 1 ]]; do
|
||||
local arg=$1
|
||||
case $arg in
|
||||
(desko|lappy|moby)
|
||||
hosts+=("$arg")
|
||||
shift
|
||||
;;
|
||||
(all)
|
||||
hosts+=(desko lappy moby)
|
||||
shift
|
||||
;;
|
||||
(--verbose)
|
||||
if [[ "${#hosts[@]}" -eq 0 ]]; then
|
||||
SYNC_DEBUG=1
|
||||
shift
|
||||
else
|
||||
# it's a passthru flag
|
||||
break
|
||||
fi
|
||||
;;
|
||||
(--help)
|
||||
usage
|
||||
shift
|
||||
;;
|
||||
(*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
passthruArgs+=("$@")
|
||||
}
|
||||
|
||||
parseArgs "$@"
|
||||
debug "hosts:" "${hosts[@]}"
|
||||
for host in "${hosts[@]}"; do
|
||||
syncHost "$host" "${passthruArgs[@]}"
|
||||
done
|
||||
|
Reference in New Issue
Block a user