diff options
author | Andrew Cady <d@jerkface.net> | 2023-08-27 11:55:32 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-08-27 11:55:32 -0400 |
commit | 17e91005ccedc355cb213fda0cbbe674a847ea85 (patch) | |
tree | 49644eff7c5d88ea9e84e1ad530688a03d54c595 | |
parent | b01d26fcc596f46f20207f17636331f7916bb0ac (diff) |
YES
-rw-r--r-- | src/rpc.bash | 28 | ||||
-rw-r--r-- | src/rpc.main.bash | 47 | ||||
-rw-r--r-- | src/rpc.main2.bash | 30 |
3 files changed, 53 insertions, 52 deletions
diff --git a/src/rpc.bash b/src/rpc.bash index d13942b..853120f 100644 --- a/src/rpc.bash +++ b/src/rpc.bash | |||
@@ -73,18 +73,29 @@ __bashrpc__run_function_simple() | |||
73 | "$@" | 73 | "$@" |
74 | } | 74 | } |
75 | 75 | ||
76 | __bashrpc__notty_stage1() | ||
77 | { | ||
78 | [ "$1" ] && | ||
79 | read -N"$1" -r && # Read script from stdin, munges REPLY | ||
80 | shift && # Prepare "$@" for script execution context. | ||
81 | eval "unset REPLY; $REPLY" # Unset munged REPLY in exec context | ||
82 | } | ||
83 | |||
76 | __bashrpc__remote_run_stage1_notty() | 84 | __bashrpc__remote_run_stage1_notty() |
77 | { | 85 | { |
86 | stage1_source=$( | ||
87 | declare -f __bashrpc__notty_stage1 | | ||
88 | sed -Ene 's/^ {4}//p' | ||
89 | ) | ||
78 | stage2_source=$1 | 90 | stage2_source=$1 |
79 | shift | 91 | shift |
80 | { | 92 | { |
81 | printf '%s' "$stage2_source" | 93 | printf '%s' "$stage2_source" |
82 | cat | 94 | cat |
83 | } | | 95 | } | |
84 | __bashrpc__run_function_simple \ | 96 | __bashrpc__remote_run_script \ |
85 | __bashrpc__eval_stdin \ | 97 | "$stage1_source" "${#stage2_source}" \ |
86 | "${#stage2_source}" \ | 98 | "$@" |
87 | "$@" | ||
88 | } | 99 | } |
89 | 100 | ||
90 | __bashrpc__read_stdin() | 101 | __bashrpc__read_stdin() |
@@ -96,7 +107,7 @@ __bashrpc__read_stdin() | |||
96 | __bashrpc__tty_stage1() | 107 | __bashrpc__tty_stage1() |
97 | { | 108 | { |
98 | local SET_TERM="$1" | 109 | local SET_TERM="$1" |
99 | local prelude="shift;${BASH_RPC_TRACE_REMOTE:+ set -x;}" | 110 | local PRELUDE="shift;${BASH_RPC_TRACE_REMOTE:+ set -x;}" |
100 | __bashrpc__read_stdin <<END | 111 | __bashrpc__read_stdin <<END |
101 | # We saved stage2 in TERM. | 112 | # We saved stage2 in TERM. |
102 | # Store it in parameter 1: | 113 | # Store it in parameter 1: |
@@ -104,10 +115,7 @@ set -- "\$TERM" "\$@" | |||
104 | # Restore original TERM: | 115 | # Restore original TERM: |
105 | TERM=${SET_TERM@Q} | 116 | TERM=${SET_TERM@Q} |
106 | # Run stage2: | 117 | # Run stage2: |
107 | source <( | 118 | source <(printf '%s\n%s' ${PRELUDE@Q} "\$1") |
108 | printf '%s\n' "$prelude" | ||
109 | printf '%s' "\$1" | ||
110 | ) | ||
111 | END | 119 | END |
112 | printf '%s' "$REPLY" | 120 | printf '%s' "$REPLY" |
113 | } | 121 | } |
@@ -115,7 +123,7 @@ END | |||
115 | __bashrpc__remote_run_stage1_tty() | 123 | __bashrpc__remote_run_stage1_tty() |
116 | { | 124 | { |
117 | stage2_source=$1 | 125 | stage2_source=$1 |
118 | stage1_source=$(__bashrpc__tty_stage1 "$TERM") | 126 | stage1_source=$(__bashrpc__tty_stage1 "$TERM" | grep -v '^#') |
119 | shift | 127 | shift |
120 | ( | 128 | ( |
121 | # printf 'DEBUG2:<%s>\n' "${BASH_RPC_SSH_OPTIONS[@]}" >&2 | 129 | # printf 'DEBUG2:<%s>\n' "${BASH_RPC_SSH_OPTIONS[@]}" >&2 |
diff --git a/src/rpc.main.bash b/src/rpc.main.bash index c34296e..21dc071 100644 --- a/src/rpc.main.bash +++ b/src/rpc.main.bash | |||
@@ -1,46 +1,10 @@ | |||
1 | #!/usr/bin/bash -e | 1 | #!/bin/bash |
2 | set -e | 2 | set -e |
3 | set -o pipefail | 3 | set -o pipefail |
4 | |||
5 | case "$0" in | 4 | case "$0" in |
6 | [^/]* ) PATH=$(realpath -e "$(dirname "$BASH_SOURCE")"):$PATH ;; | 5 | [^/]* ) PATH=$(realpath -e "$(dirname "$BASH_SOURCE")"):$PATH ;; |
7 | esac | 6 | esac |
8 | 7 | source rpc.bash | |
9 | . rpc.bash | ||
10 | |||
11 | our_main() | ||
12 | { | ||
13 | REMOTE_DEST=localhost | ||
14 | # main2 "$@" | ||
15 | main1 "$@" | ||
16 | } | ||
17 | |||
18 | main1() | ||
19 | { | ||
20 | # local -a BASH_RPC_SSH_OPTIONS=('-4' '-6' '-4') | ||
21 | with_ssh_options -4 -6 -4 -- \ | ||
22 | remote_run_function fudge "$@" | ||
23 | } | ||
24 | |||
25 | main2() | ||
26 | { | ||
27 | funcs=$(find_local_only_functions "$@" </dev/null | xargs) | ||
28 | [ ! "$funcs" ] || printf 'Local-only functions (main2): %s\n' "$funcs" >&2 | ||
29 | } | ||
30 | |||
31 | find_local_only_functions() | ||
32 | { | ||
33 | remote_commands=($(remote_run_function all_commands | sort -u)) | ||
34 | intersection <(extract_words < "$BASH_SOURCE") \ | ||
35 | <(difference <(all_commands) \ | ||
36 | <(printf '%s\n' "${remote_commands[@]}")) | ||
37 | } | ||
38 | |||
39 | all_commands() | ||
40 | { | ||
41 | : main2 | ||
42 | compgen -A command | sort -u | ||
43 | } | ||
44 | 8 | ||
45 | gudge() | 9 | gudge() |
46 | { | 10 | { |
@@ -48,12 +12,11 @@ gudge() | |||
48 | topic=${*@Q} | 12 | topic=${*@Q} |
49 | echo "Don't argue with me about ${topic:-punctuation}." | 13 | echo "Don't argue with me about ${topic:-punctuation}." |
50 | } | 14 | } |
51 | |||
52 | fudge() | 15 | fudge() |
53 | { | 16 | { |
54 | read -p "[$(hostname)] Name? " && gudge "$@" | 17 | read -p "[$(hostname)] Name? " && gudge "$@" |
55 | exit | 18 | exit |
56 | } | 19 | } |
57 | 20 | with_ssh_options -4 -- \ | |
58 | our_main "$@" | 21 | remote_run_function \ |
59 | 22 | fudge "$@" | |
diff --git a/src/rpc.main2.bash b/src/rpc.main2.bash new file mode 100644 index 0000000..ad5e15b --- /dev/null +++ b/src/rpc.main2.bash | |||
@@ -0,0 +1,30 @@ | |||
1 | #!/bin/bash | ||
2 | set -e | ||
3 | set -o pipefail | ||
4 | case "$0" in | ||
5 | [^/]* ) PATH=$(realpath -e "$(dirname "$BASH_SOURCE")"):$PATH ;; | ||
6 | esac | ||
7 | source rpc.bash | ||
8 | |||
9 | main() | ||
10 | { | ||
11 | funcs=$(find_local_only_functions "$@" </dev/null | xargs) | ||
12 | [ ! "$funcs" ] || printf 'Local-only functions (main2): %s\n' "$funcs" >&2 | ||
13 | } | ||
14 | |||
15 | find_local_only_functions() | ||
16 | { | ||
17 | remote_commands=($(remote_run_function all_commands | sort -u)) | ||
18 | printf 'remote commands: %d\n' ${#remote_commands[@]} >&2 | ||
19 | intersection <(extract_words < "$BASH_SOURCE") \ | ||
20 | <(difference <(all_commands) \ | ||
21 | <(printf '%s\n' "${remote_commands[@]}")) | ||
22 | } | ||
23 | |||
24 | all_commands() | ||
25 | { | ||
26 | : main | ||
27 | compgen -A command | sort -u | ||
28 | } | ||
29 | |||
30 | main "$@" | ||