#!/bin/bash
# ipc-inject.sh - Injector for toolbox IPC PubSub messages
-# Copyright (C) 2022 Matthias Kruk
+# Copyright (C) 2022-2023 Matthias Kruk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
main() {
local proto
local endpoint
+ local endpoint_name
local message
declare -gA hooks
declare -gi signal_received
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" \
+ opt_add_arg "p" "proto" "v" "ipc" \
"The IPC protocol to inject" \
'^u?ipc$'
+ opt_add_arg "e" "endpoint" "v" "" \
+ "The IPC endpoint to use"
if ! opt_parse "$@"; then
return 1
return 1
fi
- if ! endpoint=$(ipc_endpoint_open); then
+ endpoint_name=$(opt_get "endpoint")
+ if ! endpoint=$(ipc_endpoint_open "$endpoint_name"); then
return 1
fi
#!/bin/bash
# ipc-sshtunnel.sh - Tunnel toolbox PubSub IPC messages over SSH
-# Copyright (C) 2022 Matthias Kruk
+# Copyright (C) 2022-2023 Matthias Kruk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
establish_ipc_tunnel() {
local direction="$1"
local remote="$2"
- local -n ref_topics="$3"
- local -n ref_tap_hooks="$4"
- local -n ref_inject_hooks="$5"
+ local endpoint="$3"
+ local -n ref_topics="$4"
+ local -n ref_tap_hooks="$5"
+ local -n ref_inject_hooks="$6"
local proto
local topic
proto=$(opt_get "proto")
tap_args=(
- --proto "$proto"
+ --proto "$proto"
+ --endpoint "$endpoint"
)
inject_args=(
- --proto "$proto"
+ --proto "$proto"
+ --endpoint "$endpoint"
)
for topic in "${ref_topics[@]}"; do
spawn_tunnel() {
local direction="$1"
local remote="$2"
- local ref_topics="$3"
- local ref_tap_hooks="$4"
- local ref_inject_hooks="$5"
+ local endpoint="$3"
+ local ref_topics="$4"
+ local ref_tap_hooks="$5"
+ local ref_inject_hooks="$6"
local -i tunnel
- if tunnel=$(establish_ipc_tunnel "$direction" "$remote" "$ref_topics" "$ref_tap_hooks" "$ref_inject_hooks"); then
+ if tunnel=$(establish_ipc_tunnel "$direction" "$remote" "$endpoint" "$ref_topics" "$ref_tap_hooks" "$ref_inject_hooks"); then
while inst_running && process_is_running "$tunnel"; do
sleep 5
done
declare -gxa tap_hooks
declare -gxa inject_hooks
local remote
+ local endpoint
input_topics=()
output_topics=()
return 1
fi
+ endpoint="ipc-sshtunnel-$HOSTNAME-$$"
remote=$(opt_get "remote")
- if ! inst_start spawn_tunnel "in" "$remote" input_topics tap_hooks inject_hooks ||
- ! inst_start spawn_tunnel "out" "$remote" output_topics tap_hooks inject_hooks; then
+ if ! inst_start spawn_tunnel "in" "$remote" "$endpoint" input_topics tap_hooks inject_hooks ||
+ ! inst_start spawn_tunnel "out" "$remote" "$endpoint" output_topics tap_hooks inject_hooks; then
return 1
fi
#!/bin/bash
# ipc-tap.sh - Interceptor for toolbox IPC PubSub messages
-# Copyright (C) 2022 Matthias Kruk
+# Copyright (C) 2022-2023 Matthias Kruk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
}
tap_topics() {
- local topics=("$@")
+ local endpoint_name="$1"
+ local topics=("${@:2}")
local endpoint
local topic
err=0
signal_received=0
- if ! endpoint=$(ipc_endpoint_open); then
+ if ! endpoint=$(ipc_endpoint_open "$endpoint_name"); then
return 1
fi
}
main() {
+ local endpoint
local proto
local topics
declare -gA hooks
topics=()
- opt_add_arg "t" "topic" "rv" "" \
+ opt_add_arg "t" "topic" "rv" "" \
"A topic to tap into" \
'' \
add_topic
- opt_add_arg "k" "hook" "v" "" \
+ opt_add_arg "k" "hook" "v" "" \
"Hook to execute upon receipt" \
'^[^:]+:.+$' \
add_hook
- opt_add_arg "p" "proto" "v" "ipc" \
+ opt_add_arg "p" "proto" "v" "ipc" \
"The IPC protocol to tap" \
'^u?ipc$'
+ opt_add_arg "e" "endpoint" "v" "" \
+ "The IPC endpoint to use"
if ! opt_parse "$@"; then
return 1
return 1
fi
- if ! tap_topics "${topics[@]}"; then
+ endpoint=$(opt_get "endpoint")
+ if ! tap_topics "$endpoint" "${topics[@]}"; then
return 1
fi