-
Notifications
You must be signed in to change notification settings - Fork 10
/
remote-virtualgl.sh
executable file
·62 lines (53 loc) · 1.8 KB
/
remote-virtualgl.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
############################################################
# Copyright (c) 2015 Jonathan Yantis #
# Released under the MIT license #
############################################################
# #
# Connect to remote SSH server and and launch our container
# then reconnect to that container and run VirtualGL over
# X-forwarding. Then shut down the container when done.
#
# Usage:
# remote-virtualgl.sh username hostname
#
# Example:
# remote-virtualgl.sh user hermes
# #
############################################################
# Exit the script if any statements returns a non true (0) value.
# set -e
# Exit the script on any uninitialized variables.
set -u
# Exit the script if the user didn't specify at least two arguments.
if [ "$#" -ne 2 ]; then
echo "Error: You need to specifiy the host and user"
exit 1
fi
USER_NAME=$2
HOST_NAME=$2
# Pick a random port as we might have multiple things running.
PORT=$[ 32767 + $[ RANDOM % 32767 ] ]
# Connect to the server and launch our container.
ssh -o StrictHostKeyChecking=no \
$USER_NAME@$HOST_NAME -tt << EOF
sudo docker run \
--privileged \
-d \
-v /home/user/.ssh/authorized_keys:/authorized_keys:ro \
-h docker \
-p 49154:22 \
-v /home/$USER_NAME/.ssh/authorized_keys:/authorized_keys:ro \
-p $PORT:22 \
yantis/virtualgl
exit
EOF
# Now that is is launched go ahead and connect to our new server
vglconnect -Y \
-o ConnectionAttempts=255 \
-o StrictHostKeyChecking=no \
docker@$HOST_NAME -p $PORT
# Since we are done politely kill root to force a container shutdown.
ssh -o StrictHostKeyChecking=no \
docker@$HOST_NAME -p $PORT \
-t sudo pkill -INT -u root