about summary refs log tree commit diff
path: root/home/profiles
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2023-08-01 21:47:02 +0900
committersefidel <contact@sefidel.net>2023-08-01 21:50:20 +0900
commitc61ae865683f4f702984f6d09c309d3224cc9890 (patch)
treef8c8727a8686515c55efeabf08f5e042784c9fba /home/profiles
parent5dbed05ed5c106f411671edb52a35b053e5d6855 (diff)
downloadnixrc-c61ae865683f4f702984f6d09c309d3224cc9890.tar.gz
nixrc-c61ae865683f4f702984f6d09c309d3224cc9890.zip
feat(home/base): airport: delete files by default
Diffstat (limited to 'home/profiles')
-rwxr-xr-xhome/profiles/base/scripts/airport.nix15
1 files changed, 10 insertions, 5 deletions
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)