diff --git a/docker/Dockerfile.ubuntu18.doom b/docker/Dockerfile.ubuntu18.doom new file mode 100644 index 0000000..8e29ef7 --- /dev/null +++ b/docker/Dockerfile.ubuntu18.doom @@ -0,0 +1,62 @@ +FROM ubuntu:18.04 + +ENV DISPLAY=:1 \ + VNC_PORT=8443 \ + VNC_RESOLUTION=1280x720 \ + MAX_FRAME_RATE=24 \ + VNCOPTIONS="-PreferBandwidth -DynamicQualityMin=4 -DynamicQualityMax=7" \ + HOME=/home/user \ + TERM=xterm \ + STARTUPDIR=/dockerstartup \ + INST_SCRIPTS=/dockerstartup/install \ + KASM_RX_HOME=/dockerstartup/kasmrx \ + DEBIAN_FRONTEND=noninteractive \ + VNC_COL_DEPTH=24 \ + VNC_RESOLUTION=1280x1024 \ + VNC_PW=vncpassword \ + VNC_USER=user \ + VNC_VIEW_ONLY_PW=vncviewonlypassword \ + LD_LIBRARY_PATH=/usr/local/lib/ \ + OMP_WAIT_POLICY=PASSIVE \ + SHELL=/bin/bash \ + SINGLE_APPLICATION=1 + +EXPOSE $VNC_PORT + +WORKDIR $HOME + +### REQUIRED STUFF ### + +RUN apt-get update && apt-get install -y supervisor xfce4 xfce4-terminal xterm libnss-wrapper gettext libjpeg-dev wget +RUN apt-get purge -y pm-utils xscreensaver* + +RUN mkdir -p $STARTUPDIR +COPY src/startup/ $STARTUPDIR +RUN mkdir -p $HOME/.config/xfce4/xfconf/xfce-perchannel-xml +COPY src/xfce/ $HOME/.config/xfce4/xfconf/xfce-perchannel-xml +# overwite default with single app config +RUN mv $HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop-single-app.xml $HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml +RUN echo 'source $STARTUPDIR/generate_container_user' >> $HOME/.bashrc + +# KasmVNC install +RUN wget -qO- https://github.com/kasmtech/KasmVNC/releases/download/v0.9.1-beta/KasmVNC_0.9.1-beta_Ubuntu_18.04.tar.gz | tar xz --strip 1 -C / + +### START CUSTOM STUFF #### + +# We need the server to use a fixed resulution and have the client scale, which is not the default behavior of KasmVNC +RUN sed -i "s#UI.initSetting('resize', 'remote');#UI.initSetting('resize', 'scale');#" /usr/local/share/kasmvnc/www/app/ui.js + +RUN apt-get install -y chocolate-doom doom-wad-shareware prboom-plus freedoom + +# Use software rendering, comment this out if you have a GPU +#RUN mkdir -p $HOME/.local/share/chocolate-doom && \ +# echo 'force_software_renderer 1' > $HOME/.local/share/chocolate-doom/chocolate-doom.cfg + + +### END CUSTOM STUFF ### + +RUN chown -R 1000:0 $HOME +USER 1000 +WORKDIR $HOME + +ENTRYPOINT [ "/dockerstartup/vnc_startup.sh", "xfce4-terminal", "-e", "/usr/games/chocolate-doom" ] diff --git a/docker/src/startup/generate_container_user b/docker/src/startup/generate_container_user new file mode 100755 index 0000000..b259e7c --- /dev/null +++ b/docker/src/startup/generate_container_user @@ -0,0 +1,37 @@ +# Set current user in nss_wrapper +USER_ID=$(id -u) +GROUP_ID=$(id -g) +echo "USER_ID: $USER_ID, GROUP_ID: $GROUP_ID" + +# Attempt to set the username to the kasm username +USERNAME=${VNC_USER:-default} +# Make the username posix compliant +USERNAME=$(echo "$USERNAME" | sed -r 's#[^a-zA-Z0-9\._\-]#_#g') +if ! echo "$USERNAME" | grep -qP "^[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*"; then + USERNAME="default" +fi +export PS1="$USERNAME:\w\$ " + +if [ x"$USER_ID" != x"0" ]; then + + NSS_WRAPPER_PASSWD=/tmp/passwd + NSS_WRAPPER_GROUP=/etc/group + + cat /etc/passwd > $NSS_WRAPPER_PASSWD + + echo "${USERNAME}:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/bin/bash" >> $NSS_WRAPPER_PASSWD + + export NSS_WRAPPER_PASSWD + export NSS_WRAPPER_GROUP + + if [ -r /usr/lib/libnss_wrapper.so ]; then + LD_PRELOAD=/usr/lib/libnss_wrapper.so + elif [ -r /usr/lib64/libnss_wrapper.so ]; then + LD_PRELOAD=/usr/lib64/libnss_wrapper.so + else + echo "no libnss_wrapper.so installed!" + exit 1 + fi + echo "nss_wrapper location: $LD_PRELOAD" + export LD_PRELOAD +fi diff --git a/docker/src/startup/vnc_startup.sh b/docker/src/startup/vnc_startup.sh new file mode 100755 index 0000000..42ff912 --- /dev/null +++ b/docker/src/startup/vnc_startup.sh @@ -0,0 +1,68 @@ +#!/bin/bash +### every exit != 0 fails the script +set -e + +# should also source $STARTUPDIR/generate_container_user +source $HOME/.bashrc + +## correct forwarding of shutdown signal +cleanup () { + kill -s SIGTERM $! + exit 0 +} +trap cleanup SIGINT SIGTERM + +## resolve_vnc_connection +VNC_IP=$(hostname -i) + +# first entry is control, second is view (if only one is valid for both) +mkdir -p "$HOME/.vnc" +PASSWD_PATH="$HOME/.vnc/passwd" +echo "$VNC_PW" | kasmvncpasswd -f > $HOME/.kasmpasswd +chmod 0600 $HOME/.kasmpasswd +openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout $HOME/.vnc/self.pem -out $HOME/.vnc/self.pem -subj "/C=US/ST=VA/L=None/O=None/OU=DoFu/CN=kasm/emailAddress=none@none.none" + +vncserver :1 -interface 0.0.0.0 +vncserver -kill :1 + +if [[ -f $PASSWD_PATH ]]; then + rm -f $PASSWD_PATH +fi + +#echo "$VNC_PW" | vncpasswd -f > $PASSWD_PATH +#echo "$VNC_VIEW_ONLY_PW" | vncpasswd -f >> $PASSWD_PATH +#chmod 600 $PASSWD_PATH + +unset VNC_VIEW_ONLY_PW +unset VNC_PW + +if [[ $DEBUG == true ]]; then + echo -e "\n------------------ start VNC server ------------------------" + echo "remove old vnc locks to be a reattachable container" +fi +vncserver -kill $DISPLAY &> $HOME/.vnc/vnc_startup.log \ + || rm -rfv /tmp/.X*-lock /tmp/.X11-unix &> $HOME/.vnc/vnc_startup.log \ + || echo "no locks present" + +echo -e "start vncserver with param: VNC_COL_DEPTH=$VNC_COL_DEPTH, VNC_RESOLUTION=$VNC_RESOLUTION\n..." +vncserver $DISPLAY -depth $VNC_COL_DEPTH -geometry $VNC_RESOLUTION -FrameRate=$MAX_FRAME_RATE -websocketPort $VNC_PORT -cert $HOME/.vnc/self.pem -sslOnly -interface 0.0.0.0 $VNCOPTIONS #&> $STARTUPDIR/no_vnc_startup.log + +PID_SUN=$! + +echo -e "start window manager\n..." +$STARTUPDIR/window_manager_startup.sh #&> $STARTUPDIR/window_manager_startup.log + +## log connect options +echo -e "\n\n------------------ VNC environment started ------------------" +echo -e "\nVNCSERVER started on DISPLAY= $DISPLAY \n\t=> connect via VNC viewer with $VNC_IP:$VNC_PORT" +echo -e "\nnoVNC HTML client started:\n\t=> connect via http://$VNC_IP:$NO_VNC_PORT/?password=...\n" +echo "WEB PID: $PID_SUB" + +# tail vncserver logs +tail -f $HOME/.vnc/*$DISPLAY.log & + +eval "$@" + +wait $PID_SUB + +echo "Exiting Kasm container" diff --git a/docker/src/startup/window_manager_startup.sh b/docker/src/startup/window_manager_startup.sh new file mode 100755 index 0000000..d5e1774 --- /dev/null +++ b/docker/src/startup/window_manager_startup.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -e + +echo -e "\n------------------ Xfce4 window manager startup------------------" + +### disable screen saver and power management +xset -dpms & +xset s noblank & +xset s off & + +if [ "$SINGLE_APPLICATION" -eq "1" ]; then + echo "Configured of Single Application Mode" + sed -i "s/O|SHMC/|/g" $HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml + #xfwm4 --daemon +fi diff --git a/docker/src/xfce/xfce4-desktop-single-app.xml b/docker/src/xfce/xfce4-desktop-single-app.xml new file mode 100644 index 0000000..8b30c0e --- /dev/null +++ b/docker/src/xfce/xfce4-desktop-single-app.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker/src/xfce/xfce4-desktop.xml b/docker/src/xfce/xfce4-desktop.xml new file mode 100644 index 0000000..b76cbea --- /dev/null +++ b/docker/src/xfce/xfce4-desktop.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker/src/xfce/xfce4-keyboard-shortcuts.xml b/docker/src/xfce/xfce4-keyboard-shortcuts.xml new file mode 100644 index 0000000..4e2cea2 --- /dev/null +++ b/docker/src/xfce/xfce4-keyboard-shortcuts.xml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker/src/xfce/xfce4-panel.xml b/docker/src/xfce/xfce4-panel.xml new file mode 100644 index 0000000..df7cdd4 --- /dev/null +++ b/docker/src/xfce/xfce4-panel.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker/src/xfce/xfce4-session.xml b/docker/src/xfce/xfce4-session.xml new file mode 100644 index 0000000..cc2b30c --- /dev/null +++ b/docker/src/xfce/xfce4-session.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker/src/xfce/xfwm4.xml b/docker/src/xfce/xfwm4.xml new file mode 100644 index 0000000..28e861c --- /dev/null +++ b/docker/src/xfce/xfwm4.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker/src/xfce/xsettings.xml b/docker/src/xfce/xsettings.xml new file mode 100644 index 0000000..3324472 --- /dev/null +++ b/docker/src/xfce/xsettings.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +