From 60bf635a0cc68b6a960e47f1bfdd8792b3d09cdd Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 18 Sep 2026 19:50:18 +0200 Subject: [PATCH] feat: add rscp function for rsyncing files to NAS datasets --- functions/rscp.fish | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 functions/rscp.fish diff --git a/functions/rscp.fish b/functions/rscp.fish new file mode 100644 index 0000000..adde257 --- /dev/null +++ b/functions/rscp.fish @@ -0,0 +1,55 @@ +function rscp + if test (count $argv) -lt 2 + echo "Usage: rscp SOURCE DESTINATION" + return 1 + end + + if not command -q rsync + echo "rscp: 'rsync' is not installed. Install it via your package manager." + return 1 + end + + set -l src $argv[1] + set -l dst $argv[2] + + # Mount <-> NAS dataset mapping (keep both lists in the same order) + set -l mounts /home/honney/mount/Media /home/honney/mount/Data /home/honney/mount/Ripping /home/honney/mount/Apps + set -l remotes NAS:/mnt/tank/Media NAS:/mnt/tank/Data NAS:/mnt/tank/Ripping NAS:/mnt/tank/Apps + + set -l src_remote 0 + set -l dst_remote 0 + + for i in (seq (count $mounts)) + if string match -q -- $mounts[$i] $src; or string match -q -- "$mounts[$i]/*" $src + set src (string replace -f -- $mounts[$i] $remotes[$i] -- $src) + set src_remote 1 + break + end + end + + for i in (seq (count $mounts)) + if string match -q -- $mounts[$i] $dst; or string match -q -- "$mounts[$i]/*" $dst + set dst (string replace -f -- $mounts[$i] $remotes[$i] -- $dst) + set dst_remote 1 + break + end + end + + if test $src_remote -eq 0 -a $dst_remote -eq 0 + echo "cp -av -- $src $dst" + command cp -av -- $src $dst + return $status + end + + # --no-perms: required - TrueNAS ZFS datasets use SMB ACLs and reject unix perms preservation + set -l opts -avh --no-perms --info=progress2 --partial + if test $dst_remote -eq 1 + set -a opts --rsync-path="sudo -n rsync" --chown=1000:0 + end + if test $src_remote -eq 1 + set -a opts --rsync-path="sudo -n rsync" + end + + echo rsync $opts -- $src $dst + command rsync $opts -- $src $dst +end