From 4e5dfce9fb615da2aa0a0c5cbfc139d3a032d8a8 Mon Sep 17 00:00:00 2001 From: "xiongdian.me" Date: Fri, 3 Nov 2023 18:55:24 +0800 Subject: [PATCH] riot: support multiple remotes, delimiter=comma (,) --- scripts/riot | 84 +++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/scripts/riot b/scripts/riot index 0d72028..9827750 100755 --- a/scripts/riot +++ b/scripts/riot @@ -91,18 +91,19 @@ get_server_meta() { esac } -# remote setting, including jump servers -# will be called only once -# provides: -SERVER="" -TRUST_SERVER=1 -PORT="" # optional -USERNAME="" # optional -SSH_OPTIONS="" # optional -if [[ "$RIOT_TRUST_CLIENT" == "1" ]]; then - SSH_OPTIONS='-o ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes' -fi parse_remote() { + # remote setting, including jump servers + # called for every remote + # provides: + SERVER="" + TRUST_SERVER=1 + PORT="" # optional + USERNAME="" # optional + SSH_OPTIONS="" # optional + if [[ "$RIOT_TRUST_CLIENT" == "1" ]]; then + SSH_OPTIONS='-o ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes' + fi + # handle input local remote="$1" local jump_servers="" # loop for jump servers @@ -212,35 +213,38 @@ router() { print_help exit fi - parse_remote "$1" - case $2 in - -h|--help) - print_help - exit - ;; - ssh|"" ) - run_ssh ssh "${@:3}" - ;; - zssh ) - run_ssh zssh - ;; - sftp ) - run_ssh sftp - ;; - sshl ) - test -n "$3" || fmt_fatal "no target address provided" - run_sshl "$3" - ;; - scp ) - test -n "$3" || fmt_fatal "no source path specified" - test -n "$4" || fmt_fatal "no destination path specified" - run_scp "$3" "$4" - ;; - * ) - print_help - fmt_fatal "unknown command: $2" - ;; - esac + + IFS=',' read -ra remotes <<< "$1" + for remote in "${remotes[@]}"; do + if [[ -z "$remote" ]]; then + continue + fi + parse_remote "$remote" + case $2 in + ssh|"" ) + run_ssh ssh "${@:3}" + ;; + zssh ) + run_ssh zssh + ;; + sftp ) + run_ssh sftp + ;; + sshl ) + test -n "$3" || fmt_fatal "no target address provided" + run_sshl "$3" + ;; + scp ) + test -n "$3" || fmt_fatal "no source path specified" + test -n "$4" || fmt_fatal "no destination path specified" + run_scp "$3" "$4" + ;; + * ) + print_help + fmt_fatal "unknown command: $2" + ;; + esac + done } router "${GOT_OPTS[@]}"