Skip to content

Commit

Permalink
Change shebang to /usr/bin/env bash for portability. #83
Browse files Browse the repository at this point in the history
  • Loading branch information
mviereck committed Nov 22, 2018
1 parent a690b96 commit c921b2a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ x11docker assumes that you want to run a single application in seamless mode, i.
- You can specify a host window manager with option `--wm WINDOWMANAGER`, for example `--wm openbox`.
- Desktop mode with `--desktop` is supported with all X server options except `--hostdisplay`. If available, x11docker prefers `--xephyr` and `--nxagent`.

## Shared folders and HOME in container
Changes in a running docker container system will be lost, the created docker container will be discarded. For persistent data storage you can share host directories:
- Option `-m, --home` creates a host directory in `~/x11docker/IMAGENAME` that is shared with the container and mounted as its `HOME` directory. Files in container home and configuration changes will persist.
- Option `--sharedir DIR` mounts a host directory at the same location in container. `--sharedir DIR:ro` restricts to read-only access.
- Option `--homedir DIR` is similar to `--home` but allows you to specify a custom host directory for data storage.
- Special cases for `$HOME`:
- `--homedir $HOME` will use your host home as container home. Discouraged, use with care.
- `--sharedir $HOME` will symlink your host home as a subfolder of container home.

## Hardware acceleration
Hardware acceleration for OpenGL is possible with option `-g, --gpu`.
- This will work out of the box in most cases with open source drivers on host. Otherwise have a look at [Dependencies](#option-dependencies).
Expand Down Expand Up @@ -125,15 +134,6 @@ x11docker provides option `--lang $LANG` for flexible language locale settings.
- If x11docker does not find the locale, it creates it on container startup. (Needs package `locales` in image.)
- Examples: `--lang de` for German, `--lang zh_CN` for Chinese, `--lang ru` for Russian, `--lang $LANG` for your host locale.
- For support of chinese, japanese and korean characters install a font like `fonts-arphic-uming` in image.

## Shared folders and HOME in container
Changes in a running docker container system will be lost, the created docker container will be discarded. For persistent data storage you can share host directories:
- Option `-m, --home` creates a host directory in `~/x11docker/IMAGENAME` that is shared with the container and mounted as its `HOME` directory. Files in container home and configuration changes will persist.
- Option `--sharedir DIR` mounts a host directory at the same location in container. `--sharedir DIR:ro` restricts to read-only access.
- Option `--homedir DIR` is similar to `--home` but allows you to specify a custom host directory for data storage.
- Special cases for `$HOME`:
- `--homedir $HOME` will use your host home as container home. Discouraged, use with care.
- `--sharedir $HOME` will symlink your host home as a subfolder of container home.

## Wayland
To run [Wayland](https://wayland.freedesktop.org/) instead of an X server x11docker provides options `--wayland`, `--weston`, `--kwin` and `--hostwayland`.
Expand Down
51 changes: 30 additions & 21 deletions x11docker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#! /usr/bin/env bash

# x11docker
# Run GUI applications and desktop environments in docker
Expand All @@ -11,14 +11,14 @@
# Type 'x11docker --help' or scroll down to read usage information.
# More documentation at: https://github.com/mviereck/x11docker

Version="5.3.3"
Version="5.3.4-beta"

usage() { # --help: show usage information
echo "
x11docker: Run GUI applications and desktop environments in docker.
Usage:
To run a docker image with new X server (auto-choosing X server):
To run a docker image with new X server:
x11docker [OPTIONS] IMAGE [COMMAND]
x11docker [OPTIONS] -- IMAGE [COMMAND [ARG1 ARG2 ...]]
x11docker [OPTIONS] -- DOCKER_RUN_OPTIONS -- IMAGE [COMMAND [ARG1 ARG2 ...]]
Expand Down Expand Up @@ -249,6 +249,7 @@ Init system and DBus daemon:
--hostdbus Connect to DBus session from host.
Container capabilities:
Custom capabilities can be added with --cap-add=CAP after --
--hostipc Sets docker option --ipc=host, disables IPC namespacing.
Severe reduction of container isolation! Shares
host interprocess communication and shared memory.
Expand All @@ -259,7 +260,6 @@ Container capabilities:
--cap-default Allow default docker container capabilities and
disable container security hardening of x11docker.
--sys-admin Add capability SYS_ADMIN. Please avoid that.
Custom capabilities can be added with --cap-add=CAP after --
Miscellaneous:
--launcher Create application launcher on desktop and exit.
Expand Down Expand Up @@ -353,14 +353,14 @@ $Message" | gxmessage -file - -default okay ||:
} || {
[ -n "$Anyterminal" ] && [ -e "$Cachefolder" ] && [ "$Xserver" != "--tty" ] && {
mkfile $Cachefolder/message
echo "#! /bin/bash
echo "#! /usr/bin/env bash
echo '$Title
$Message
(Press any key to close window)'
read -n1
" >> $Cachefolder/message
$Anyterminal /bin/bash $Cachefolder/message
$Anyterminal /usr/bin/env bash $Cachefolder/message
:
}
} || {
Expand Down Expand Up @@ -760,6 +760,15 @@ verlte() { # version number check $1 less than or equal $2
verlt() { # version number check $1 less than $2
[ "${1:-}" = "${2:-}" ] && return 1 || { verlte "${1:-}" "${2:-}" && return 0 || return 1 ; }
}
check_parent_sshd() { # check whether pid $1 runs in SSH session
local Wanted_pid="${1:-}" Process_line
while [ $Wanted_pid -ne 1 ] ; do
Process_line="$(ps -f -p "$Wanted_pid"| tail -n1)"
Wanted_pid="$(echo $Process_line| awk '{print $3}')"
[[ $Process_line =~ sshd ]] && return 0
done
return 1
}
getrandomnumber() { # get random number
# chosen by fair dice roll
# guaranteed to be random
Expand Down Expand Up @@ -1619,7 +1628,7 @@ setup_clipboard() { # option --clipboard: create shareclipboard scri
Clipreceive=""
}

echo "#! /bin/bash
echo "#! /usr/bin/env bash
# share clipboard between X servers $Hostdisplay and $Newdisplay
while [ ! -s "$Timetosaygoodbye" ] ; do
Expand Down Expand Up @@ -2892,7 +2901,7 @@ mode=$Screensize
# fake NXclient
export NX_CLIENT="$Cachefolder/nx_client"
mkfile "$NX_CLIENT"
echo '#! /bin/bash
echo '#! /usr/bin/env bash
# helper script to terminate nxagent.
# nxagent runs program noted in NX_CLIENT if window close button is pressed.
# (real nxclient does not exist)
Expand Down Expand Up @@ -3844,7 +3853,7 @@ create_dockerrc() { # create dockerrc: This script runs as root (or
# check and set up cgroup on host for systemd or elogind
# run docker
local Line= Wantcgroup=
echo "#! /bin/bash"
echo "#! /usr/bin/env bash"

declare -f mkfile
declare -f rocknroll
Expand Down Expand Up @@ -3898,7 +3907,7 @@ create_dockerrc() { # create dockerrc: This script runs as root (or
echo "# check whether image is available locally"
echo "$Dockerexe inspect --type=image $Imagename >/dev/null 2>&1 || {"
[ "$Pullterminal" = "$Passwordterminal" ] && [ "$Passwordneeded" = "yes" ] && Pullterminal=""
echo " env $Terminalxenv $Pullterminal /bin/bash $Pullrc"
echo " env $Terminalxenv $Pullterminal /usr/bin/env bash $Pullrc"
echo " waitforfilecreation $Cachefolder/pullterminalready 5 && {"
echo " rm $Cachefolder/pullterminalready"
echo " waitforfilecreation $Cachefolder/pullready infinity ||:"
Expand Down Expand Up @@ -4451,7 +4460,7 @@ exec setsid agetty -a \$Containeruser -l /usr/local/bin/x11docker-login console
;;
runit)
echo "# create and enable x11docker service containing image command"
#echo "echo 'FAKE_SHELL /usr/bin/bash' >> /etc/login.defs"
#echo "echo 'FAKE_SHELL /bin/bash' >> /etc/login.defs"
echo "mkdir -p /etc/sv/x11docker"
echo "echo \"#! /bin/sh
waitforservice() {
Expand Down Expand Up @@ -4742,7 +4751,7 @@ exit 0\" >> /etc/rc.local"
return 0
} >> $Containerrootrc
create_pullrc() { # create pullrc: interactive script to pull image from docker hub
echo "#! /bin/bash"
echo "#! /usr/bin/env bash"
#[ "$Debugmode" = "yes" ] && echo "set -x"
declare -f rmcr
echo "touchpullready() {"
Expand All @@ -4763,7 +4772,7 @@ create_pullrc() { # create pullrc: interactive script to pull imag
return 0
} >> $Pullrc
create_xtermrc() { # create xtermrc: script to prompt for password and to run dockerrc
echo "#! /bin/bash"
echo "#! /usr/bin/env bash"
#[ "$Debugmode" = "yes" ] && echo "set -x"
echo "touchxtermready() {"
echo " $Mksu 'touch $Cachefolder/xtermready'"
Expand Down Expand Up @@ -4895,11 +4904,11 @@ start_docker() { # start docker container
[ "$Passwordterminal" = "bash -c" ] && Passwordterminal=""
#[ -z "$Passwordterminal" ] && exec </dev/tty
case $Passwordneeded in
no) /bin/bash $Xtermrc ;;
yes) $Passwordterminal /bin/bash $Xtermrc ;;
no) /usr/bin/env bash $Xtermrc ;;
yes) $Passwordterminal /usr/bin/env bash $Xtermrc ;;
esac
;;
*) $Passwordterminal "/bin/bash $Xtermrc" ;;
*) $Passwordterminal "/usr/bin/env bash $Xtermrc" ;;
esac
waitforfilecreation $Cachefolder/xtermready infinity

Expand Down Expand Up @@ -4932,7 +4941,7 @@ start_hostexe() { # options --exe, --xonly: Run host executeable i
local Hostexepid=

# create start script
{ echo "#! /bin/bash"
{ echo "#! /usr/bin/env bash"
#[ "$Debugmode" = "yes" ] && echo "set -Eux"
echo "storepid() {"
echo " echo \${1:-} \${2:-} >> $Bgpidfile"
Expand Down Expand Up @@ -5101,10 +5110,10 @@ check_host() { # check host environment
export -f rmcr

# Check whether x11docker runs over SSH
pstree -ps $$ 2>/dev/null | grep -q sshd && Hostssh="yes" || Hostssh="no" ### FIXME pstree is not available everywhere
command -v pstree >/dev/null || {
[ "${SSH_CLIENT:-}" ] && Hostssh="yes" || note "Could not check whether x11docker is running over ssh.
Please install pstree."
command -v pstree >/dev/null && {
pstree -ps $$ | grep -q sshd && Hostssh="yes" || Hostssh="no"
} || {
check_parent_sshd "$$" && Hostssh="yes" || Hostssh="no"
}

# Check whether x11docker runs on X or on tty
Expand Down

0 comments on commit c921b2a

Please sign in to comment.