-
Notifications
You must be signed in to change notification settings - Fork 379
/
Copy pathx11docker
4298 lines (3962 loc) · 206 KB
/
x11docker
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /bin/bash
# x11docker
# Run GUI applications and desktop environments in docker on a separate X server or Wayland compositor.
# Circumvents common X security leaks.
# Provides GPU acceleration and pulseaudio sound.
# Restrictes docker container privileges with 'docker run --cap-drop=ALL --security-opt=no-new-privileges'
# Container user is same as host user to avoid root in container.
# Type 'x11docker --help' or scroll down to read usage information.
# https://github.com/mviereck/x11docker
Version="3.9.1.4"
changelog() {
# 12.01.2017 V3.9.1.4 --help: some usage updates
# 10.01.2017 --xorg: create virtual framebuffer if no monitor is connected (headless server setup)
# --xpra: note that 2.1.x series is more stable than 2.2.x series
# 06.01.2017 create $Cacherootfolder/Xenv.latest with latest X environment variables for easier custom access
# --verbose --systemd: hide error messages: Failed to add fd to store | Failed to set invocation ID | Failed to reset devices.list
# --systemd: set global environment XAUTHORITY
# 04.01.2017 V3.9.1.3 --dbus-daemon: set xhost +SI:localuser:$USER, needed for deepin
# 03.01.2017 bugfix --systemd: global XAUTHORITY setting was wrong, removed at all
# faster startup of pulseaudio, no sleep 1
# bugfix: pull terminal did not appear if running from terminal
# create fake homedir and softlinks to sharedirs in CMD.sh, base is /fakehome now
# 29.12.2017 extension XTEST: more restrictive defaults
# 28.12.2017 V3.9.1.2 --sudouser: root gets password 'x11docker', too
# check environment variables in image and set them in x11docker.CMD.sh. Allows PATH of x11docker/trinity again.
# bugfix parsing host XAUTHORITY if running from gksu
# cut image command at '#'
# 28.12.2017 V3.9.1.1 bugfix --systemd: directly share X socket as systemd can have issues with soft links
# 25.12.2017 V3.9.1 run in detached mode, drop mess of nohup/setsid/script
# 24.12.2017 --dbusdaemon: dropped consolekit, not really useful
# --dbusdaemon: switch only for --tini/--none. Always run daemon for --systemd --openrc --runit
# 22.12.2017 --systemd: create /sys/fs/cgroup/systemd if missing on host
# --sys-admin: deprecated thanks to --tmpfs=/run/lock
# containersetup.sh collects most former 'docker exec' commands from dockerrc
# 21.12.2017 V3.9.0.5 add capability DAC_OVERRIDE if user switching is allowed -> needed to change /etc/sudoers if ro
# bugfix: only create XDG_RUNTIME_DIR if not already existing
# --systemd: adding --tmpfs=/run/lock allows to drop --sys-admin !
# 20.12.2017 V3.9.0.4 docker run --workdir=/tmp, avoids issues with WORKDIR in image (seen with lirios/unstable)
# 19.12.2017 bugfix --dbus: check for dbus-launch in x11docker.CMD.sh, not in dockerrc on host
# 18.12.2017 changes to satisfy lirios:
# add docker run -ti
# run docker command with script -c to provide fake tty
# change /tmp/fakehome to /home/fakehome
# 17.12.2017 V3.9.0.3 switched back to /tmp/fakehome to avoid CHOWN and issues with --sharedir
# drop --cap-add CHOWN
# bugfix --sudouser, failed to start
# --sharedir: without --home[dir], create softlinks to /tmp/fakehome
# --home: avoid conflict with --sharedir=$HOME, mount as $HOME/$(basename $HOME)
# 16.12.2017 only chown $Benutzerhome if --home[dir] is not used. Change non-writeable error in warning only
# --hostdisplay: warning if host has no own cookie
# avoid grey edge with Xwayland, Xaxis must be dividable by 8
# 16.12.2017 V3.9.0.2 /etc/sudoers[.d/]: replace completly to avoid possible evil image setups
# --cap-add CHOWN as default to allow /home/$Benutzer with --sharedir
# 16.12.2017 V3.9.0.1 bugfix: --systemd: do not set $HOME globally, root may write into it
# use /home/$Benutzer instead of /tmp/fakehome
# 15.12.2017 V3.9.0 /etc/shadow: disable possible root password
# --dbusdaemon: new option to run dbus system daemon and consolekit in container
# 14.12.2017 re-checked capabilities for init systems
# --systemd: set environment globally, especially DISPLAY for deepin is needed
# --systemd: set xhost+SI:localuser:$Benutzer as XAUTHORITY seems to be ignored
# 12.12.2017 /tmp/.ICE-unix created in dockerrc, root owned with 1777, needed for SESSION_MANAGER
# --rw: deprecated, root file system is always r/w now due to 'docker exec' in dockerrc
# 10.12.2017 (V3.8.1) bugfix Ubuntu: avoid Wayland backend for Weston due to MIR issue #19
# (V3.8.1) --xorg: change Xorg to X. X is setuid wrapper for Xorg on Ubuntu 14.04
# (V3.8.1) +iglx removed from X options, not present in older versions of X, and maybe security issue.
# 09.12.2017 create user in dockerrc with 'docker exec' instead of using createuser.sh
# --xorg: removed +iglx from options, not supported on older X versions
# 07.12.2017 --openrc: new option for init system OpenRC in container
# --sharecgroup: new option to share /sys/fs/cgroup. default for --systemd.
# 06.12.2017 create /var/lib/dbus in dockerrc to avoid dbus errors with init systems
# show image name and display in weston windows
# bugfix --runit: add SYS_BOOT even with --cap-default
# 04.12.2017 V3.8.0 --sudouser: create user with docker run options instead of createuser script
# --sudouser: create /etc/sudoers.d/$Benutzer with docker exec in dockerrc
# 03.12.2017 --sudouser: create /etc/sudoers.d/$Benutzer instead of adding groups wheel and sudo
# createuser.sh: check for useradd, if missing use adduser (fits fedora and alpine/busybox as well)
# 02.12.2017 --runit: new option for init system runit
# --init: new option for init system tini (default now, docker run option --init)
# --no-init: new option to run image command as PID 1 (has been default before x11docker 3.8)
# 01.12.2017 --sys-admin: new option for --cap-add=SYS_ADMIN. Needed for systemd in debian based images.
# 28.11.2017 --sudouser, --systemd: set needed capabilities only instead of --cap-default
# --xpra --hostuser: create /run/user/$Hostuseruid if missing
# $Sharefolder/stdout+sterr: chmod 666 to allow access with --user
# container user password: x11docker (creating volume /etc/shadow)
# 25.11.2017 init system tini as default with 'docker run --init'
# --systemd: unprivileged systemd in container
# 23.11.2017 --exe and --xonly: regard --home and --homedir, --user and --hostuser
# --wayland: new option to auto-setup Wayland environment
# -W is now --wayland instead of --weston, -T for --weston now
# check pids before calling mywatch()
# 22.11.2017 bugfix: --hostdisplay --gpu needs trusted cookies
# colored logfile output
# 19.11.2017 bugfix in createuser.sh: adduser failed with fedora based images, use useradd and usermod instead
# 18.11.2017 bugfix: --pw=gksu: avoid wrong docker startup error message, use nohup in dockerrc
# 17.11.2017 --verbose: green colored output for logfile titles and verbose() lines
# 16.11.2017 set env DISPLAY XAUTHORITY and WAYLAND_DISPLAY in x1docker.CMD.sh as systemd eats them otherwise
# --systemd: new option to run systemd as PID1 in container and image command as a service
# use docker run option --tmpfs for /tmp, /var/tmp and /run instead of --volume=/tmp
# --sudouser: instead of empty password, user name is password now
# changed container share folder /tmp/x11docker to /x11docker to avoid issues with --tmpfs /tmp
# 11.11.2017 V3.7.2 allow rw with --volume=/var/tmp, needed for trinity
# 09.11.2017 bugfix for su on console: exec </dev/tty
# 06.11.2017 --nxagent: removed xhost startup workaround
# $Hostxenv: removed custom environment
# 05.11.2017 --nxagent: shift+F11 toggles fullscreen
# --nxagent on Mageia: only show warning about seamless mode instead of disabling it
# 03.11.2017 V3.7.1 bugfix for gksudo and lxsudo
# read host cookie with xauth if XAUTHORITY is empty, can happen with xdm
# --nxagent on Mageia: no seamless mode
# 02.11.2017 Ubuntu 16.04: bugfix for --xpra (must not set --webcam=no)
# 01.11.2017 replaced while/sleep loops with watch
# 31.10.2017 bugfix for weston and kwin on konsole, terminal for password prompt failed
# alertbox(): regard $DISPLAY, use $Anyterminal otherwise to support Wayland
# weston.ini: keyboard config setting on console
# fedora: show alert for --ipc/--trusted due to missing extension security
# 30.10.2017 V3.7.0 new option --alsa; use -wm for --xephyr and the likes; support more terminals and message dialogs
# 30.10.2017 V3.7.0 auto-choose window manager in --xephyr/--xorg/--weston-xwayland/--kwin-xwayland/--xwayland except --desktop is set
# 29.10.2017 --alsa: new option for ALSA sound
# changed content of variable $Xserver to X server option names itself
# 28.10.2017 --kwin-xwayland: set keyboard layout
# --kwin-native: deprecated, too much trouble, but less use
# 27.10.2017 extended terminal list for password prompt/docker pull
# --xhost: always disabling with no_xhost(), afterwards setting --xhost
# bugfix --weston/--weston-xwayland: set backend in compositor command, weston's autodetection can fail
# bugfix --kwin/--kwin-xwayland: set backend in compositor command, weston's autodetection can fail
# 25.10.2017 new function alertbox, outsourced from error(). yad, kaptain, kdialog, gxmessage, xterm: additional messagebox tools
# 25.10.2017 V3.6.3.9 show error messages regardless of --silent
# change "sudo" to "sudo -E", needed for OpenSUSE
# code cleanup, some improved messages
# 25.10.2017 V3.6.3.8 fedora: set --ipc and --trusted for --hostdisplay only
# 25.10.2017 V3.6.3.7 bugfix --hostdisplay on fedora: use host cookie, custom cookie is rejected
# 24.10.2017 V3.6.3.6 --wmlist: new option to retrieve list of window managers, used by x11docker-gui
# --gpu: improved support in autochoosing mode
# disabled note of xpra keyboard shortcuts, takes too long
# hardcoded xpra environment variables, parsing 'xpra showconfig' takes too long
# bugfix for --pw=sudo, issue with setsid
# 24.10.2017 V3.6.3.5 bugfix xpra with host user root: set environment variables
# dbus-launch for konsole and terminator, needed in dockerrc
# 23.10.2017 V3.6.3.4 add /usr/sbin to PATH, needed on mageia for ip
# bugfix --pw=sudo: 'setsid sudo' fails, must use 'sudo setsid'
# 23.10.2017 V3.6.3.3 removed experimental Code
# bugfix for --wm as root in xinitrc
# 23.10.2017 V3.6.3.2 remove debugging 'set -x' in xinitrc
# 23.10.2017 V3.6.3.1 bugfix: don't use su $USER in xinitrc
# 20.10.2017 split X server command with \backslash in multiple lines
# 20.10.2017 V3.6.3 new option --no-internet; adjustments for CentOS/RHEL, Arch and Manjaro
# 10.10.2017 V3.6.2 new option --xfishtank; better SELinux support; --scale and --size for --xorg
# 15.08.2017 V3.6.1 new options --stdout and --stderr; support stdin
# 12.08.2017 V3.6 allow root to start x11docker, use $(logname) for X server and as container user
# 17.05.2017 V3.5 hardening container security (--cap-drop=ALL), improved user handling (--user)
:
}
todo() {
# deepin: check dockerfile again, dde-session-daemon is no longer running
# BUG: --pulseaudio: stopping container with pulseaudio disables sound of other containers, too. Seems to be an pulseaudio bug. Check moduleid.
# headless server: check if xrandr framebuffer works now
# check issues with xpra 2.2
# --xorg: getty and autologin to avoid Xwrapper.config changes?
# gnome3 based desktop failing due to gnome bugs: pantheon budgie gnome3
# --nothing: do no show error message on fast exit
# check detached mode on mageia
# --systemd: try to avoid xhost +SI:localuser:$Benutzer
# check Xorg version for +iglx, check security implications, maybe option --iglx?
# GTK3 in Wayland: --dbus once worked with $Dbusdaemon=yes
# --wayland --user/--hostuser: wayland socket access denied
# check all FIXME
# --nxagent 3.5.0: Mageia 6: seamless mode fails
# check out possibilities to allow 'sudo docker' directly again.
# new option --printer: xpra printer forwarding?
# xpra: --file-transfer? How to set folder?
# --xpra-xwayland, xdummy-xwayland: use kwin-wayland as fallback for missing weston?
# fedora: SElinux issue: '--security-opt label=type:container_runtime_t': need more restrictive setting
# https://unix.stackexchange.com/questions/386767/selinux-and-docker-allow-access-to-x-unix-socket-in-tmp-x11-unix
# multimonitor support for --scale and --size
# check current multimonitor behaviour for weston on tty
# --xdummy --gpu on tty allows real resolutions only
# --xorg: check custom systemd start of X #7
# check X in container #7
# some tests with Xephyrglamor=no
### BUG collection: x11docker bugs:
# BUG check whether VT is not in use with --xorg/--xpra/--xdummy, bug if accidently using vt that is already in use
### BUG collection: non x11docker bugs
# BUG Xwayland does not always sit at 0:0 on multiple outputs.
# bugreport: https://bugzilla.redhat.com/show_bug.cgi?id=1498665
# BUG nxagent with x11docker/lxde: segmentation fault of lxpanel with --userns-remap. bug in nxagent, lxpanel or x11docker?
# BUG --kwin*: wrong fullscreen and crashes in gnome-wayland, strange in weston, WAYLAND_DISPLAY="" does not help, probably bug in kwin
# BUG scale>1 Xwayland in Weston is too large (Xwayland bug), rendering issues on tty (switching scaled/unscaled Xwayland on keyboard/mouse events)
# bugreport: https://bugzilla.redhat.com/show_bug.cgi?id=1498669
# BUG x11docker-gui in weston freezes weston in combo boxes. Weston bug ? QT3/4 bug?
# BUG debian bug report lightdm/sddm contra gdm, dm can crash on tty switch if multiple graphical sessions are running
:
}
usage() { # --help: show usage information
echo "
x11docker: Run GUI applications and desktop environments in docker.
* No dependencies in docker images
Focus on security:
* Avoids X security leaks using additional X servers.
* Container user is same as host user to avoid root in container.
* Default docker container capabilities are dropped.
Optional features:
* Hardware acceleration for OpenGL
* Pulseaudio and ALSA sound
* Clipboard sharing
* Persistent home folders
* Wayland support
* Init system support (systemd, openrc, runit, tini)
Usage:
To run a docker image with new X server (auto-choosing X server):
x11docker [OPTIONS] IMAGE [COMMAND]
x11docker [OPTIONS] -- "'"[DOCKER_RUN_OPTIONS]"'" IMAGE [COMMAND [ARG1 ARG2 ...]]
To run a host application on a new X server:
x11docker [OPTIONS] --exe COMMAND
x11docker [OPTIONS] --exe -- COMMAND [ARG1 ARG2 ...]
To run only a new empty X server:
x11docker [OPTIONS]
Dependencies on host:
Depending on chosen options, x11docker needs some packages to be installed.
It will check for them on startup and show messages if some are missing.
List of possible needed packages:
* most recommended to allow security and convenience:
xpra Xephyr xauth xrandr
* advanced GPU support:
weston Xwayland xdotool
* less important:
xclip pulseaudio kwin_wayland nxagent xdpyinfo Xvfb
* least important:
xserver-xorg-legacy xserver-xorg-video-dummy xfishtank
xdg-desktop-icon xdg-icon-resource unzip
Dependencies in image:
Doesn't have dependencies inside of docker images, except for
options --gpu and --pulseaudio, see below at option descriptions.
Options:
--help display this message and exit.
-e, --exe execute host application on new X server (no docker).
--xonly only create empty X server.
Basic settings: (especially influencing auto choosing X server)
-d, --desktop Indicate desktop environment in image.
-W, --wayland Set up a wayland environment. (Some QT5 apps also need
option --dbus, some GTK3 apps must run without --dbus.)
-w, --wm COMMAND Host window manager to use for single applications in
nested X server options like --xephyr.
To autodetect a host wm, use --wm=auto or short: -wm
To set default autodetected window manager:
update-alternatives --config x-window-manager
-g, --gpu Hardware accelerated OpenGL rendering. Shares files in
/dev/dri. Works best with open source drivers installed
on host and OpenGL/Mesa in image. Closed source drivers
need to be the very same on host and in image.
Degrades container isolation. Container access to GPU.
Shared folders:
-m, --home Share a host folder ~/x11docker/imagename as home folder
in container (to store persistent data).
--homedir DIR Specify custom host folder DIR for option --home.
--sharedir DIR Share host folder (or file) DIR with r/w access.
(can be specified multiple times for multiple folders).
Clipboard and sound options:
-c, --clipboard Share clipboard between X servers (works best with xpra.
Most other X servers need xclip to be installed).
-p, --pulseaudio Sound with pulseaudio over tcp. Degrades isolation.
Needs 'pulseaudio' on host and in image.
--alsa Sound with ALSA. Shares devices in /dev/snd. You can
define desired sound card with: --env ALSA_CARD=cardname
Degrades isolation. Container access to sound hardware.
X server options:
--auto Auto choose X server for docker applications (default).
(Regards options --desktop, --gpu, --wayland and --wm).
-a, --xpra Use xpra to show application windows on host display.
(Needs 'xpra' on host. Get it from www.xpra.org.
With option --desktop xpra runs in nested desktop mode.)
-y, --xephyr Use nested X server Xephyr to show container desktops
in a window on host display. (Needs 'Xephyr' or 'Xnest').
With option --wm=auto usefull for single apps, too.
-A, --xpra-xwayland Like --xpra, but supports option --gpu.
(Needs 'xpra', 'Xwayland', 'weston' and 'xdotool').
-Y, --weston-xwayland Like --xephyr, but supports option --gpu.
Runs as nested server in X or on its own from console.
(Needs 'weston' and 'Xwayland'.)
-h, --hostdisplay Share host display :0, quite bad container isolation!
Least overhead of all X server options.
-x, --xorg Run new core Xorg server. Runs ootb from console.
Switch tty with <CTRL><ALT><F1>....<F12>.
To run from within X, edit '/etc/X11/Xwrapper.conf' and
replace line: allowed_users=console
with lines allowed_users=anybody
needs_root_rights=yes
Debian 9 and Ubuntu 16.04: Install xserver-xorg-legacy.
Special X servers:
-n, --nxagent Like --xpra for single applications, but faster startup.
With --desktop like --xephyr, but resizeable.
(Needs 'nxagent', best since nxagent version 3.5.99).
--kwin-xwayland Like --weston-xwayland, but using kwin_wayland
(Needs 'kwin_wayland' and 'Xwayland').
-X, --xwayland Use Xwayland, needs a running Wayland compositor.
(Needs 'Xwayland' to be installed.)
--xdummy Invisible X server. (Needs Xorg's dummy video driver)
--xvfb Invisible X server. (Needs 'Xvfb')
--xdummy and --xvfb can be used for custom access,
for example with VNC or ssh.
Output of environment variables on stdout. (--showenv)
Along with option --gpu an invisible setup with Weston,
Xwayland and xdotool is used (instead of Xdummy or Xvfb)
--nothing Do not provide any X or Wayland server.
Wayland without X: (see also above: --wayland)
-T, --weston Weston without X for pure Wayland applications.
Runs in X or from console. (Needs package weston.)
-K, --kwin KWin without X for pure Wayland applications.
Runs from X or from console. (Needs kwin_wayland.)
-H, --hostwayland Share host Wayland without X for pure Wayland apps.
(Needs already running Wayland compositor like Gnome 3.)
(Can be combined with --hostdisplay.)
-E, --waylandenv Set some environment variables summoning some toolkits
to use Wayland. (GTK3 QT5 Clutter SDL Elementary Evas)
X appearance options:
-f, --fullscreen Run Xephyr, nxagent or Weston in fullscreen mode.
--size XxY Screen size of new X server (f.e. 800x600).
-l, --scale N Scale/zoom factor N for xpra, Xorg or Weston.
Allowed for --xpra, --xorg --xpra-xwayland: 0.25...8.0.
Allowed for --weston and --weston-xwayland: 1...9.
(Mismatching font sizes can be adjusted with --dpi).
--rotate N Rotate display (--xorg, --weston and --weston-xwayland)
Allowed values: 0, 90, 180, 270, flipped, flipped-90,
flipped-180, flipped-270. (flipped = mirrored)
--dpi N dpi value (dots per inch) to submit to clients.
Influences font size of some applications.
--output-count N Multiple outputs for Weston, KWin or Xephyr.
--xfishtank Show fish tank on new X server (needs 'xfishtank').
Advanced options:
-v, --verbose Be verbose. (Shows logfiles).
--silent Do not show terminal messages (except errors).
--stdout Show stdout of container applications.
--stderr Show stderr of container applications.
--no-entrypoint Disable ENTRYPOINT in image to allow other commands, too
--no-internet Disable internet access for container.
--pw FRONTEND Choose frontend for password prompt. Possible FRONTEND:
su sudo gksu gksudo lxsu lxsudo kdesu kdesudo
pkexec beesu none
Init system and dbus daemon:
--tini Default: init system tini (built-in of docker).
--no-init No init system in container. Image command is PID 1.
--runit Init system runit. Degrades container isolation.
Needs 'runit' installed in image.
--openrc Init system OpenRC. Degrades container isolation a bit,
but needs less capabilities than --runit and --systemd.
Needs 'openrc' installed in image.
--systemd Init system systemd. Degrades container isolation.
For faster startup mask services that fail in container.
Needs 'systemd' installed in image.
--sharecgroup Share /sys/fs/cgroup. Default for --systemd.
Can be used with --openrc.
--dbus-daemon Run dbus system daemon in container. (includes --dbus)
-b, --dbus Run image command with dbus-launch.
User settings:
--user N Create container user N (N=name or N=uid). Default:
same as host user. N can also be an unknown user id.
You can specify a group id with N being 'user:gid'.
--hostuser USER Run X (and container user) as user USER. Default is
result of \$(logname). (x11docker must run as root).
--sudouser Allow sudo and su for container user. Use with care,
severe reduction of default x11docker security!
Password: x11docker
Container environment:
--env VAR=value Set custom environment variable VAR=value
Special usecase for language: '--env LANG=\$LANG'
--showenv Echo new \$DISPLAY, \$XAUTHORITY and \$WAYLAND_DISPLAY.
For custom access to new X server. Get environment
with: read xenv < <(x11docker --showenv [...])
--sharewayland Share Wayland socket and set WAYLAND_DISPLAY.
X authentication:
--xhost STR Set \"xhost STR\" on new X server (see 'man xhost').
(Use with care. '--xhost +' allows access for everyone).
-o, --no-xhost Disable any access to host X server granted by xhost.
--no-auth Disable cookie authentication on new X server.
--trusted Use trusted cookies for --hostdisplay
--untrusted Create untrusted cookies. Restricts X access.
Default for --hostdisplay to avoid keylogging and
MIT-SHM errors. If --gpu is set, --trusted is used.
X and Wayland configuration:
--vt N Use vt / tty N (affects --xorg, --xdummy, --xpra).
--display N Use display number N for new X server.
--westonini FILE Custom weston.ini for --weston and --weston-xwayland.
Container capabilities:
--ipc Sets docker option --ipc=host, disables IPC namespacing.
Severe reduction of container isolation! Shares
host interprocess communication and shared memory.
Allows MIT-SHM extension of X servers.
--net Set docker run option --net=host, disables network
namespacing. Severe reduction of container isolation!
Shares host network stack, allows dbus communication.
--cap-default Allow default docker container capabilities and
disable container security hardening of x11docker.
Custom capabilities can be added with --cap-add=CAP after --
Miscellaneous:
--starter Create starter on desktop and exit.
--cachedir DIR Custom cache folder. (Default: \$HOME/.cache/x11docker)
--license Show license of x11docker (MIT) and exit.
--ps Preserve container and cache files on exit.
--cleanup Clean up orphaned containers and cache files.
Installation options (need root permissions):
--install Install x11docker and x11docker-gui on your system.
--update Update x11docker with latest version from github.
--remove Remove x11docker from your system.
x11docker version: $Version
Please report issues at https://github.com/mviereck/x11docker
"
}
license() { # --license: show license (MIT)
echo 'MIT License
Copyright (c) 2015, 2016, 2017, 2018 Martin Viereck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'
}
alertbox() { # X alert box with title $1 and message $2
local Title Message
Title=${1:-}
Message=${2:-}
Message="$(echo "$Message" | LANG=C sed "s/[\x80-\xFF]//g")" # remove UTF-8 special chars
# try some tools to show alert message. If all tools fail, return 1
command -v xmessage >/dev/null && [ -n "$DISPLAY" ] && {
echo "$Title
$Message" | xmessage -file - -default okay ||:
} || {
command -v gxmessage >/dev/null && [ -n "$DISPLAY" ] && {
echo "$Title
$Message" | gxmessage -file - -default okay ||:
}
} || {
command -v zenity >/dev/null && [ -n "$DISPLAY" ] && {
zenity --error --no-markup --ellipsize --title="$Title" --text="$Message" 2>/dev/null ||:
}
} || {
command -v yad >/dev/null && [ -n "$DISPLAY" ] && {
yad --image "dialog-error" --title "$Title" --button=gtk-ok:0 --text "$(echo "$Message" | sed 's/\\/\\\\/g')" --fixed 2>/dev/null ||:
}
} || {
command -v kaptain >/dev/null && [ -n "$DISPLAY" ] && {
echo 'start "'$Title'" -> message @close=" cancel" ;
message "'$(echo "$Message" | sed 's/\\/\\\\\\/g' | sed 's/"/\\"/g' | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' )'" -> @fill ;' | kaptain ||:
}
} || {
command -v kdialog >/dev/null && [ -n "$DISPLAY" ] && {
kdialog --title "$Title" --error "$(echo "$Message" | sed 's/\\/\\\\/g' )" 2>/dev/null ||:
}
} || {
command -v xterm >/dev/null && [ -n "$DISPLAY" ] && {
xterm -title "$Title" -e "echo '$(echo "$Message" | sed "s/'/\"/g")' ; read -n1" ||:
}
} || {
[ -n "$Anyterminal" ] && [ -e "$Cachefolder" ] && {
mkfile $Cachefolder/message
echo "#! /bin/bash
echo '$Title
$Message
(Press any key to close window)'
read -n1
" >> $Cachefolder/message
$Anyterminal /bin/bash $Cachefolder/message ||:
}
} || {
notify-send "$Title:
$Message" 2>/dev/null
} || return 1
return 0
}
error() { # show error messages on stderr and exit
Message="$*
Type 'x11docker --help' for usage information
For debugging, run x11docker in terminal and/or enable option '--verbose'
and look afterwards at logfile $Logfile3
If you think this is a bug in x11docker,
please report at https://github.com/mviereck/x11docker"
# output to terminal
echo -e "
\033[41mx11docker ERROR:\033[49m $Message
" >&2
# output to X dialogbox
[ -n "$Hostxenv" ]&& export $Hostxenv
[ -n "$Newxenv" ] && [ "$Tty" = "yes" ] && export $Newxenv
[ "$Xserver" = "--xorg" ] && export $Newxenv
alertbox "x11docker ERROR" "$Message"
# output to logfile
[ -e "$Logfile" ] && echo "x11docker ERROR: $Message
" >> "$Logfile"
saygoodbye
touch $Errorfile
exit 1 # trap to finish()
}
warning() { # show warning messages
echo "$(tput setaf 3)x11docker WARNING:$(tput sgr0) $*" >&3
echo "" >&3
[ -e "$Logfile" ] && echo "x11docker WARNING: $*
" >> "$Logfile"
return 0
}
note() { # show notice messages
echo "$(tput setaf 2)x11docker note:$(tput sgr0) $*" >&3
echo "" >&3
[ -e "$Logfile" ] && echo "x11docker note: $*
" >> "$Logfile"
return 0
}
verbose() { # show verbose messages
# only logfile notes here, terminal output is done with tail in part:verbose
[ -e "$Logfile" ] && echo "x11docker: $*
" >> "$Logfile"
return 0
}
installer() { # --install, --update, --remove: Installer for x11docker
# --install:
# - copies x11docker and x11docker-gui to /usr/bin
# - installs icon in /usr/share/icons
# - creates x11docker.desktop file in /usr/share/applications
# --update:
# - download and install latest version from github
# --remove
# - remove installed files
local X11dockericonfile
export PATH="$PATH:/usr/local/bin" # avoid bug on opensuse where root does not have this in $PATH. Will become obsolete as new default is /usr/bin
# Prepairing
case ${1:-} in
--install)
command -v x11docker > /dev/null && { error "x11docker seems to be installed already.
Try 'x11docker --update' instead." ; }
[ -f "./x11docker" ] || { error "File x11docker not found in current folder.
Try 'x11docker --update' instead." ; }
command -v kaptain > /dev/null || { warning "x11docker-gui needs package kaptain
to provide a GUI, but could not find kaptain on your system.
Please install package kaptain if you want to use x11docker-gui.
x11docker-gui tries to use image x11docker/kaptain if kaptain missig.
x11docker itself does not need it and works fine from cli.
Get kaptain on github: https://github.com/mviereck/kaptain" ; }
;;
--update)
mkdir -p /tmp/x11docker-install && cd /tmp/x11docker-install || error "Could not create or cd to /tmp/x11docker-install"
echo "Downloading latest x11docker version from github"
command -v wget >/dev/null || error "wget not found. Need 'wget' for download.
Please install wget."
wget https://github.com/mviereck/x11docker/archive/master.zip || error "Could not download x11docker-master from github"
echo "Unpacking archive"
command -v unzip >/dev/null || error "Can not unpack archive. Please install 'unzip'."
unzip master.zip || error "Could not unzip archive"
echo ""
cd /tmp/x11docker-install/x11docker-master || error "could not cd to /tmp/x11docker-install/x11docker-master"
;;
esac
# Doing
case ${1:-} in
--install|--update)
[ -x /usr/local/bin/x11docker ] && rm -v /usr/local/bin/x11docker
[ -x /usr/local/bin/x11docker-gui ] && rm -v /usr/local/bin/x11docker-gui
echo "Installing x11docker and x11docker-gui in /usr/bin"
cp x11docker /usr/bin/ || error "Could not copy x11docker to /usr/bin"
chmod 755 /usr/bin/x11docker || error "Could not set executeable bit on x11docker"
cp x11docker-gui /usr/bin/ && chmod 755 /usr/bin/x11docker-gui || warning "x11docker-gui not found"
echo "Creating icon and application entry for x11docker"
X11dockericonfile=$(x11docker-gui --icon)
[ -e "$X11dockericonfile" ] && {
xdg-icon-resource install --context apps --novendor --size 72 "$X11dockericonfile" x11docker
command -v xdg-icon-resource >/dev/null || warning "Could not install icon for x11docker.
Please install 'xdg-icon-resource' and try again."
rm $X11dockericonfile
} || note "Could not create icon for x11docker"
[ -e "/usr/bin/x11docker-gui" ] && {
echo "[Desktop Entry]
Version=1.0
Type=Application
Name=x11docker
Comment=Run GUI applications in docker images
Exec=x11docker-gui
Icon=x11docker
Categories=System
" > /usr/share/applications/x11docker.desktop
} || note "Did not create desktop entry for x11docker-gui"
command -v kaptain >/dev/null || warning "Could not find 'kaptain' for x11docker-gui.
Please install 'kaptain'.
If your distributions does not provide it, look at kaptain repository:
https://github.com/mviereck/kaptain"
echo "Storing README.md and LICENSE.txt in /usr/share/doc/x11docker"
mkdir -p /usr/share/doc/x11docker && {
cp README.md /usr/share/doc/x11docker/
cp LICENSE.txt /usr/share/doc/x11docker/
} || note "Error while creating /usr/share/doc/x11docker"
echo "Installation ready: x11docker version $(x11docker --version)"
;;
--remove)
echo "removing x11docker from your system"
[ -x /usr/local/bin/x11docker ] && { # from older installations. /usr/bin is default now as /usr/local/bin can miss in $PATH for root
/usr/local/bin/x11docker --cleanup
rm -v /usr/local/bin/x11docker
rm -v /usr/local/bin/x11docker-gui
}
[ -x /usr/bin/x11docker ] && {
/usr/bin/x11docker --cleanup
rm -v /usr/bin/x11docker
rm -v /usr/bin/x11docker-gui
}
[ -e "/usr/share/applications/x11docker.desktop" ] && rm -v /usr/share/applications/x11docker.desktop
[ -e "/usr/share/doc/x11docker" ] && rm -R -v /usr/share/doc/x11docker
xdg-icon-resource uninstall --size 72 x11docker
note "Will not remove files in your home folder.
There may be files left in \$HOME/.local/share/x11docker
The symbolic link \$HOME/x11docker may exist, too.
The cache folder \$HOME/.cache/x11docker should be removed already."
;;
esac
# Cleanup
case ${1:-} in
--update)
echo "Removing downloaded files"
cd ~
rm -R /tmp/x11docker-install
;;
esac
echo "Ready."
}
checkorphaned() { # --cleanup : check for non-removed containers and left cache files
local Orphanedcontainers Orphanedfolders Line
note "x11docker will check for orphaned containers from earlier sessions.
This can happen if docker was not closed successfully.
x11docker will look for those containers and will clean up x11docker cache.
Caution: any currently running x11docker sessions will be terminated, too."
Orphanedcontainers=""
Orphanedfolders=""
cd $Cacherootfolder || error "Could not cd to cache folder '$Cacherootfolder'."
[ $? ] && [ -n "$(echo "$Cacherootfolder" | grep .cache/x11docker)" ] && Orphanedfolders=$(echo $(find "$Cacherootfolder" -mindepth 1 -maxdepth 1 -type d | sed s%$Cacherootfolder/%%))
Orphanedcontainers="$(docker ps -a --filter name=x11docker_X --format "{{.Names}}")"
Orphanedcontainers="$(env IFS='' echo $Orphanedcontainers)"
if [ -z "$Orphanedcontainers" ] && [ -z "$Orphanedfolders" ] ; then
note "No orphaned containers or cache files found. good luck!"
else
note "Found orphaned containers:
$Orphanedcontainers"
note "Found orphaned folders in $Cacherootfolder:
$Orphanedfolders"
for Line in $Orphanedfolders ; do
[ -d "$Cacherootfolder/$Line/share" ] && [ ! -e "$Cacherootfolder/$Line/share/timetosaygoodbye" ] && {
note "Found possibly active container $Line.
Will summon it to terminate itself."
touch "$Cacherootfolder/$Line/share/timetosaygoodbye" # terminating possibly running x11docker sessions
sleep 3
}
done
[ -n "$Orphanedcontainers" ] && {
note "Removing containers with: docker rm -f $Orphanedcontainers
$(bash -c "docker rm -f $Orphanedcontainers" 2>&1)"
}
[ -n "$Orphanedfolders" ] && {
note "Removing cache files with: rm -R -f $Orphanedfolders
$(rm -R -f $Orphanedfolders 2>&1)"
}
fi
note "Ready."
}
storepid () { # store pids and names of background processes in file $Bgpidfile
# store Pid and process name of background processes in file
# $1 should be Pid, $2 should be name of process
# for use on exit / with trap to clean up with background processes
# this subroutine has a twin in xinitrc
echo ${1:-} ${2:-} >> $Bgpidfile
verbose "stored background pid ${1:-} of ${2:-}"
}
saygoodbye() { # create file signaling watching processes to terminate
verbose "Creating $Timetosaygoodbye"
[ -e "$Sharefolder" ] && $Mksu "touch $Timetosaygoodbye"
}
finish() { # trap routine, clean up background processes and cache
local Pid Name Zeit
trap - EXIT
verbose "terminating x11docker ..."
saygoodbye
[ -s "$Bgpidfile" ] && {
# check for possible remaining background processes stored in $Bgpidfile
while read -r Line ; do
Pid=$(echo $Line | awk '{print $1}')
Name=$(echo $Line | awk '{print $2}')
if [ -n "$Pid" ] && [ -n "$(ps -p $Pid --no-headers)" ] ; then
verbose "terminating background pid $Pid of $Name"
case $Name in
weston|kwin_wayland|compositor|xpraserver|xpraclient|windowmanager|shareclipboard|hostexe|xfishtank) kill -s KILL $Pid || {
sleep 1
[ -n "$(ps -p $Pid --no-headers)" ] && warning "error terminating $Pid $Name"
}
;;
docker)
[ -n "$Sudo" ] && Sudo="sudo -n" # no password prompt here, rather fail
$Sudo docker stop $Containername >/dev/null 2>&1 || {
! $Sudo docker images >/dev/null 2>&1 || { [ -n "$($Sudo docker ps --filter name=$Containername --quiet 2>&1)" ] || ps -p $Pid >/dev/null ; } && {
note "Found remaining docker process. Most probably the X session was
interrupted. Can not stop container because x11docker does not run as root.
Will wait up to 10 seconds for docker to finish."
Zeit=$(date +%s)
while ps -p $Pid >/dev/null ; do
note "waiting for docker to terminate ..."
sleep 1
[ 10 -lt $(echo "$(date +%s) - $Zeit" | bc) ] && break ||:
done
if ps -p $Pid >/dev/null ; then
note "docker didn't terminate as it should.
Will not clean cache to avoid file permission problems.
You can remove the new container with command:
docker rm -f $Containername
Afterwards, remove cache files with:
rm -R $Cachefolder
or let x11docker do the cleanup work for you:
x11docker --cleanup"
Preservecachefiles="yes"
else
note "docker container terminated successfully"
fi
}
}
;;
*) note "Found remaining background process.
Will send signal KILL to process tree of $Line
$(ps -p $Pid --no-headers)"
pkill -KILL -P $Pid || warning "error terminating $Pid $Name"
;;
esac
fi
done < <(tac $Bgpidfile)
}
# option --pulseaudio: unload tcp module
[ -n "$Pulseaudiomoduleid" ] && pactl unload-module $Pulseaudiomoduleid
sleep 3 # a bit time for all processes to look for $Timetosaygoodbye (most look every 1 second)
[ -n "$Logfile2$Logfile3" ] && $Mksu "cp '$Logfile2' '$Logfile3'"
rm "$Logfile"
[ "$Preservecontainer" = "yes" ] && Preservecachefiles="yes"
[ "$Preservecachefiles" = "no" ] && echo "$Cachefolder" | grep -q .cache && echo "$Cachefolder" | grep -q x11docker && [ "x11docker" != "$(basename "$Cachefolder")" ] && rm -f -R "$Cachefolder"
if [ -e "$Errorfile" ]; then rm "$Errorfile" ; exit 1; else exit 0; fi
}
verlte() { # version number check $1 less than or equal $2
[ "${1:-}" = "$(echo -e "${1:-}\n${2:-}" | sort -V | head -n1)" ] && return 0 || return 1
}
verlt() { # version number check $1 less than $2
[ "${1:-}" = "${2:-}" ] && return 1 || { verlte "${1:-}" "${2:-}" && return 0 || return 1 ; }
}
mywatch() { # repeat $1 untils its output changes
# --interval must be integer for centos and fedora depite contrary documentation in manpage
env TERM=linux watch --interval 1 --chgexit --no-title -- "sh -c '${1:-}'" >/dev/null 2>&1
}
isnum() { # check if $1 is a number
[ "1" = "$(awk -v a="${1:-}" 'BEGIN {print (a == a + 0)}')" ]
}
writeaccess() { # check if useruid $1 has write access to folder $2
local dirVals gMember
if read -a dirVals < <(stat -Lc "%U %G %A" "${2:-}") && (
( [ "$(id -u $dirVals)" == "${1:-}" ] && [ "${dirVals[2]:2:1}" == "w" ] ) ||
( [ "${dirVals[2]:8:1}" == "w" ] ) ||
( [ "${dirVals[2]:5:1}" == "w" ] && (
gMember=($(groups ${1:-} 2>/dev/null)) &&
[[ "${gMember[*]:2}" =~ ^(.* |)${dirVals[1]}( .*|)$ ]]
) ) )
then
return 0
else
[ "w" = "$(getfacl -pn "${2:-}" | grep user:${1:-}: | rev | cut -c2)" ] && return 0 || return 1 # FIXME: could check write access for gid, if uid access fails.
fi
}
waitforfilecreation() { # similar to inotify-wait: wait up to 15s for file $1 to be created
# $1 file to wait for
# $2 time to wait. default: 15s. possible: infinity
local Zeit Warten
Zeit=$(date +%s)
verbose "Waiting for file creation of ${1:-}"
case $2 in
"") Warten=15 ;;
infinity|inf) Warten=32000 ;; # nearly infinity in fast-moving today ...
*) Warten=${2:-} ;;
esac
while [ ! "$(find "${1:-}" 2>/dev/null)" ] ; do
sleep 0.2
[ $Warten -lt $(expr $(date +%s) - $Zeit) ] && return 1
[ -e "$Timetosaygoodbye" ] && return 1
done
verbose "Found newly created file ${1:-}"
return 0
}
waitforfilecontent() { # wait for file $1 to be not empty
local Zeit
# $1 file to look at
Zeit=$(date +%s)
verbose "Waiting for file content in ${1:-}"
while [ ! -s "${1:-}" ] ; do
sleep 0.1
[ 15 -lt $(expr $(date +%s) - $Zeit) ] && return 1
[ -e "$Timetosaygoodbye" ] && return 1
done
verbose "Found file content in ${1:-}"
return 0
}
waitforlogentry() { # wait for entry $3 in logfile $2 of application $1
# $1 is the application we are waiting for to be ready
# $2 points to logfile
# $3 keyword to wait for
local Zeit
Zeit=$(date +%s)
while [ -z "$(cat "${2:-}" | grep "${3:-}")" ] ; do
verbose "waiting since $(expr $(date +%s) - $Zeit)s for ${1:-} to be ready..."
sleep 0.2
[ 15 -lt $(expr $(date +%s) - $Zeit) ] && return 1
[ -e "$Timetosaygoodbye" ] && return 1
done
return 0
}
no_xhost() { # remove any access to X server granted by xhost
local Line
xhost
xhost | tail -n +2 /dev/stdin | while read -r Line ; do # read all but the first line (header)
xhost -$Line # disable every entry
done
xhost - # enable access control
[ "$(xhost | wc -l)" -gt "1" ] && {
warning "Remaining xhost permissions found on display $DISPLAY
$(xhost)"
return 1
}
return 0
}
mkfile() { # create file $1 owned by $Hostuser
:> "${1:-}"
chown $Hostuser "${1:-}"
chgrp $Hostusergid "${1:-}"
[ -n "${2:-}" ] && chmod ${2:-} "${1:-}"
}
{ #### part: variables: default settings
trap finish EXIT
export IFS=$' \n\t' # set IFS to default
exec 3>&2 # second stderr channel
exec 4>&2 # stderr channel for --stderr
tty | grep -q tty && Tty="yes" || Tty="no" # check if running on X or on tty
export PATH="$PATH:/usr/games:/usr/local/bin" # may miss for root, but can be needed for --exe and --xfishtank
export PATH="$PATH:/usr/sbin" # may miss for unprivileged users, but can be needed for `ip`
# Logfiles
Mycookie=$(mcookie | cut -b1-6)
[ -z "$Mycookie" ] && Mycookie=$RANDOM
export Logfile=/tmp/x11docker.$Mycookie.log # collection of all Logfiles. Stored in /tmp because cache is not ready yet
touch $Logfile && chmod 666 $Logfile
Logfile2= # live copy of $Logfile in $Sharefolder
Logfile3= # afterward copy of $Logfile in $Cacherootfolder
Errorfile=/tmp/x11docker.error.$Mycookie # error indicating file created by error()
Bgpidfile=backgroundpids # file to store pids and names of background processes that shut be killed on exit
Timetosaygoodbye=timetosaygoodbye # file giving term signal to all parties
# Users
Lognameuser="" # $(logname) or $SUDO_USER or $PKEXEC_USER
Hostuser="" # $Lognameuser or --hostuser. Unprivileged user for non-root commands
Hostuseruid=""
Hostusergid=""
Hostuserhome=""
Benutzer="" # option --user: container user. Default: same as $Hostuser.
Benutzeruid=""
Benutzergid=""
Benutzerhome=""
Benutzergruppe=""
Benutzerpasswdentry=""
Benutzerpasswort="sac19FwGGTx/A" # encrypted password "x11docker", suits /etc/shadow. Created with: perl -e 'print crypt("x11docker", "salt"),"\n"'
Mksu="" # prefix to run unprivileged commands (auto or --hostuser)
Mksubenutzer="" # prefix to run commands as user defined by --user
# Gaining root privileges to run docker
Passwordprompt="" # way to ask for password. one of pkexec, su, sudo, gksu, gksudo, auto
Getroot="" # prefix for commands needing root (only dockerrc script)
Sudo="" # "sudo" or empty
Needpassword="yes" # Need password? assume yes, check later
# Cache folders
Cacherootfolder="" # cache folder to store temporary files
Cachefolder=""
Sharefolder=share # subfolder for shared files
Cshare=/x11docker # mountpoint of $Sharefolder in container
# Parsed arguments
X11dockermode="run" # can be either "xonly", "run" or "exe", depends on options. while parsing, xonly changes to run or exe
X11dockerargs="$*" # arguments for x11docker
Imagename="" # name of image to run
Imagecommand="" # image command [+args]
Hostexe="" # can contain host executable
Dockeroptions="" # options for docker after -- and before image name
# docker variables
Containername="" # name of container set by x11docker to make --cleanup able to find orphaned containers
Dockerip="" # IP adress of docker interface
Dockeriprange="" # IP adress of docker interface including suffix /16
Containerpid="" # process ID of script process with docker container
Dockerdaemon="$(pgrep -xa $(ps -e -o comm | grep dockerd) 2>/dev/null)" # how docker daemon has been started
# docker related files
Dockerrc=dockerrc # init script run by docker. Creates $Imagecommandscript
Imagecommandscript=x11docker.CMD.sh # name of shared script containing image command
Dockerlogfile=docker.log # file to log output of docker
Containerpidfile=docker.pid # file to store process ID of script -c docker
Containerip=container.ip # IP adress of container
Setupscript=containersetup.sh
# X server config files, log files and such stuff
Xinitrc=xinitrc # file to store xinitrc commands
Xinitlogfile=xinit.log # file to log output of X server
Xtermrc=xtermrc # file for password prompt script
Pullrc=pullrc # file for pull dialog script
Xtermlogfile=xterm.log # file to log output of xterm
Compositorlogfile=compositor.log # file to log output of Weston or KWin
Compositorpidfile=compositor.pid # process id of compositor
Xpraserverlogfile=xpraserver.log # logfile for xpra server
Xpraclientlogfile=xpraclient.log # logfile for xpra client
Westonini=weston.ini # config file for weston
Customwestonini="" # custom config file for weston
Xdummyconf=xdummy.xorg.conf # xorg.conf for dummy video driver
Xdummywrapper=Xdummywrapper # fork from xpra to wrap Xorg for Xdummy
Xservercookie=Xservercookie # file to store new X server cookies
Xclientcookie=Xclientcookie # file to store new X client cookies
# stdin stdout stderr
Cmdstdinfile=stdin # stdin for image command piped to x11docker
Cmdstdoutlogfile=stdout # stdout for image command
Cmdstderrlogfile=stderr # stderr for image command
# host environment
Hostsystem="$(source /etc/os-release ; echo $ID)"
Hostdisplay="$DISPLAY" # store environment variable containing name of current display
Hostdisplaynumber="$(echo $Hostdisplay | cut -d: -f2 | cut -d. -f1)" # display number without ":" and ".0"
Hostxauthority="Xauthority-$Hostdisplaynumber" # file to store copy of $XAUTHORITY
[ -n "$Hostdisplay" ] && Hostxsocket="/tmp/.X11-unix/X$Hostdisplaynumber" || Hostxsocket="" # X socket from host, needed for --hostdisplay
# X server settings
Xserver="" # X server to use
Xcommand="" # command to start X server
Newdisplay="" # new display for new X server
Newdisplaynumber="" # Like Newdisplay, but without ':'
Newxsocket="" # New X socket
Newxenv="" # environment variables for new X server DISPLAY XAUTHORITY XSOCKET WAYLAND_DISPLAY