diff options
author | Case Duckworth | 2020-04-12 12:13:19 -0500 |
---|---|---|
committer | Case Duckworth | 2020-04-12 12:13:19 -0500 |
commit | 1f5c56d2de26395ebaec3f8086004b0387273ced (patch) | |
tree | 3109140b7b235bc60add382584e44a0ac9f0ccd4 | |
parent | Ignore comments (diff) | |
download | mrgrctrnl-1f5c56d2de26395ebaec3f8086004b0387273ced.tar.gz mrgrctrnl-1f5c56d2de26395ebaec3f8086004b0387273ced.zip |
Add dry_run flag
-rwxr-xr-x | mrgrctrnl | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/mrgrctrnl b/mrgrctrnl index 131894e..4f090d1 100755 --- a/mrgrctrnl +++ b/mrgrctrnl | |||
@@ -9,10 +9,11 @@ usage() | |||
9 | { | 9 | { |
10 | cat <<-END | 10 | cat <<-END |
11 | mrgrctrnl: make magic ssh tunnels | 11 | mrgrctrnl: make magic ssh tunnels |
12 | usage: mrgrctrnl [-h] [-c CONF] | 12 | usage: mrgrctrnl [-h] [-c CONF] [-d] |
13 | 13 | ||
14 | -h show this help | 14 | -h show this help |
15 | -c CONF use config file CONF. | 15 | -c CONF use config file CONF. |
16 | -d do a dry run: don't actually tunnel | ||
16 | . default: \$XDG_CONFIG_HOME/mrgrctrnl/config | 17 | . default: \$XDG_CONFIG_HOME/mrgrctrnl/config |
17 | 18 | ||
18 | END | 19 | END |
@@ -32,11 +33,13 @@ die() | |||
32 | 33 | ||
33 | config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config" | 34 | config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config" |
34 | pidf=/tmp/mrgrctrnl.pid | 35 | pidf=/tmp/mrgrctrnl.pid |
36 | dry_run=false; | ||
35 | 37 | ||
36 | while getopts hc: opt; do | 38 | while getopts hc:d opt; do |
37 | case "$opt" in | 39 | case "$opt" in |
38 | h) usage ;; | 40 | h) usage ;; |
39 | c) config="$OPTARG" ;; | 41 | c) config="$OPTARG" ;; |
42 | d) dry_run=true ;; | ||
40 | \?) usage 2 ;; | 43 | \?) usage 2 ;; |
41 | *) usage 2 ;; | 44 | *) usage 2 ;; |
42 | esac | 45 | esac |
@@ -44,7 +47,7 @@ done | |||
44 | shift "$((OPTIND - 1))" | 47 | shift "$((OPTIND - 1))" |
45 | 48 | ||
46 | [ -f "$config" ] || die "Need a config! Edit $config" | 49 | [ -f "$config" ] || die "Need a config! Edit $config" |
47 | [ -e "$pidf" ] && { | 50 | [ -e "$pidf" ] && ! "$dry_run" && { |
48 | while read -r pid; do | 51 | while read -r pid; do |
49 | kill "$pid" | 52 | kill "$pid" |
50 | done < "$pidf" | 53 | done < "$pidf" |
@@ -54,6 +57,13 @@ shift "$((OPTIND - 1))" | |||
54 | awk '{sub(/#.*$/,"");print}' "$config" | | 57 | awk '{sub(/#.*$/,"");print}' "$config" | |
55 | while read -r machine user local remote | 58 | while read -r machine user local remote |
56 | do | 59 | do |
60 | [ -z "$machine" ] || [ -z "$user" ] || | ||
61 | [ -z "$local" ] || [ -z "$remote" ] && | ||
62 | continue | ||
63 | |||
64 | echo ssh -N "$user@$machine" -L "$local:$remote" | ||
65 | |||
66 | $dry_run || | ||
57 | while : | 67 | while : |
58 | do | 68 | do |
59 | ssh -N "$user@$machine" -L "$local:$remote" | 69 | ssh -N "$user@$machine" -L "$local:$remote" |