-
Notifications
You must be signed in to change notification settings - Fork 2
/
host
executable file
·39 lines (30 loc) · 1.1 KB
/
host
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
SERVER="${SERVER:-mumble.ugent.be}"
pairinguser="pairing@$SERVER"
set -e
for COMMAND in abduco socat ssh uuidgen dvtm; do
if ! command -v $COMMAND > /dev/null 2>&1; then
printf '%s found: no\n' "$COMMAND"
exit
fi
done
# Create a temporary directory for our sockets
umask 077
socketdir="$(mktemp -d)"
trap "rm -rf '$socketdir'" EXIT
# Invent a secret session name
session="$(uuidgen)"
read -p "Copy this session key and hit enter to start: $session" unused
# Create the session in which you'll host, in the background
SESSION_NAME="$session" SESSION_SOCKET="$socketdir/abduco" abduco -n "$socketdir/abduco"
# Create an SSH master connection in the background, to allow asking for passphrases
ssh -N -f -M -S "$socketdir/ssh" "$pairinguser"
# Connect our sessions socket to a remote socket over our existing ssh connection
socat unix:"$socketdir/abduco" exec:"ssh -S '$socketdir/ssh' '$pairinguser' 'host $session'" &
socatpid="$!"
# Attach to the session created earlier
abduco -a "$socketdir/abduco"
# Close in reverse order
kill "$socatpid" || true
ssh -O exit -S "$socketdir/ssh" "$pairinguser"
wait