Compare commits

...

2 Commits

Author SHA1 Message Date
xiongdian.me
4e5dfce9fb riot: support multiple remotes, delimiter=comma (,) 2023-11-03 18:55:24 +08:00
xiongdian.me
c5841e4aaa riot: proxy delimiter from comma (,) to slash (/) 2023-11-03 18:34:55 +08:00

View File

@ -91,24 +91,25 @@ 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
while [[ -n $remote ]]; do
local server=${remote%%,*}
remote=${remote#*,}
local server=${remote%%/*}
remote=${remote#*/}
get_server_meta "$server"
if [[ -n "$RET_JUMP_SERVER" ]]; then
jump_servers="$jump_servers${jump_servers:+,}$RET_JUMP_SERVER"
@ -212,12 +213,14 @@ router() {
print_help
exit
fi
parse_remote "$1"
IFS=',' read -ra remotes <<< "$1"
for remote in "${remotes[@]}"; do
if [[ -z "$remote" ]]; then
continue
fi
parse_remote "$remote"
case $2 in
-h|--help)
print_help
exit
;;
ssh|"" )
run_ssh ssh "${@:3}"
;;
@ -241,6 +244,7 @@ router() {
fmt_fatal "unknown command: $2"
;;
esac
done
}
router "${GOT_OPTS[@]}"