-
Notifications
You must be signed in to change notification settings - Fork 3
/
xlaunch.sh
executable file
·74 lines (67 loc) · 1.84 KB
/
xlaunch.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
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# This script may be used to launch a docker container with docker options that:
# * enable running X applications inside the container if the host has an
# active X-windows session
# * map certain devices if present on the host
# * map volumes
test -z "$1" && echo "USAGE: $0 (docker opts) <docker image> (command)" && exit 1
####################################
# XAUTH
####################################
# enable xauth if the host appears to have active X session
# reference: http://stackoverflow.com/questions/91368/checking-from-shell-script-if-a-directory-contains-files
if (test ! -d /tmp/.X11-unix || (find /tmp/.X11-unix/ -maxdepth 0 -empty | read v))
then
echo "$0: not enabling xauth"
else
echo "$0: enabling xauth"
XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
chmod 644 $XAUTH
_OPTS_XAUTH="
-e DISPLAY=$DISPLAY \
-e XAUTHORITY=$XAUTH \
-v $XSOCK:$XSOCK:rw \
-v $XAUTH:$XAUTH:rw \
"
fi
####################################
# VOLUMES
####################################
_PWD="$(readlink -f $(dirname $0))"
_OPTS_VOLUMES="
"
####################################
# DEVICES
####################################
_OPTS_DEVICES=""
for x in \
/dev/dri/card* \
/dev/loop* \
/dev/nvidia* \
/dev/snd/seq \
/dev/ttyUSB* \
/dev/video*
do
test -e $x && _OPTS_DEVICES="$_OPTS_DEVICES --device=$x:$x"
done
####################################
# CAPS
####################################
#_OPTS_CAPS="
# --privileged
# --cap-add SYS_ADMIN
# --cap-add MKNOD
#"
####################################
# DOCKER RUN
####################################
docker run -it \
${_OPTS_CAPS} \
${_OPTS_XAUTH} \
${_OPTS_VOLUMES} \
${_OPTS_DEVICES} \
$@
exit 0