diff options
author | Case Duckworth | 2020-05-08 08:52:26 -0500 |
---|---|---|
committer | Case Duckworth | 2020-05-08 08:52:26 -0500 |
commit | 2bed591dbe9324e91e59f2835d683f3ea2aa1d21 (patch) | |
tree | b09e57c1a9315f1e51b8e6765f0a16823e4de1a0 | |
parent | Add burgercontrol recipe (diff) | |
download | mrgrctrnl-2bed591dbe9324e91e59f2835d683f3ea2aa1d21.tar.gz mrgrctrnl-2bed591dbe9324e91e59f2835d683f3ea2aa1d21.zip |
Fix -r flag
-rwxr-xr-x | mrgrctrnl | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/mrgrctrnl b/mrgrctrnl index b516596..aa6016c 100755 --- a/mrgrctrnl +++ b/mrgrctrnl | |||
@@ -12,6 +12,7 @@ main() { | |||
12 | _RUN=true | 12 | _RUN=true |
13 | _LOG=true | 13 | _LOG=true |
14 | _USE_CONFIG=true | 14 | _USE_CONFIG=true |
15 | _RESTART=false | ||
15 | # options | 16 | # options |
16 | __CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/$PRGN/config" | 17 | __CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/$PRGN/config" |
17 | __PIDF="/tmp/$PRGN.pid" | 18 | __PIDF="/tmp/$PRGN.pid" |
@@ -19,9 +20,6 @@ main() { | |||
19 | __SSH="$(command -v autossh || command -v ssh)" | 20 | __SSH="$(command -v autossh || command -v ssh)" |
20 | __SSH_ARGS="-nT -N \"\$user@\$machine\" -L \"\$local:\$remote\"" | 21 | __SSH_ARGS="-nT -N \"\$user@\$machine\" -L \"\$local:\$remote\"" |
21 | 22 | ||
22 | # save command invocation (for -r) | ||
23 | printf '%s %s\n' "$PRGN" "$*" >"$__CMDF" | ||
24 | |||
25 | # parse options | 23 | # parse options |
26 | while getopts hkrnqSAc:s: OPT; do | 24 | while getopts hkrnqSAc:s: OPT; do |
27 | case "$OPT" in | 25 | case "$OPT" in |
@@ -34,10 +32,7 @@ main() { | |||
34 | pkill -x "$PRGN" | 32 | pkill -x "$PRGN" |
35 | exit "$?" | 33 | exit "$?" |
36 | ;; | 34 | ;; |
37 | r) | 35 | r) _RESTART=true ;; |
38 | untunnel | ||
39 | exec "$(cat "$__CMDF")" | ||
40 | ;; | ||
41 | n) _RUN=false ;; | 36 | n) _RUN=false ;; |
42 | q) _LOG=false ;; | 37 | q) _LOG=false ;; |
43 | S) __SSH='ssh' ;; | 38 | S) __SSH='ssh' ;; |
@@ -52,6 +47,14 @@ main() { | |||
52 | done | 47 | done |
53 | shift $((OPTIND - 1)) | 48 | shift $((OPTIND - 1)) |
54 | 49 | ||
50 | # save command invocation (for -r) | ||
51 | if $_RESTART; then | ||
52 | untunnel | ||
53 | exec "$PRGN" $(cat "$__CMDF") | ||
54 | else | ||
55 | printf '%s\n' "$*" >"$__CMDF" | ||
56 | fi | ||
57 | |||
55 | # make sure ssh is installed | 58 | # make sure ssh is installed |
56 | if ! command -v "$__SSH" >/dev/null; then | 59 | if ! command -v "$__SSH" >/dev/null; then |
57 | log "Not installed: $__SSH" | 60 | log "Not installed: $__SSH" |