-
Notifications
You must be signed in to change notification settings - Fork 0
/
instantplayer.sh
91 lines (80 loc) · 2.89 KB
/
instantplayer.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
### TODO:
### * sudoers
# enable pulse audio network remote-access
if gconftool-2 -g /system/pulseaudio/modules/remote-access/enabled | grep "No value set"; then
gconftool-2 -t bool -s /system/pulseaudio/modules/remote-access/enabled true
pulseaudio -k && pulseaudio --start
PA_NETWORK_PREVIOUS=false
else
PA_NETWORK_PREVIOUS=$(gconftool-2 -g /system/pulseaudio/modules/remote-access/enabled)
fi
gconftool-2 -t bool -s /system/pulseaudio/modules/remote-access/enabled true
# create passwd and group lines for the container
cat /etc/passwd > /tmp/passwd
echo $(getent passwd $(whoami)) >> /tmp/passwd
cat /etc/group > /tmp/group
echo $(getent group $(id -g $(whoami))) >> /tmp/group
# check for nvidia graphics
if hash nvidia-docker 2>/dev/null; then
DOCKER_BINARY='nvidia-docker'
else
DOCKER_BINARY='docker'
fi
# define options as array
OPTIONS=(
"$DOCKER_BINARY"
'run'
'--rm'
'-it'
'-v /tmp/.X11-unix:/tmp/.X11-unix'
'-e DISPLAY'
'--device=/dev/dri:/dev/dri'
'--device=/dev/snd'
"-e PULSE_SERVER=tcp:$(ip -f inet addr show docker0 | grep -Po 'inet \K[\d.]+'):4713"
"-v $HOME:$HOME"
"-u=$(id -u $(whoami)):$(id -g $(whoami))"
'-v /tmp:/tmp'
'-v /tmp/passwd:/etc/passwd'
'-v /tmp/group:/etc/group'
'-v /usr/share/themes:/usr/share/themes'
'-v /usr/share/gtk-engines:/usr/share/gtk-engines'
'-v /usr/share/icons:/usr/share/icons'
)
# parse additional args
if [ $# -gt 0 ]; then
# if someone wants a bash prompt
if [ "$1" = "/bin/bash" ]; then
# coloring the prompt of the container
OPTIONS+=('-e PS1=\[\033[41;37m\]docker_instantreality\[\033[0m\]:\w\$ ')
OPTIONS+=('--entrypoint=/bin/bash')
shift
# for people with creative .bashrc, we add --norc
set -- "--norc" "$@"
# elif [ "$1" = "sav" ]; then
# OPTIONS+=('--entrypoint=/usr/local/bin/sav')
# shift
else
OPTIONS+=('--entrypoint=/usr/local/bin/InstantPlayer')
fi
fi
# for better desktop integration
if [ -d /usr/lib/x86_64-linux-gnu/gtk-2.0 ]; then
OPTIONS+=('-v /usr/lib/x86_64-linux-gnu/gtk-2.0:/usr/lib/x86_64-linux-gnu/gtk-2.0')
OPTIONS+=('-v /usr/lib/x86_64-linux-gnu/gtk-3.0:/usr/lib/x86_64-linux-gnu/gtk-3.0')
elif [ -d /usr/lib/gtk-2.0 ]; then
OPTIONS+=('-v /usr/lib/gtk-2.0:/usr/lib/x86_64-linux-gnu/gtk-2.0')
OPTIONS+=('-v /usr/lib/gtk-3.0:/usr/lib/x86_64-linux-gnu/gtk-3.0')
fi
# choose the image
if hash nvidia-docker 2>/dev/null; then
OPTIONS+=('nexero/instantplayer:trusty-nvidia')
else
OPTIONS+=('nexero/instantplayer:trusty-intel')
fi
# launch with dbus-launch, because otherwise there won't be a dbus-connection and the app may complain about that
dbus-launch sudo ${OPTIONS[@]} $@
# restore pulseaudio setting
gconftool-2 -t bool -s /system/pulseaudio/modules/remote-access/enabled $PA_NETWORK_PREVIOUS
# cleanup
rm /tmp/{passwd,group}