Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
metrics: add tunneling script for access via SSH
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Lars Gierth <[email protected]>
  • Loading branch information
Lars Gierth committed Nov 9, 2015
1 parent e80ea37 commit 3f54b4b
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions solarnet/metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

[email protected]
target=metrics.i.ipfs.io:80
localport=8080

usage() {
echo "usage: $0 [<proxy>] [<target>] [<localport>]"
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

0 comments on commit 3f54b4b

Please sign in to comment.