2024-03-26 16:47:35 +01:00
|
|
|
{ pkgs, lib, ... }:
|
2024-03-17 19:18:53 +01:00
|
|
|
''
|
|
|
|
# rsync -rlptzv --progress --delete --exclude=.git --exclude=.vscode --exclude=result --exclude=channels/ /Users/os/src/fc.qemu os@hydra01:
|
|
|
|
# rsync -rlptzv --progress --rsh="ssh -J fcio-whq-jump" --delete --exclude=.git --exclude=.vscode --exclude=result --exclude=channels/ /Users/os/src/fc-nixos/ os@patty:fc-nixos/
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_JUMPHOST="fcio-whq-jump"
|
|
|
|
|
|
|
|
_parse_rsync_args() {
|
|
|
|
# reset pre-defined variables that are read and manipulated throughout this function
|
|
|
|
unset JUMPHOST
|
|
|
|
# arrays are bash or zsh specific
|
|
|
|
RSYNC_OPTS=("-rlptzv" "--progress" "--delete" "--exclude=.git" "--exclude=.vscode" "--exclude=result" "--exclude=channels/" "--exclude=.mypy_cache")
|
|
|
|
|
|
|
|
while getopts ':Jj:' OPT; do
|
|
|
|
case $OPT in
|
|
|
|
j)
|
|
|
|
if [ -n "$JUMPHOST" ]; then
|
|
|
|
echo "-j and -J are conflicting arguments" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
JUMPHOST="$OPTARG"
|
|
|
|
;;
|
|
|
|
J)
|
|
|
|
if [ -n "$JUMPHOST" ]; then
|
|
|
|
echo "-j and -J are conflicting arguments" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
JUMPHOST="$DEFAULT_JUMPHOST"
|
|
|
|
;;
|
|
|
|
?)
|
2024-07-25 23:09:57 +02:00
|
|
|
echo "rsyncrepo [-J] [-j <jumphost>] <directory> <hostname> [target dir name]"
|
2024-03-17 19:18:53 +01:00
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# trim CLI parameters
|
|
|
|
shift "$(($OPTIND -1))"
|
|
|
|
|
|
|
|
RR_FROM="$1"
|
|
|
|
RR_TO="$2"
|
2024-07-25 23:09:57 +02:00
|
|
|
RR_TARGET="$3"
|
2024-03-17 19:18:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_do_rsync() {
|
|
|
|
# parameter check
|
|
|
|
if [ -z "$1" ] || [ -z "$2" ]; then
|
|
|
|
echo "Missing arguments, required: <directory> <hostname>" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$JUMPHOST" ]; then
|
2024-03-26 16:47:35 +01:00
|
|
|
RSYNC_OPTS+=("--rsh=${lib.getExe pkgs.openssh} -J ''${JUMPHOST}")
|
2024-03-17 19:18:53 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
for OPTI in "''${RSYNC_OPTS[@]}"; do
|
|
|
|
echo "$OPTI"
|
|
|
|
done
|
|
|
|
|
2024-07-25 23:09:57 +02:00
|
|
|
# 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
|
2024-03-17 19:18:53 +01:00
|
|
|
|
|
|
|
echo "Syncing ''${1} to ''${RR_DEST}…"
|
|
|
|
|
|
|
|
# ensure trailing slash for src to avoid recreating directory
|
2024-03-26 16:47:35 +01:00
|
|
|
${lib.getExe pkgs.rsync} "''${RSYNC_OPTS[@]}" "''${1}/" "''${RR_DEST}"
|
2024-03-17 19:18:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rsyncrepo() {
|
|
|
|
_parse_rsync_args "$@"
|
|
|
|
# inherits parsed arguments through variables
|
2024-07-25 23:09:57 +02:00
|
|
|
_do_rsync "$RR_FROM" "$RR_TO" "$RR_TARGET"
|
2024-03-17 19:18:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rsynchydra() {
|
|
|
|
_parse_rsync_args "$@"
|
2024-07-25 23:09:57 +02:00
|
|
|
_do_rsync "$RR_FROM" "hydra01" "$RR_TARGET"
|
2024-03-17 19:18:53 +01:00
|
|
|
}
|
|
|
|
''
|