diff options
author | Case Duckworth | 2020-04-12 12:02:48 -0500 |
---|---|---|
committer | Case Duckworth | 2020-04-12 12:02:48 -0500 |
commit | 2bbb32c0e5a649db7bdabc18a16ee9569da61d78 (patch) | |
tree | da4f57ab8032a62f90a27b0fe3b9ec2d062f6b84 | |
download | mrgrctrnl-2bbb32c0e5a649db7bdabc18a16ee9569da61d78.tar.gz mrgrctrnl-2bbb32c0e5a649db7bdabc18a16ee9569da61d78.zip |
Initial commit
-rw-r--r-- | README.md | 50 | ||||
-rw-r--r-- | mrgrc.jpg | bin | 0 -> 61830 bytes | |||
-rwxr-xr-x | mrgrctrnl | 64 |
3 files changed, 114 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..870922e --- /dev/null +++ b/README.md | |||
@@ -0,0 +1,50 @@ | |||
1 | # MERGIRC TURNEL | ||
2 | |||
3 | a configurable ssh tunneler that I use for IRC | ||
4 | |||
5 | this is a small shell script that'll set up | ||
6 | an IRC tunnel between hosts that you can configure | ||
7 | using a file. | ||
8 | |||
9 | When you run mrgrctrnl, | ||
10 | it'll automagically tunnel the hosts | ||
11 | and let you sign into IRC on your own computer. | ||
12 | Yay! | ||
13 | |||
14 | ## Why | ||
15 | |||
16 | I like running weechat from my computer but have it connected to others. | ||
17 | For example, I like to stay connected to tilde.town's IRC from my laptop. | ||
18 | According to instructions from | ||
19 | [~nick](https://tilde.town/~nick/sshtunnel.html), | ||
20 | you can just set up an SSH tunnel. | ||
21 | But I have multiple servers! | ||
22 | So I made this script. | ||
23 | |||
24 | ### Why the stupid name? | ||
25 | |||
26 | ![gersbermps meme edited so she's holding terminals](mrgrc.jpg "ermahgerd") | ||
27 | |||
28 | ## Config file | ||
29 | |||
30 | The config file is located at `$XDG_CONFIG_HOME/mrgrctrnl/config`. | ||
31 | Each row is an ssh tunnel to run, | ||
32 | with whitespace-separeted fields. | ||
33 | A `#` begins a comment that goes to the end of the line. | ||
34 | |||
35 | ``` | ||
36 | # machine user local remote | ||
37 | example.com ted localhost:6989 localhost:6667 | ||
38 | ``` | ||
39 | |||
40 | ## Requirements | ||
41 | |||
42 | - POSIX environment | ||
43 | - ssh | ||
44 | |||
45 | ## Install | ||
46 | |||
47 | ```` | ||
48 | $ make clean | ||
49 | # make install | ||
50 | ``` | ||
diff --git a/mrgrc.jpg b/mrgrc.jpg new file mode 100644 index 0000000..fc9e9d1 --- /dev/null +++ b/mrgrc.jpg | |||
Binary files differ | |||
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 | |||
8 | usage() | ||
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 | |||
22 | die() | ||
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 | |||
33 | config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config" | ||
34 | pidf=/tmp/mrgrctrnl.pid | ||
35 | |||
36 | while getopts hc: opt; do | ||
37 | case "$opt" in | ||
38 | h) usage ;; | ||
39 | c) config="$OPTARG" ;; | ||
40 | \?) usage 2 ;; | ||
41 | *) usage 2 ;; | ||
42 | esac | ||
43 | done | ||
44 | shift "$((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 | |||
54 | while read -r machine user local remote | ||
55 | do | ||
56 | while : | ||
57 | do | ||
58 | ssh -N "$user@$machine" -L "$local:$remote" | ||
59 | echo "$!" >> "$pidf" | ||
60 | sleep 3 | ||
61 | done & | ||
62 | done < "$config" | ||
63 | |||
64 | wait | ||