commit 2a3eb9218efe6ec6ae9c67ff4ddaa3cc6896a2ea Author: Jens Ahrensfeld Date: Fri May 31 19:13:10 2024 +0200 Initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3415787 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# syntax=docker/dockerfile:1 +FROM jayfield/novnc-baseimage + +RUN apt-get update && \ + apt-get -y install --no-install-recommends dosbox unzip alsa-utils smbclient && \ + rm -rf /var/lib/apt/lists/* + +RUN openssl req -x509 -nodes -newkey rsa:2048 -keyout /tmp/novnc.key -out /tmp/novnc.pem -days 3650 -subj "/C=US/ST=NY/L=NY/O=NY/OU=NY/CN=NY emailAddress=email@example.com" +ENV DISPLAY_NUM=99 +ENV DISPLAY=:${DISPLAY_NUM} +RUN touch /root/.Xauthority + +ENV GAMES_HOME=/opt/games +ENV SCRIPTS_HOME=/opt/scripts +ENV PATH=${PATH}:${SCRIPTS_HOME} + +ADD scripts ${SCRIPTS_HOME} +WORKDIR /tmp/apps +RUN smbget -au smb://vlda-01/software/Games/dosbox/stuntcar.zip +RUN smbget -au smb://vlda-01/software/Games/dosbox/t7g.zip + +RUN mkdir -p ${GAMES_HOME} +RUN unzip -o -d ${GAMES_HOME} "/tmp/apps/*.zip" +RUN rm -rf /tmp/apps +RUN cd ~ + +EXPOSE 60${DISPLAY_NUM} +EXPOSE 5900 + +ENTRYPOINT ["/opt/scripts/server_start.sh", "/opt/scripts/server.sh"] + +# see also +# https://github.com/ich777/docker-krusader diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/game.sh b/game.sh new file mode 100755 index 0000000..af47ca4 --- /dev/null +++ b/game.sh @@ -0,0 +1,4 @@ +#/bin/bash + +docker exec -it dosbox-novnc start_game.sh $1 + diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..bbe6a45 --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#/bin/bash + +docker run --name dosbox-novnc -d --rm --net bridge -e SCREEN_W=1536 -e SCREEN_H=960 --device /dev/snd jayfield/dosbox-novnc + diff --git a/scripts/server.sh b/scripts/server.sh new file mode 100755 index 0000000..90eb171 --- /dev/null +++ b/scripts/server.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -x + +RFB_PORT=59${DISPLAY_NUM} +NOVNC_PORT=80${DISPLAY_NUM} + +echo Display at ${DISPLAY} with ${SCREEN_W}x${SCREEN_H}x24 +/opt/TurboVNC/bin/Xvnc ${DISPLAY} -geometry ${SCREEN_W}x${SCREEN_H} -depth 24 +xinerama -securitytypes none >/var/log/xvfb.log & +fluxbox & +/tmp/websockify/run -D --web=/tmp/noVNC/ --cert=/tmp/novnc.pem --key=/tmp/novnc.key ${NOVNC_PORT} localhost:${RFB_PORT} diff --git a/scripts/server_start.sh b/scripts/server_start.sh new file mode 100755 index 0000000..20c662f --- /dev/null +++ b/scripts/server_start.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +APP=$1 +set -x + +# Signal helper +source /opt/scripts/signals.sh + +PID=0 +TERM_handler() { + SIGNAME="$1" + echo "Killing ${PID}" + echo "Signal ${SIGNAME}" + if [ ${PID} -ne 0 ]; then + ps -ef --forest + CHILDS=$(pgrep -P "${PID}") + kill -"${SIGNAME}" -"${PID}" + for i in $CHILDS; do + wait $i + done + fi + ps -ef --forest + ret=$(signal_return_val ${SIGNAME}) + exit $ret +} + +signals_trap_with_arg TERM_handler SIGTERM +${APP} & +PID=$$ + +# wait forever +signals_wait_forever + +# https://docs.docker.com/compose/faq/ +# https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86 \ No newline at end of file diff --git a/scripts/signals.sh b/scripts/signals.sh new file mode 100644 index 0000000..bd48be3 --- /dev/null +++ b/scripts/signals.sh @@ -0,0 +1,25 @@ +signals_trap_with_arg() { + func="$1" ; shift + for sig ; do + echo "$func $sig" + trap "$func $sig" "$sig" + done +} + +signals_wait_forever() { + while true + do + tail -f /dev/null & wait ${!} + done +} + +signal_name_to_number() { + SIGNAME="$1" + trap -l | sed -nr "s/.*\b([0-9]+)\) $SIGNAME.*/\1/p" +} + +signal_return_val() { + SIGNAME="$1" + SIGNUM=$(signal_name_to_number ${SIGNAME}) + echo "128 + $SIGNUM" | bc +} diff --git a/scripts/start_game.sh b/scripts/start_game.sh new file mode 100755 index 0000000..09fac91 --- /dev/null +++ b/scripts/start_game.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +DOSBOX_VERSION="0.74-3" + +NAME="$1" +APPDIR=${GAMES_HOME}/${NAME} +DOSBOX_CONFIG=${APPDIR}/dosbox-${DOSBOX_VERSION}.conf + +dosbox ${APPDIR}/run.bat -conf ${DOSBOX_CONFIG} + +# https://docs.docker.com/compose/faq/ +# https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86