about summary refs log tree commit diff stats
path: root/mrgrctrnl
diff options
context:
space:
mode:
Diffstat (limited to 'mrgrctrnl')
-rwxr-xr-xmrgrctrnl64
1 files changed, 64 insertions, 0 deletions
diff --git a/mrgrctrnl b/mrgrctrnl new file mode 100755 index 0000000..8b6c10d --- /dev/null +++ b/mrgrctrnl
@@ -0,0 +1,64 @@
1#!/bin/sh
2# mrgrctrnl
3# configurable ssh tunneler
4# by Case Duckworth <acdw@acdw.net>
5# version 0.1
6# LICENSE: MIT
7
8usage()
9{
10 cat <<-END
11 mrgrctrnl: make magic ssh tunnels
12 usage: mrgrctrnl [-h] [-c CONF]
13
14 -h show this help
15 -c CONF use config file CONF.
16 . default: \$XDG_CONFIG_HOME/mrgrctrnl/config
17
18 END
19 exit "${1:-0}"
20}
21
22die()
23{
24 [ "$#" -eq 0 ] && exit 1
25 case "$1" in
26 0-9*) ec="$1"; shift ;;
27 *) ec=1 ;;
28 esac
29 printf '!!%s: %s\n' "mrgrctrnl" "$*"
30 exit "$ec"
31}
32
33config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config"
34pidf=/tmp/mrgrctrnl.pid
35
36while getopts hc: opt; do
37 case "$opt" in
38 h) usage ;;
39 c) config="$OPTARG" ;;
40 \?) usage 2 ;;
41 *) usage 2 ;;
42 esac
43done
44shift "$((OPTIND - 1))"
45
46[ -f "$config" ] || die "Need a config! Edit $config"
47[ -e "$pidf" ] && {
48 while read -r pid; do
49 kill "$pid"
50 done < "$pidf"
51 rm "$pidf"
52}
53
54while read -r machine user local remote
55do
56 while :
57 do
58 ssh -N "$user@$machine" -L "$local:$remote"
59 echo "$!" >> "$pidf"
60 sleep 3
61 done &
62done < "$config"
63
64wait