From 3f54b4b19cbe8f08f780d00d747828096bc2c10a Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Mon, 9 Nov 2015 18:11:54 +0100 Subject: [PATCH] metrics: add tunneling script for access via SSH License: MIT Signed-off-by: Lars Gierth --- solarnet/metrics.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 solarnet/metrics.sh diff --git a/solarnet/metrics.sh b/solarnet/metrics.sh new file mode 100755 index 0000000..544eaab --- /dev/null +++ b/solarnet/metrics.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +proxy=root@earth.i.ipfs.io +target=metrics.i.ipfs.io:80 +localport=8080 + +usage() { + echo "usage: $0 [] [] []" + echo "proxy through to a target " + exit 1 +} + +die() { + echo "error: $@" + exit 1 +} + +if [ $# -ge 1 ]; then + proxy="$1" +fi + +if [ $# -ge 2 ]; then + target="$2" +fi + +if [ $# -ge 3 ]; then + localport="$3" +fi + +# set up local url +localurl="http://localhost:$localport" + +# setup proxy +echo "setting up proxy through $proxy" +ssh "$proxy" -N -L "$localport:$target" & +sid="$!" + +kill -0 "$!" || die "failed to log into $proxy" + +cleanup() { + echo "stopping..." + kill "$sid" + exit +} + +trap cleanup INT TERM + +# use proxy +echo "proxying $localurl -> $proxy -> $target" + +# open +echo "open $localurl" +open "$localurl" + +# wait forever +echo "enter ^C to stop" +tail -f /dev/null