about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xmrgrctrnl16
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
33config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config" 34config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config"
34pidf=/tmp/mrgrctrnl.pid 35pidf=/tmp/mrgrctrnl.pid
36dry_run=false;
35 37
36while getopts hc: opt; do 38while 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
44shift "$((OPTIND - 1))" 47shift "$((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))"
54awk '{sub(/#.*$/,"");print}' "$config" | 57awk '{sub(/#.*$/,"");print}' "$config" |
55while read -r machine user local remote 58while read -r machine user local remote
56do 59do
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"