From 2e16c5e914b7f48c7bc5d6ad8b858d4cc67d5326 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Thu, 25 Jul 2024 23:09:57 +0200 Subject: [PATCH] rsyncrepo script: allow optionally supplying target name The `rsyncrepo` and `rsynchydra` scripts now support an optional 3rd argument to define the target name on the host instead of auto-determining it from the basename. This is important for syncing local directories of varying names all to the same `fc-nixos` target for dev checkouts on VMs. --- home/scripts/reporsync.nix | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/home/scripts/reporsync.nix b/home/scripts/reporsync.nix index dfdaa29..c5fcb4c 100644 --- a/home/scripts/reporsync.nix +++ b/home/scripts/reporsync.nix @@ -29,7 +29,7 @@ JUMPHOST="$DEFAULT_JUMPHOST" ;; ?) - echo "rsyncrepo [-J] [-j ] " + echo "rsyncrepo [-J] [-j ] [target dir name]" return 1 ;; esac @@ -40,6 +40,7 @@ RR_FROM="$1" RR_TO="$2" + RR_TARGET="$3" } _do_rsync() { @@ -57,8 +58,12 @@ echo "$OPTI" done - # we always sync /path/to/dir/ to hostname:dir - RR_DEST="''${2}:$(basename $(realpath "''${1}"))" + # If no $3 is specified, we sync /path/to/dir/ to hostname:dir + if [ -z "$3" ]; then + RR_DEST="''${2}:$(basename $(realpath "''${1}"))" + else + RR_DEST="''${2}:''${3}" + fi echo "Syncing ''${1} to ''${RR_DEST}…" @@ -69,11 +74,11 @@ rsyncrepo() { _parse_rsync_args "$@" # inherits parsed arguments through variables - _do_rsync "$RR_FROM" "$RR_TO" + _do_rsync "$RR_FROM" "$RR_TO" "$RR_TARGET" } rsynchydra() { _parse_rsync_args "$@" - _do_rsync "$RR_FROM" "hydra01" + _do_rsync "$RR_FROM" "hydra01" "$RR_TARGET" } ''