From: Matthias Kruk Date: Thu, 9 Mar 2023 07:48:18 +0000 (+0900) Subject: utils: Allow ipc-sshtunnel and friends to be used for uipc messages X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=6f7817b84f8d9a9aa9d907a02b5bdb825305d089;p=toolbox utils: Allow ipc-sshtunnel and friends to be used for uipc messages The scripts for tunneling IPC messages over SSH cannot be used with uipc messages, even though the two modules share the same interface. This commit modifies the scripts ipc-sshtunnel, ipc-inject, and ipc-tap, so that they can handle uipc as well as ipc messages by adding a command line option for specifying the ipc protocol to be tunneled. --- diff --git a/utils/ipc-inject.sh b/utils/ipc-inject.sh index df3c9ba..004e829 100755 --- a/utils/ipc-inject.sh +++ b/utils/ipc-inject.sh @@ -121,6 +121,7 @@ handle_message() { } main() { + local proto local endpoint local message declare -gA hooks @@ -132,15 +133,23 @@ main() { signal_received=0 - opt_add_arg "k" "hook" "v" "" \ + opt_add_arg "k" "hook" "v" "" \ "Command for handling hook data" \ '^[^:]+:.*$' \ add_hook + opt_add_arg "p" "proto" "v" "ipc" \ + "The IPC protocol to inject" \ + '^u?ipc$' if ! opt_parse "$@"; then return 1 fi + proto=$(opt_get "proto") + if ! include "$proto"; then + return 1 + fi + if ! endpoint=$(ipc_endpoint_open); then return 1 fi @@ -163,7 +172,7 @@ main() { exit 1 fi - if ! include "log" "opt" "ipc"; then + if ! include "log" "opt"; then exit 1 fi diff --git a/utils/ipc-sshtunnel.sh b/utils/ipc-sshtunnel.sh index 09b4858..2e3f568 100755 --- a/utils/ipc-sshtunnel.sh +++ b/utils/ipc-sshtunnel.sh @@ -49,11 +49,20 @@ establish_ipc_tunnel() { local -n ref_tap_hooks="$4" local -n ref_inject_hooks="$5" + local proto local topic local hook local tap_args local inject_args + proto=$(opt_get "proto") + tap_args=( + --proto "$proto" + ) + inject_args=( + --proto "$proto" + ) + for topic in "${ref_topics[@]}"; do tap_args+=(--topic "$topic") done @@ -124,15 +133,17 @@ main() { tap_hooks=() inject_hooks=() - opt_add_arg "i" "input-topic" "v" "" "Topic to relay from the remote side (may be used more than once)" \ + opt_add_arg "i" "input-topic" "v" "" "Topic to relay from the remote side (may be used more than once)" \ "" _array_add - opt_add_arg "o" "output-topic" "v" "" "Topic to relay to the remote side (may be used more than once)" \ + opt_add_arg "o" "output-topic" "v" "" "Topic to relay to the remote side (may be used more than once)" \ "" _array_add - opt_add_arg "T" "tap-hook" "v" "" "Hook to pass to ipc-tap" \ + opt_add_arg "T" "tap-hook" "v" "" "Hook to pass to ipc-tap" \ "" _array_add - opt_add_arg "I" "inject-hook" "v" "" "Hook to pass to ipc-inject" \ + opt_add_arg "I" "inject-hook" "v" "" "Hook to pass to ipc-inject" \ "" _array_add - opt_add_arg "r" "remote" "rv" "" "Address of the remote side" + opt_add_arg "r" "remote" "rv" "" "Address of the remote side" + opt_add_arg "p" "proto" "v" "ipc" "The IPC protocol to tunnel" \ + '^u?ipc$' if ! opt_parse "$@"; then return 1 diff --git a/utils/ipc-tap.sh b/utils/ipc-tap.sh index 265c1d9..452f0c6 100755 --- a/utils/ipc-tap.sh +++ b/utils/ipc-tap.sh @@ -136,6 +136,7 @@ tap_topics() { } main() { + local proto local topics declare -gA hooks @@ -149,11 +150,19 @@ main() { "Hook to execute upon receipt" \ '^[^:]+:.+$' \ add_hook + opt_add_arg "p" "proto" "v" "ipc" \ + "The IPC protocol to tap" \ + '^u?ipc$' if ! opt_parse "$@"; then return 1 fi + proto=$(opt_get "proto") + if ! include "$proto"; then + return 1 + fi + if ! tap_topics "${topics[@]}"; then return 1 fi @@ -166,7 +175,7 @@ main() { exit 1 fi - if ! include "log" "opt" "ipc" "json"; then + if ! include "log" "opt" "json"; then exit 1 fi