]> git.corax.cc Git - toolbox/commitdiff
utils: Allow ipc-sshtunnel and friends to be used for uipc messages
authorMatthias Kruk <m@m10k.eu>
Thu, 9 Mar 2023 07:48:18 +0000 (16:48 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 9 Mar 2023 07:52:39 +0000 (16:52 +0900)
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.

utils/ipc-inject.sh
utils/ipc-sshtunnel.sh
utils/ipc-tap.sh

index df3c9baedea8a1bc5f8f8bf1f4d106672aaf0bd4..004e8293d8e34d3d102133dad5aef1b1925d32ea 100755 (executable)
@@ -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
 
index 09b4858e27d194d0d7676d05ae69d1cdbc904255..2e3f5689c70e18d49163775c7956b29e34b370fd 100755 (executable)
@@ -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
index 265c1d9100a9f00ed7d3d63c18d82d837f5688cc..452f0c6f35ebaca5821a6f3d3bf3876698bdc295 100755 (executable)
@@ -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