From c61ae865683f4f702984f6d09c309d3224cc9890 Mon Sep 17 00:00:00 2001 From: sefidel Date: Tue, 1 Aug 2023 21:47:02 +0900 Subject: feat(home/base): airport: delete files by default --- home/profiles/base/scripts/airport.nix | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'home/profiles/base/scripts/airport.nix') diff --git a/home/profiles/base/scripts/airport.nix b/home/profiles/base/scripts/airport.nix index cedb1d4..c46573d 100755 --- a/home/profiles/base/scripts/airport.nix +++ b/home/profiles/base/scripts/airport.nix @@ -2,9 +2,10 @@ # airport.sh - shared file store # # # Environment variables - # `AIRPORT_HOST` - host to rsync to - # `AIRPORT_USER` - username to connect with - # `AIRPORT_DIR` - defaults to `~/airport`, directory to use + # `AIRPORT_HOST` - host to rsync to + # `AIRPORT_USER` - username to connect with + # `AIRPORT_DIR` - defaults to `~/airport`, directory to use + # `AIRPORT_SAFEOP` - 'safe operations' mode, which doesn't delete files set -euo pipefail @@ -47,6 +48,7 @@ HOST=''${AIRPORT_HOST:?"AIRPORT_HOST needs to be set"} USER=''${AIRPORT_USER:?"AIRPORT_USER needs to be set"} DIR=''${AIRPORT_DIR:-"$HOME/airport"} + SAFEOP=''${AIRPORT_SAFEOP:-1} [ "$#" -eq 0 ] && die "FATAL: expected exactly 1 argument, $# provided" @@ -58,15 +60,18 @@ bin_exists "rsync" || die "FATAL: couldn't find rsync" + opts=(-au --stats --info=progress2) + [ $SAFEOP ] || opts+=(--delete-after) + case "$1" in send) delay "Airport will run 'rsync -au' to $DIR to SEND" - rsync -au --stats --info=progress2 --mkpath $DIR/ $USER@$HOST:airport + rsync ''${opts[@]} --mkpath $DIR/ $USER@$HOST:airport ;; recv) delay "Airport will run 'rsync -au' to $DIR to RECV" - rsync -au --stats --info=progress2 $USER@$HOST:airport/ $DIR + rsync ''${opts[@]} $USER@$HOST:airport/ $DIR ;; configure) -- cgit 1.4.1