diff options
-rwxr-xr-x | mrgrctrnl | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/mrgrctrnl b/mrgrctrnl index d51be58..af29269 100755 --- a/mrgrctrnl +++ b/mrgrctrnl | |||
@@ -35,12 +35,15 @@ die() { | |||
35 | 35 | ||
36 | demolish_tunnels() { | 36 | demolish_tunnels() { |
37 | printf '%s...' "Demolishing tunnels" | 37 | printf '%s...' "Demolishing tunnels" |
38 | while read -r pid; do | 38 | if [ -f "$pidf" ]; then |
39 | [ -z "$pid" ] && continue | 39 | while read -r pid; do |
40 | kill "$pid" 2>/dev/null | 40 | [ -z "$pid" ] && continue |
41 | done <"$pidf" | 41 | kill "$pid" 2>/dev/null |
42 | rm "$pidf" | 42 | done <"$pidf" |
43 | sleep 3 | 43 | rm "$pidf" |
44 | else | ||
45 | pkill -x ssh | ||
46 | fi | ||
44 | printf '%s.\n' "Done" | 47 | printf '%s.\n' "Done" |
45 | } | 48 | } |
46 | 49 | ||
@@ -48,7 +51,7 @@ config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config" | |||
48 | pidf=/tmp/mrgrctrnl.pid | 51 | pidf=/tmp/mrgrctrnl.pid |
49 | dry_run=false | 52 | dry_run=false |
50 | 53 | ||
51 | while getopts hc:dk opt; do | 54 | while getopts hc:dkr opt; do |
52 | case "$opt" in | 55 | case "$opt" in |
53 | h) usage ;; | 56 | h) usage ;; |
54 | c) config="$OPTARG" ;; | 57 | c) config="$OPTARG" ;; |
@@ -58,6 +61,11 @@ while getopts hc:dk opt; do | |||
58 | pkill -x mrgrctrnl | 61 | pkill -x mrgrctrnl |
59 | exit | 62 | exit |
60 | ;; | 63 | ;; |
64 | r) | ||
65 | demolish_tunnels | ||
66 | exec mrgrctrnl | ||
67 | exit | ||
68 | ;; | ||
61 | \?) usage 2 ;; | 69 | \?) usage 2 ;; |
62 | *) usage 2 ;; | 70 | *) usage 2 ;; |
63 | esac | 71 | esac |
@@ -83,11 +91,11 @@ awk '{sub(/#.*$/,"");print}' "$config" | | |||
83 | 91 | ||
84 | echo ssh "$@" | 92 | echo ssh "$@" |
85 | 93 | ||
94 | touch "$pidf" | ||
86 | "$dry_run" || { | 95 | "$dry_run" || { |
87 | while :; do | 96 | while [ -f "$pidf" ]; do |
88 | ssh "$@" | 97 | ssh "$@" || break |
89 | echo "$!" >>"$pidf" | 98 | echo "$!" >>"$pidf" |
90 | sleep 5 | ||
91 | done & | 99 | done & |
92 | } | 100 | } |
93 | done | 101 | done |