cli
[eostre.git] / meatviewer / client.sh
CommitLineData
c5bafd5b 1#!/bin/bash -xe
2
3function print_usage {
92877f88 4 set +x
c5bafd5b 5 echo \
6"
92877f88 7usage: $0 PORT REMOTE_PORT user@proxy
8 script that sets up a reverse ssh tunnel
c5bafd5b 9 PORT is the port that your techy needs access to. In general, for graphical issues use 5900 and for command-line issues use 22
92877f88 10 REMOTE_PORT is the port that you'll get on the proxy server, any number over 1000 works as long as you and your techy plug in the same number. This number gets used as a kind of identifier for your remote support session.
524da846 11 USER is just your username at the remote proxy machine, if left blank it is assumed to be the same as your username on your local machine
c5bafd5b 12"
92877f88 13 set -x
14 exit
c5bafd5b 15}
16
92877f88 17function get_techy_sshauth {
18 SSH_PUBKEY=$(curl http://$PROXY/$REMOTE_PORT) || GET_PUBKEY_OVER_HTTP_FAILED=true
19 if [ -n "$SSH_PUBKEY" ]; then GET_PUBKEY_OVER_HTTP_FAILED=true; fi
20 if [ "$GET_PUBKEY_OVER_HTTP_FAILED" -eq "true" ]; then
21 set -x
22 echo "Automatically fetching your support partner's SSH public key failed, please ask them for their public key and paste it in your terminal here:"
23 set +x
24 read -p ":>" SSH_PUBKEY
25 fi
26 set -x
27 echo "Adding your partner's SSH key to your authorized_keys, feel free to delete this line from your authorized_keys once this session is over"
28 set +x
29 echo $SSH_PUBKEY >> ~/.ssh/authorized_keys
30}
31
32if [ -n "$@" ]; then print_usage; fi
c5bafd5b 33
34PORT_TO_FORWARD=$1
35REMOTE_PORT=$2
524da846 36USER=${3:-$(whoami)}
92877f88 37PROXY=e9d.org
c5bafd5b 38
92877f88 39ssh -T -R $REMOTE_PORT:localhost:$PORT_TO_FORWARD $USER@$PROXY