-
Notifications
You must be signed in to change notification settings - Fork 379
/
x11docker
3431 lines (3178 loc) · 168 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.
# Provides GPU acceleration and pulseaudio sound. Circumvents common X security leaks.
# 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.6.2.11"
changelog() {
# 18.10.2017 V3.6.2.12 bugfix: dbus-launch disturbed gksu
# 18.10.2017 V3.6.2.11 CentOS/RHEL workaround: insist on root or gksu; terminal password prompt causes docker to terminate regardless of nohup
# 17.10.2017 V3.6.2.10 bugfixes in terminal-emulator setup for password prompt and pull question (2)
# 17.10.2017 V3.6.2.9 bugfixes in terminal-emulator setup for password prompt and pull question
# 14.12.2017 xpra: --file-transfer=off (stores files in "Downloads" from host, useless here)
# 12.10.2017 V3.6.2.8 --xdummy/--xpra: add multiple modelines for virtual display sizes to allow flexible changes of xpra client desktop window
# 10.10.2017 --xpra: virtual display size always equal with physical display, create smaller mode in xinitrc -> allow fullscreen
# xpra: disable some unused, but possibly leaking features (forwarding of webcam, notifications, printer)
# xpra: set xpra specific environment variables in dockerrc
# xpra: show keyboard shortcuts
# 08.10.2017 V3.6.2.7 --xephyr: title for Xephyr windows
# --xephyr: Xnest as fallback for missing Xephyr
# --xpra --desktop hint: screensize bug fixed since xpra v2.2-r17117
# 07.10.2017 V3.6.2.6 bugfix: --xpra --desktop: use start-desktop instead of shadow
# 05.10.2017 V3.6.2.5 no_xhost() after cookie creation avoids xhost warning on Xwayland
# 04.10.2017 --output-count in --auto mode: choose --weston-xwayland
# 01.10.2017 --display: allow : before display number
# 30.09.2017 sh instead of bash to run x11docker_CMD
# 27.09.2017 V3.6.2.4 --starter: missing xdg-user-dir is no longer an error
# --silent: redirect stderr already while parsing
# --user=root: disable --cap-drop=ALL
# --help: update usage info
# weston.ini: background color and zoom-in effect
# 26.09.2017 bugfix --xonly: do not fail if docker daemon is not running
# 25.09.2017 use Kwin/Kwin-Xwayland as fallback for Weston/Weston-Xwayland
# catch closing xpra client in every case, not only in desktop mode
# 22.09.2017 parsing cli options: check for remaining arguments $# instead of empty $1
# 19.09.2017 V3.6.2.3 --xorg: only run setxkbmap in xinitrc if $Hostdisplay is set
# 18.09.2017 V3.6.2.2 --xpra --scale in desktop mode: regard different --dpi behaviour since xpra v2.2
# --help: update usage info
# 17.09.2017 setxkbmap for Xorg like for Xephyr, too
# weston.ini: added panel-position=none, different syntax for different weston versions (seen in Arch Linux).
# 16.09.2017 x11docker_CMD: replace shell with "exec $Imagecommand" (only if stdin is empty)
# 15.09.2017 V3.6.2.1 --home: avoid creating $Adduserhomefolder with wrong restrictions if $Hostuser is different from $Benutzer
# 14.09.2017 removed z flag in docker command, not needed with current SELinux solution
# --weston[-xwayland]: no output section on tty without --scale, --size or --rotate
# --weston[-xwayland]: allow --size on tty, though only "real" resolutions will take effect
# --xorg: --scale, --size: change primary monitor only, will do better on multi monitor setup
# bugfixes in part:check screensize
# 13.09.2017 bugfix: watch for closing xpra client in desktop mode to avoid invisible remaining x11docker
# bugfix: --xdummy --gpu now possible on tty, too
# bugfix: --xorg on tty: do not set screen size without --size.
# 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() {
# find workaround for forking terminals and detach docker from terminal
# CentOS: allow terminal password prompt, currently docker terminates with terminal even with nohup
# BUG centos7: x11docker-gui: x11docker/kaptain does not run
# further checks on centos 7
# check all FIXME
# new option --no-internet?
# 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 KDE-Wayland fails with different --user, seems to be ownership issues with wayland socket
### BUG collection: non x11docker bugs
# BUG kdeneon/all:user-lts plasmashell: no kwin?
# 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.
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.
Features:
* Hardware acceleration for OpenGL
* Pulseaudio sound
* Clipboard sharing
* Persistent home folders
* Wayland support
* No dependencies in docker images
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-user-dir xdg-icon-resource unzip
Dependencies in image:
Doesn't have dependencies inside of docker images, except for special
options --gpu, --pulseaudio and --dbus, 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 (default if no image name)
Container desktop environment, host window manager:
-d, --desktop Indicate desktop environment in image.
-w, --wm COMMAND Host window manager to use.
Usefull f.e to run single applications in Xephyr.
If COMMAND is 'auto' or 'm', autodetect a host wm.
Shared folders, GPU, clipboard and sound options:
-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).
-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. Needs
'pulseaudio' to be installed on host and in image.
-g, --gpu Hardware accelerated OpenGL rendering. Shares files in
/dev/dri. Needs MESA/OpenGL to be installed in image.
Degrades container isolation. Container access to GPU.
X server options:
--auto Auto choose X server for docker applications (default).
(Regards options --desktop, --gpu and --wm).
-a, --xpra Use xpra to show application windows on host display.
(Needs 'xpra' to be installed. On Ubuntu 16.04 also
'Xvfb'. With option --desktop it runs in desktop mode.)
-y, --xephyr Use Xephyr to show desktops in a window on host display.
(Needs 'Xephyr'. Possible fallback alternative: 'Xnest').
-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' to be installed.)
-h, --hostdisplay Share host display :0, QUITE BAD CONTAINER ISOLATION!
Least overhead of all X server options.
-x, --xorg Use 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
Ubuntu 16.04 and debian 9: 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' to be installed). (Experimental).
-N, --kwin-native Seamless X and Wayland together. (Experimental).
--kwin-xwayland Like --weston-xwayland, but using kwin_wayland
-X, --xwayland Use Xwayland, needs a running Wayland compositor.
(Needs 'Xwayland' to be installed.)
--xdummy Invisible X server. (Needs 'xserver-xorg-video-dummy')
--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.
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:
-W, --weston Weston without X for pure Wayland applications.
Runs in X or from console. (Needs package weston.)
-H, --hostwayland Share host Wayland without X for pure Wayland apps.
(Needs already running Wayland compositor.)
(Can be combined with --hostdisplay.)
-K, --kwin KWin without X for pure Wayland applications.
Runs from X or from console. (Needs kwin_wayland.)
Screensize and 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 any terminal messages.
--stdout Show stdout of container applications.
--stderr Show stderr of container applications.
-E, --waylandenv Set some environment variables summoning some toolkits
to use Wayland. (GTK3 QT5 Clutter SDL Elementary Evas)
-b, --dbus Start image command with dbus-launch.
(often needed for QT5 applications running on Wayland).
(Needs 'dbus-launch' to be installed in image)
--no-entrypoint Disable ENTRYPOINT in image to allow other commands, too
--pw FRONTEND Choose frontend for password prompt. Possible FRONTEND:
su sudo gksu gksudo lxsu lxsudo kdesu kdesudo
pkexec beesu none
Developer options:
--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'.
--sudouser sudo without password for container user.
Severe reduction of default x11docker security!
--hostuser USER Run X (and container user) as user USER. Default is
result of \$(logname). (x11docker must run as root).
--env VAR=value Set custom environment variable VAR=value
--showenv echo new \$DISPLAY, \$XAUTHORITY and \$WAYLAND_DISPLAY.
-S, --sharewayland Share Wayland socket and set WAYLAND_DISPLAY.
--westonini FILE Custom weston.ini for --weston and --weston-xwayland.
--cachedir DIR Custom cache folder. (Default: \$HOME/.cache/x11docker)
--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 and --kwin-native
--untrusted Create untrusted cookies. Restricts X access.
Default for --hostdisplay and --kwin-native to avoid
MIT-SHM errors. Avoids keylogging with --hostdisplay.
If --gpu is set, --trusted is used.
--vt N Use vt / tty N (affects --xorg, --xdummy, --xpra)
--display N Use display number N
--ps Preserve container and cache files on exit.
--ipc Set docker run option --ipc=host, BREAKS ISOLATION.
Shares host interprocess communication and
shared memory. Allows MIT-SHM extension.
--net Set docker run option --net=host, BREAKS ISOLATION.
Shares host network stack including dbus communication.
--cap-default Allow default docker container capabilities.
Disables container security hardening normally done with
'--cap-drop=ALL --security-opt=no-new-privileges'
(default for --user=root and --sudouser).
--rw Allow read/write access to container root filesystem
(default for --user=root and --sudouser).
Options not starting docker or X server:
--license Show license of x11docker (MIT) and exit.
--starter Create starter on desktop and exit.
--orphaned Clean up orphaned containers and cache files.
Installation options (needs 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 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.'
}
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"
echo "
$(tput setaf 1)x11docker ERROR$(tput sgr0) $Message
" >&3
[ -n "$Hostxenv" ] && [ "$Xserver" != "Xorg" ] && local $Hostxenv
[ ! -s "$Timetosaygoodbye" ] && [ "$Silent" != "yes" ] && [ -n "$DISPLAY" ] && {
command -v xmessage >/dev/null && {
echo "x11docker ERROR: $Message" | xmessage -file - -default okay
:
} || {
command -v zenity >/dev/null && {
zenity --error --no-markup --ellipsize --text="x11docker ERROR: $Message"
:
}
} || notify-send "x11docker ERROR: $Message" 2>/dev/null
}
[ -e "$Logfile" ] && echo "x11docker ERROR: $Message
" >> "$Logfile"
[ -d "$Sharefolder" ] && $Mksu "touch $Timetosaygoodbye"
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 6)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
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 --orphaned
rm -v /usr/local/bin/x11docker
rm -v /usr/local/bin/x11docker-gui
}
[ -x /usr/bin/x11docker ] && {
/usr/bin/x11docker --orphaned
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() { # --orphaned : check for non-removed containers and left cache files
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 2
}
done
[ -n "$Orphanedcontainers" ] && {
note "docker rm -f $Orphanedcontainers"
note "$(bash -c "docker rm -f $Orphanedcontainers" 2>&1)"
}
[ -n "$Orphanedfolders" ] && {
note "rm -R -f -v $Orphanedfolders"
note "$(rm -R -f -v $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:-}"
}
finish() { # trap routine, clean up background processes and cache
trap - EXIT
verbose "terminating x11docker ..."
[ -e "$Sharefolder" ] && $Mksu "touch $Timetosaygoodbye"
[ -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 ### FIXME check with name was cleaner
verbose "terminating background pid $Pid of $Name"
case $Name in
weston|kwin_wayland|compositor|xpra|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)" ] || [ -n "$(ps -p $Pid | grep docker)" ] ; } && {
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 [ -n "$(ps -p $Pid | grep docker)" ] ; do
note "waiting for docker to terminate ..."
sleep 1
[ 10 -lt $(echo "$(date +%s) - $Zeit" | bc) ] && break ||:
done
if [ -n "$(ps -p $Pid | grep docker)" ] ; 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 --orphaned"
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
[ -s "$Pulseaudiomoduleid" ] && pactl unload-module $(cat "$Pulseaudiomoduleid")
sleep 1.5 # a bit time for all processes to look for $Timetosaygoodbye (most look once in a 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 ; }
}
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
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: should 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
Zeit=$(date +%s)
while [ ! "$(find "${1:-}" 2>/dev/null)" ] ; do
sleep 0.2
[ 15 -lt $(expr $(date +%s) - $Zeit) ] && return 1
[ -e "$Timetosaygoodbye" ] && return 1
done
return 0
}
waitforfilecontent() { # wait for file $1 to be not empty
# $1 file to look at
Zeit=$(date +%s)
while [ ! -s "${1:-}" ] ; do
sleep 0.1
[ 15 -lt $(expr $(date +%s) - $Zeit) ] && return 1
[ -e "$Timetosaygoodbye" ] && return 1
done
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
Zeit=$(date +%s)
while [ -z "$(cat "${2:-}" | grep "${3:-}")" ] ; do
verbose "waiting since $(expr $(date +%s) - $Zeit)s for ${1:-} to be ready..."
sleep 1
[ 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
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)" = "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:-}"
}
{ #### 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
# Logfiles
Mycookie=$(mcookie | cut -b1-6)
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=""
Benutzerpasswdentry=""
# 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)
Pkexec="" # "pkexec" or empty
Sudo="" # "sudo" or empty
# Cache folders
Cacherootfolder="" # cache folder to store temporary files
Cachefolder=""
Sharefolder=share # subfolder for shared files
Cshare=/tmp/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 --orphaned able to find orphaned containers
Dockerip="" # IP adress of docker interface
Dockeriprange="" # IP adress of docker interface including suffix /16
Dockerpid="" # process ID of 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 # name of shared script containing imagecommand
Createsudouser=createsudouser # script to create sudo user (option --sudouser)
Dockerlogfile=docker.log # file to log output of docker
Dockerpidfile=docker.pid # file to store process ID of docker
Containerip=container.ip # IP adress of container
Etcpasswd=passwd # created /etc/passwd for container
# 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=terminalrc # file for password prompt script
Pullrc=pullrc # file for pull dialog script
Xtermlogfile=terminal.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 server
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
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
Newxvt="" # Virtual console to use for core new X server (>7)
#Newxlock="" # .Xn-lock - exists for running X server with socket n
Xserveroptions="" # options for new X server
Xpraservercommand=""
Xpraclientcommand=""
Xpraoptions="" # options for xpra server and client
Xprashm="" # content XPRA_XSHM=0 disables usage of MIT-SHM in xpra
Xpraversion="" # $(xpra --version)
Nxagentoptions="" # options for nxagent
Xephyroptions="" # options for Xephyr
Xephyrglamor="yes" # former option '--glamor': enable Xephyr glamor 2D acceleration (deprecated, now always yes)
Xfishtank="no" # --fish: xfishtank on new X server
# Main X server options
Autochooseserver="yes" # option '--auto': automated choosing server
Desktopmode="" # option --desktop: image contains a desktop enironment.
Windowmanager="" # option '-w, --wm': window manager to use. if not given but needed, autodetection is used
Gpu="no" # option '--gpu': Use hardware accelerated OpenGL, share files in /dev/dri
# Screensize and related X server adjustments
Screensize="" # option --size XxY
Xaxis="" # virtual screen width
Yaxis="" # virtual screen height
Modeline="" # screen modeline describing display size, see "man cvt"
Maxxaxis="" # describes maximal screen size of display to support fullscreen beside windowed desktop
Maxyaxis=""
Fullscreen="no" # option '-f, --fullscreen': use fullscreen mode (Xephyr only)
Scaling="0" # option --scale: Scaling factor for xpra and weston
Rotation="" # option --rotate: Rotation for --weston and --weston-xwayland 0/90/180/270/flipped/flipped-90/..
Dpi="" # option --dpi: dots per inch to tell the clients.
Outputcount="1" # option --output-count, quantum of virtual screens for Weston and Xephyr
# Wayland and Weston
Hostwayland="$WAYLAND_DISPLAY" # store host wayland display
Compositorcommand="" # command to start Weston or KWin
Waylandsocket="" # Wayland socket for Xwayland in weston
Waylandtoolkitenv=("XDG_SESSION_TYPE=wayland GDK_BACKEND=wayland QT_QPA_PLATFORM=wayland-egl CLUTTER_BACKEND=wayland SDL_VIDEODRIVER=wayland ELM_DISPLAY=wl ELM_ACCEL=opengl ECORE_EVAS_ENGINE=wayland_egl")
Compositorpid="" # pid of weston or kwin
Westonoutput="" # Xn, WLn or monitor identifier
Sharewayland="no" # option --sharewayland: Share wayland socket and WAYLAND_DISPLAY
Setwaylandenv="no" # option --setwaylandenv: Set environment variables $Waylandtoolkitenv
Dbuslaunch="no" # option '--dbus': run image command with dbus-launch
# Available terminal emulators
Passwordterminal="" # terminal emulator to use for password prompt (if no terminal emulator is needed, it will be 'bash -c')
Pullterminal="" # terminal emulator to show progress of 'docker pull'
Terminallist="" # list of possible terminal emulators. Only a few work on wayland
# regular options
Adduserhome="no" # option '-m, --home' (or '--homedir'): share a folder ~/.local/share/x11docker/Imagename with created container
Adduserhomefolder="" # " " : path to shared folder.
Sharevolumes="" # option --volume: host folders to share
Shareclipboard="no" # option '-c, --clipboard' enable clipboard sharing
Shareclipboardscript=clipboard.bash # " " script used for text clipboard sharing
Showdisplayenvironment="no" # option -E, --env: Show environment variables of new display
Customenvironment="" # option '--env': set custom environment variables
Pulseaudio="no" # " use pulseaudio yes/no
Pulseaudiotcpport="" # option '--pulseaudio': pulseaudio tcp port to use
Pulseaudiomoduleid="pulseaudio.module.id" # " file with number of customized pulseaudio tcp module, output of pactl
Noentrypoint="no" # option --no-entrypoint: disable entrypoint in image
# verbosity options
Verbose="no" # option '-v, --verbose': if "yes", be verbose
Showstdout="no" # option --stdout: show image command stdout
Showstderr="no" # option --stderr: show image command stderr
Silent="no" # option --silent: do not show messages
# developer options
Sudouser="no" # option --sudouser: Create user with sudo permissions without a password
Capdropall="yes" # option --cap-default: (don't) drop all container capabilities
Readwrite="no" # option --rw: allow read/write access to container root file system
Shareipc="no" # option --ipc, set --ipc=host.
Sharenet="no" # option --net, set --ipc=net
Preservecachefiles="no" # if yes, dont delete cache files
Preservecontainer="no" # option '-p, --ps': if yes, preserve container instead of removing it with 'docker run --rm'
# X authentication
Xauthentication="yes" # option '--no-auth' use cookie authentication yes/no
Trusted="yes" # create trusted or untrusted cookies, see --trusted and --untrusted. Important for --hostdisplay and --kwin-native
Forcetrusted="no" # option --trusted: enforce trusted cookies for --hostdisplay and --kwin-native
Noxhost="no" # option '--no-xhost': if yes, disable all X server access granted by xhost
Xhost="" # option '--xhost': xhost + on new X server
# special options not starting X or docker
Checkorphaned="no" # option '--orphaned': check for non-removed containers and maybe root-owned files in cache
Createdesktopstarter="no" # option '--starter': create desktop starter and exit yes/no
Desktopfolder="" # " : Desktop folder of host user (xdg-user-dirs)
Installermode="" # options --install/--update/--remove
# some temporary or loop variables
Pid=""
Name=""
Zeit=""
Line=""
Count=""
# these window managers are known to work well with x11docker (alphabetical order)(excluding $Wm_not_recommended and $Wm_ugly):
Wm_good="amiwm blackbox cinnamon compiz ctwm enlightenment fluxbox flwm fvwm"
Wm_good="$Wm_good jwm kwin lxsession mate-session mate-wm marco metacity notion olwm olvwm openbox ororobus pekwm"
Wm_good="$Wm_good sawfish twm wmaker w9wm xfwm4"
# these wm's are recommended and lightweight, but cannot show desktop options. best first:
Wm_recommended_nodesktop_light="sawfish xfwm4 metacity marco mate-wm "
# these wm's are recommended and heavy, but cannot show desktop options (especially exiting themselves). best first:
Wm_recommended_nodesktop_heavy="kwin compiz"
# these wm's are recommended, lightweight AND desktop independent. best first:
Wm_recommended_desktop_light="flwm blackbox fluxbox jwm mwm wmaker afterstep amiwm fvwm ctwm pekwm olwm olvwm openbox"
# these wm's are recommended, heavy AND desktop independent. best first:
Wm_recommended_desktop_heavy="lxsession mate-session enlightenment cinnamon"
# these wm's are not really useful (please don't hit me) (best first):
Wm_not_recommended="awesome mutter muffin gnome-shell evilwm herbstluftwm i3 lwm matchbox miwm spectrwm subtle windowlab wmii wm2"
# these wm's cannot be autodetected by wmctrl if they are already running
Wm_nodetect="aewm aewm++ afterstep awesome ctwm mwm miwm olwm olvwm sapphire windowlab wm2 w9wm"
# these wm's can cause problems (they can be beautiful, though):
Wm_ugly="icewm sapphire aewm aewm++"
# these wm's doesn't work:
Wm_bad="clfswm tinywm tritium"
# List of all working window managers, recommended first: (excluding $Wm_bad)
Wm_all="$Wm_recommended_nodesktop_light $Wm_recommended_nodesktop_heavy $Wm_recommended_desktop_light $Wm_recommended_desktop_heavy $Wm_good $Wm_ugly $Wm_not_recommended $Wm_nodetect"
}
{ #### part: parsing cli options
Shortoptions="aAbcdeEfgGhHKml:MnNopPrsSutvw:WxXyY"
Longoptions="auto,x,X,xpra,xephyr,x11,xorg,hostdisplay,xwayland,weston-xwayland,xpra-xwayland,nxagent" # X servers
Longoptions="$Longoptions,weston,hostwayland,kwin,kwin-xwayland,kwin-native,xdummy,xvfb,nothing" # more X/Wayland servers
Longoptions="$Longoptions,wm:,desktop,exe,xonly"
Longoptions="$Longoptions,fullscreen,size:,glamor,scale:,rotate:,dpi:,output-count:,gpu" # screen options
Longoptions="$Longoptions,user:,home,clipboard,pulseaudio,xfishtank" # comfort options
Longoptions="$Longoptions,verbose,no-xhost,trusted,untrusted,dbus,waylandenv,pw:" # advanced options
Longoptions="$Longoptions,starter,orphaned,license,licence,help,version,install,update,remove" # special options without starting X server
Longoptions="$Longoptions,xhost:,no-auth,vt:,display:,env:,showenv,sharewayland,stdout,stderr,silent" # developer options
Longoptions="$Longoptions,ipc,net,ps,cache,cap-default,no-entrypoint,sudouser,hostuser:,rw" # developer options
Longoptions="$Longoptions,cachedir:,homedir:,westonini:,sharedir:" # developer options
Longoptions="$Longoptions,xsocket,tcp,tcpxsocket,virtualgl,glamor,volume:,xhost+,resizeable" # deprecated
Longoptions="$Longoptions,xpra-image,xpra-attach,xorg-image,xdummy-image,nopwd,no-password,root,sudo" # deprecated
Parsedoptions="$(getopt --options $Shortoptions --longoptions $Longoptions --name "$0" -- "$@" 2>/tmp/x11docker_parsererror)"
[ -e /tmp/x11docker_parsererror ] && Parsererror=$(cat /tmp/x11docker_parsererror) && rm /tmp/x11docker_parsererror
[ -n "$Parsererror" ] && error "$Parsererror"
eval set -- $Parsedoptions
[ "$*" = "-h --" ] && usage && exit 0 # catch single -h for usage info, otherwise it means --hostdisplay
while [ $# -gt 0 ] ; do
case "${1:-}" in
--help) usage && exit 0 ;; # show help/usage and exit
--license|--licence) license && exit 0 ;; # show MIT license and exit
--version) echo $Version && exit 0 ;; # output version number and exit
-e|--exe) X11dockermode="exe" ;; # execute application from host instead of running docker image
--xonly) X11dockermode="xonly" ;; # only create X erver
#### X servers
--auto) Autochooseserver="yes" ;; # use xpra or Xephyr, Xorg or hostdisplay, --xpra-xwayland or --weston-xwayland
-a|--xpra) Xserver="Xpra" ; Autochooseserver="no" ;; # use xpra on host
-y|--xephyr) Xserver="Xephyr" ; Autochooseserver="no" ;; # use Xephyr
-x|--xorg|--x11) Xserver="Xorg" ; Autochooseserver="no" ;; # use core Xorg
-h|--hostdisplay) Xserver="Hostdisplay" ; Autochooseserver="no" ;; # use host display :0 with shared X socket
-X|--xwayland) Xserver="Xwayland" ; Autochooseserver="no" ;; # Xwayland needs already running Wayland
-A|--xpra-xwayland) Xserver="Xpra-Xwayland" ; Autochooseserver="no" ;; # Xpra with Xwayland
-Y|--weston-xwayland) Xserver="Weston-Xwayland" ; Autochooseserver="no" ;; # Weston-Xwayland as Wayland compositor with Xwayland, runs in X or standalone from console
--xdummy) Xserver="Xdummy" ; Autochooseserver="no" ; Showdisplayenvironment="yes" ;; # use Xdummy. Invisible on host. For custom network setups with VNC or xpra
--xvfb) Xserver="Xvfb" ; Autochooseserver="no" ; Showdisplayenvironment="yes" ;; # use Xvfb. Invisible on host. For custom network setups with VNC or xpra
--nothing) Xserver="Nothing" ; Autochooseserver="no" ;; # Do not provide any X nor Wayland
-W|--weston) Xserver="Weston" ; Autochooseserver="no" ;; # Wayland in Weston only, no X
-H|--hostwayland) [ "$Xserver" = "Hostdisplay" ] || Xserver="Hostwayland" # share host wayland. Allow coexistence with option --hostdisplay
Sharewayland="yes" ; Autochooseserver="no" ;;
-K|--kwin) Xserver="Kwin" ; Autochooseserver="no" ;;
--kwin-xwayland) Xserver="Kwin-Xwayland" ; Autochooseserver="no" ;;
-N|--kwin-native) Xserver="Kwin-Native" ; Autochooseserver="no" # Seamless X and Wayland together
Sharewayland="yes" ; Setwaylandenv="yes"; Dbuslaunch="yes" ;;
-n|--nxagent) Xserver="Nxagent" ; Autochooseserver="no" ;;
#### Influencing X server
-d|--desktop) Desktopmode="yes" ;; # image contains a desktop environment.
-g|--gpu) Gpu="yes" ;; # share files in /dev/dri
-w|--wm) case ${2:-} in
""|"n"|"none") Windowmanager="none" ;;
"m"|"auto") Windowmanager="auto" ;;
*) Windowmanager=${2:-} ;;
esac
shift
Desktopmode="yes" ;;
#### Appearance
-f|--fullscreen) Fullscreen="yes" ;; # fullscreen mode for Xephyr and Weston
--size) Screensize="${2:-}" ; shift ;; # set virtual screen size
-l|--scale) Scaling=${2:-} ; shift ;; # zoom
--rotate) Rotation=${2:-} ; shift ;; # rotation and mirroring
--dpi) Dpi=${2:-} ; shift ;; # dots per inch / influences font size
--output-count) Outputcount="${2:-}" ; shift ;; # number of virtual outputs
--xfishtank) Xfishtank="yes" ;; # Run xfishtankon new X server
#### Options
-m|--home) Adduserhome="yes" ;; # share folder ~/x11docker/Imagename with container
-c|--clipboard) Shareclipboard="yes" ;; # share host clipboard with dockered applications (xpra only)
-p|--pulseaudio) Pulseaudio="yes" ;; # enable pulseaudio connection / sound support over tcp
#### Advanced options
-v|--verbose) Verbose="yes" ;; # be verbose
--stdout) Showstdout="yes" ;; # show stdout of image command
--stderr) Showstderr="yes" ;; # show stderr of image command
--silent) Silent="yes" ; exec 3>/dev/null ;; # do not show warnings or errors
-b|--dbus) Dbuslaunch="yes" ;; # run command with dbus-launch
-E|--waylandenv) Setwaylandenv="yes" ;; # set environment variables forcing toolkits like QTK and QT to use wayland
--no-entrypoint) Noentrypoint="yes" ;; # don't use ENTRYPOINT of image
--pw) Passwordprompt="${2:-}" ; shift ;; # frontend for password prompt
#### Developer options
## User settings
--user) Benutzer="${2:-}" ; shift ;; # set container user instead of host user
--hostuser) Hostuser="${2:-0}" # set host user different from logged in user
[ "$(echo $Hostuser | cut -c1)" = "-" ] && { ### FIXME: fuzzy validation, not reliable
warning "You are using --hostuser without an argument.
Maybe you are using it in deprecated form to have container user similar
to host user. That is default now. Now, option --hostuser expects an
argument to specify a different user than default user $(logname)"
Hostuser=""
} || shift ;;
--sudouser) Sudouser="yes" ;; # give container user sudo without password
## Environment
--showenv) Showdisplayenvironment="yes" ;; # output of display number and cookie file on stdout. Catch with ~$ read xdenv < <(x11docker --showenv)
--env) Customenvironment="$Customenvironment\n${2:-}" ; shift ;; # set custom environment variables
-S|--sharewayland) Sharewayland="yes" ;; # Share wayland socket
--vt) Newxvt="vt${2:-}" ; shift ;; # set virtual console to use
--display) Newdisplaynumber=${2:-} # display number to use