dockeraur/dockergui

88 lines
1.9 KiB
Text
Raw Normal View History

#!/usr/bin/env bash
if [ "$#" -lt 1 ]; then
echo "Usage: ./run.sh command [arguments]"
exit 1
fi
# Find free display number
for ((DNum=1 ; DNum <= 100 ; DNum++)) ; do
[ -e /tmp/.X11-unix/X$DNum ] || break
done
RESOLUTION=1920x1080
# Start nested X Server
Xephyr :$DNum \
-extension MIT-SHM \
-extension XTEST \
-nolisten tcp \
-screen $RESOLUTION \
-resizeable &
xephyrpid=$!
# If simple ratpoison window manager exists, run it
if command -v ratpoison; then
sleep 1
ratpoison -d :$DNum &
2019-12-28 14:10:43 -05:00
else # Use the default x window manager installed based on lsb_release id
2019-12-29 11:50:36 -05:00
DISPLAY=:$DNum
distro_id=$(lsb_release -i | awk '{print($3)}')
if [ "${distro_id}" == "Ubuntu" ] || [ "${distro_id}" == "Debian" ]; then
x-window-manager &
else
2019-12-28 22:14:14 -05:00
if [ "${XDG_SESSION_DESKTOP}" == "KDE" ]; then
startplasma-x11 &
elif [ "${XDG_SESSION_DESKTOP}" == "GNOME" ]; then
mutter &
2019-12-29 11:50:36 -05:00
else
printf "%s\n" "Could not find a suitable Window Manager"
exit 1
2019-12-28 22:14:14 -05:00
fi
fi
fi
2019-12-28 14:10:43 -05:00
windowmanagerpid=$!
2019-12-28 14:10:43 -05:00
#detect podman or docker
if command -v docker; then
2019-12-28 19:38:58 -05:00
engine_of_choice="docker"
2019-12-28 14:10:43 -05:00
elif command -v podman; then
2019-12-28 19:38:58 -05:00
engine_of_choice="podman"
2019-12-29 11:50:36 -05:00
else
printf "%s\n" "Docker/Podman are not installed!"
exit 1
2019-12-28 19:38:58 -05:00
fi
2019-12-28 14:10:43 -05:00
2019-12-28 19:38:58 -05:00
# then run the detected container engine
2019-12-28 14:10:43 -05:00
2019-12-28 19:38:58 -05:00
$engine_of_choice run --net=host \
2019-12-28 14:10:43 -05:00
--rm \
-e DISPLAY=:$DNum \
-v /tmp/.X11-unix/X$DNum:/tmp/.X11-unix/X$DNum:rw \
--user $(id -u):$(id -g) \
--group-add audio \
--cap-drop=ALL \
--shm-size 2g \
"$@"
kill $windowmanagerpid
kill $xephyrpid
## Explanation of docker parameters
# --net=host is to access the X server
# --rm is to remove the container when finished
# The next two lines is to pass along the X server socket and display
# --user is to set user to be non-root
# --cap-drop=ALL is to drop all priviledges
# --shm-size 2g is to increase shared memory
# $@ is to pass along the rest of the arguments