-
Notifications
You must be signed in to change notification settings - Fork 2
/
share
executable file
·47 lines (37 loc) · 1.24 KB
/
share
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
40
41
42
43
44
45
46
47
#!/bin/sh
SERVER="${SERVER:-Mumble}"
shareuser="felix@$SERVER"
set -e
for COMMAND in abduco socat ssh dvtm; do
if ! command -v $COMMAND > /dev/null 2>&1; then
printf '%s found: no\n' "$COMMAND"
exit
fi
done
if ! printf '%s' "$1" | grep '^[a-z0-9-]\+$'; then
echo 'Please provide an alphanumeric (and -) session name'
exit 1
fi
# Create a temporary directory for our sockets
umask 077
socketdir="$(mktemp -d)"
trap "rm -rf '$socketdir'" EXIT
# Create the session in which we'll teach, in the background
SESSION_NAME="$1" SESSION_SOCKET="$socketdir/abduco" abduco -n "$socketdir/abduco" dvtm
# Create an SSH master connection in the background, to allow asking for passphrases
ssh -N -f -M -S "$socketdir/ssh" "$shareuser"
# Connect our sessions socket to a remote file over our existing ssh connection
socat -u unix-connect:"$socketdir/abduco" exec:"ssh -S '$socketdir/ssh' '$shareuser' 'socat -u - create:/tmp/socks/$1,unlink-early,mode=777'" &
socatpid="$!"
# Keep 'resizing' our screen to resend the whole thing
while pkill -SIGWINCH dvtm; do
sleep 1
done &
resizepid="$!"
# Attach to the session created earlier
abduco -a "$socketdir/abduco"
# Close in reverse order
kill "$resizepid"
kill "$socatpid"
ssh -O exit -S "$socketdir/ssh" "$shareuser"
wait