From 2bbb32c0e5a649db7bdabc18a16ee9569da61d78 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 12 Apr 2020 12:02:48 -0500 Subject: Initial commit --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ mrgrc.jpg | Bin 0 -> 61830 bytes mrgrctrnl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 README.md create mode 100644 mrgrc.jpg create mode 100755 mrgrctrnl diff --git a/README.md b/README.md new file mode 100644 index 0000000..870922e --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# MERGIRC TURNEL + +a configurable ssh tunneler that I use for IRC + +this is a small shell script that'll set up +an IRC tunnel between hosts that you can configure +using a file. + +When you run mrgrctrnl, +it'll automagically tunnel the hosts +and let you sign into IRC on your own computer. +Yay! + +## Why + +I like running weechat from my computer but have it connected to others. +For example, I like to stay connected to tilde.town's IRC from my laptop. +According to instructions from +[~nick](https://tilde.town/~nick/sshtunnel.html), +you can just set up an SSH tunnel. +But I have multiple servers! +So I made this script. + +### Why the stupid name? + +![gersbermps meme edited so she's holding terminals](mrgrc.jpg "ermahgerd") + +## Config file + +The config file is located at `$XDG_CONFIG_HOME/mrgrctrnl/config`. +Each row is an ssh tunnel to run, +with whitespace-separeted fields. +A `#` begins a comment that goes to the end of the line. + +``` +# machine user local remote +example.com ted localhost:6989 localhost:6667 +``` + +## Requirements + +- POSIX environment +- ssh + +## Install + +```` +$ make clean +# make install +``` diff --git a/mrgrc.jpg b/mrgrc.jpg new file mode 100644 index 0000000..fc9e9d1 Binary files /dev/null and b/mrgrc.jpg differ diff --git a/mrgrctrnl b/mrgrctrnl new file mode 100755 index 0000000..8b6c10d --- /dev/null +++ b/mrgrctrnl @@ -0,0 +1,64 @@ +#!/bin/sh +# mrgrctrnl +# configurable ssh tunneler +# by Case Duckworth +# version 0.1 +# LICENSE: MIT + +usage() +{ + cat <<-END + mrgrctrnl: make magic ssh tunnels + usage: mrgrctrnl [-h] [-c CONF] + + -h show this help + -c CONF use config file CONF. + . default: \$XDG_CONFIG_HOME/mrgrctrnl/config + + END + exit "${1:-0}" +} + +die() +{ + [ "$#" -eq 0 ] && exit 1 + case "$1" in + 0-9*) ec="$1"; shift ;; + *) ec=1 ;; + esac + printf '!!%s: %s\n' "mrgrctrnl" "$*" + exit "$ec" +} + +config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config" +pidf=/tmp/mrgrctrnl.pid + +while getopts hc: opt; do + case "$opt" in + h) usage ;; + c) config="$OPTARG" ;; + \?) usage 2 ;; + *) usage 2 ;; + esac +done +shift "$((OPTIND - 1))" + +[ -f "$config" ] || die "Need a config! Edit $config" +[ -e "$pidf" ] && { + while read -r pid; do + kill "$pid" + done < "$pidf" + rm "$pidf" +} + +while read -r machine user local remote +do + while : + do + ssh -N "$user@$machine" -L "$local:$remote" + echo "$!" >> "$pidf" + sleep 3 + done & +done < "$config" + +wait -- cgit 1.4.1-21-gabe81