Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9ec7ae5
build: Add websocketd package
kroese Oct 8, 2025
6928907
fix: Terminate tail on exit
kroese Oct 8, 2025
ad3cb8e
Update display.sh
kroese Oct 8, 2025
05176f9
Update install.sh
kroese Oct 8, 2025
0d45407
Update start.sh
kroese Oct 8, 2025
21af41c
Update progress.sh
kroese Oct 8, 2025
f907eb9
Add socket.sh script to monitor message file
kroese Oct 8, 2025
f88cdb4
Update reset.sh
kroese Oct 8, 2025
a314f01
Implement websocket shutdown in network script
kroese Oct 8, 2025
0343295
Add WSD_PORT variable for websocket server port
kroese Oct 8, 2025
0726415
Update network.sh
kroese Oct 8, 2025
e1c9b9c
Update reset.sh
kroese Oct 8, 2025
663b060
Update script.js
kroese Oct 8, 2025
692db5c
Update script.js
kroese Oct 8, 2025
e6c8c9f
Update nginx.conf
kroese Oct 8, 2025
281ffb9
Update reset.sh
kroese Oct 8, 2025
f747c67
Rename location block from /msg to /status
kroese Oct 8, 2025
2e26d29
Revert
kroese Oct 8, 2025
e5ac344
Update script.js
kroese Oct 8, 2025
ac2e561
Update reset.sh
kroese Oct 8, 2025
1a12627
Update socket.sh
kroese Oct 8, 2025
b1461d2
Update Dockerfile
kroese Oct 8, 2025
4e28dfc
Remove and re-add iputils-ping in Dockerfile
kroese Oct 8, 2025
820055c
Update script.js
kroese Oct 8, 2025
db41b59
Update utils.sh
kroese Oct 8, 2025
86c6e4d
Implement KVM acceleration checks in reset.sh
kroese Oct 8, 2025
71f0ada
Remove KVM checks from proc.sh
kroese Oct 8, 2025
c8c4706
Update socket.sh
kroese Oct 8, 2025
4821077
Update socket.sh
kroese Oct 8, 2025
b0899f6
Update proc.sh
kroese Oct 8, 2025
a4e7906
Handle unknown events in socket.sh
kroese Oct 8, 2025
d43a338
Add error handling for case 'e' in script.js
kroese Oct 8, 2025
5e73b19
Update script.js
kroese Oct 8, 2025
0ad2553
Change delete event to delete_self in socket.sh
kroese Oct 8, 2025
a3676b8
Fix message parsing and error handling in script.js
kroese Oct 8, 2025
22b75ca
Update websocket error handling message
kroese Oct 8, 2025
88dedb9
Refactor VNC connection handling in script.js
kroese Oct 8, 2025
b68f53c
Update script.js
kroese Oct 8, 2025
ca2242d
Update script.js
kroese Oct 8, 2025
933e02b
Update reset.sh
kroese Oct 8, 2025
2f40d9f
Update entry.sh
kroese Oct 8, 2025
b76da42
Create server.sh
kroese Oct 8, 2025
1eab8e0
Update reset.sh
kroese Oct 8, 2025
003c485
Update proc.sh
kroese Oct 8, 2025
16240c7
Update socket.sh
kroese Oct 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ RUN set -eu && \
ethtool \
iptables \
iproute2 \
apt-utils \
dnsmasq \
xz-utils \
apt-utils \
net-tools \
e2fsprogs \
qemu-utils \
websocketd \
iputils-ping \
genisoimage \
inotify-tools \
netcat-openbsd \
ca-certificates \
qemu-system-x86 && \
Expand Down
2 changes: 2 additions & 0 deletions src/display.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ fi

addPackage "xserver-xorg-video-intel" "Intel GPU drivers"
addPackage "qemu-system-modules-opengl" "OpenGL module"

return 0
3 changes: 2 additions & 1 deletion src/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ set -Eeuo pipefail

cd /run

. start.sh # Placeholder
. start.sh # Startup hook
. utils.sh # Load functions
. reset.sh # Initialize system
. server.sh # Start webserver
. define.sh # Define images
. install.sh # Download image
. disk.sh # Initialize disks
Expand Down
2 changes: 2 additions & 0 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,5 @@ dst="$STORAGE/${base%.*}.$target_ext"
base=$(basename "$dst")
detectType "$STORAGE/$base" && return 0
error "Cannot convert file \"${base}\"" && exit 36

return 0
10 changes: 8 additions & 2 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ configureDNS() {
fi

if [[ "$DNSMASQ_DEBUG" == [Yy1]* ]]; then
tail -fn +0 "$log" &
tail -fn +0 "$log" --pid=$$ &
fi

return 0
Expand Down Expand Up @@ -229,6 +229,7 @@ getHostPorts() {

if [[ "${WEB:-}" != [Nn]* ]]; then
[ -z "$list" ] && list="$WEB_PORT" || list+=",$WEB_PORT"
[ -z "$list" ] && list="$WSD_PORT" || list+=",$WSD_PORT"
fi

if [[ "${NETWORK,,}" == "passt" ]]; then
Expand Down Expand Up @@ -369,7 +370,7 @@ configurePasst() {
fi

if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
tail -fn +0 "$log" &
tail -fn +0 "$log" --pid=$$ &
else
if [[ "$DEBUG" == [Yy1]* ]]; then
[ -f "$log" ] && cat "$log" && echo ""
Expand Down Expand Up @@ -555,6 +556,11 @@ closeNetwork() {
nginx -s stop 2> /dev/null
fWait "nginx"

# Shutdown websocket
local pid="/var/run/websocketd.pid"
[ -s "$pid" ] && pKill "$(<"$pid")"
rm -f "$pid"

fi

[[ "$NETWORK" == [Nn]* ]] && return 0
Expand Down
49 changes: 1 addition & 48 deletions src/proc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,14 @@ set -Eeuo pipefail
# Docker environment variables

: "${HV="Y"}"
: "${KVM:="Y"}"
: "${VMX:="N"}"
: "${CPU_FLAGS:=""}"
: "${CPU_MODEL:=""}"

[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring KVM..."

if [[ "$KVM" == [Nn]* ]]; then
warn "KVM acceleration is disabled, this will cause the machine to run about 10 times slower!"
else
if [[ "${ARCH,,}" != "amd64" ]]; then
KVM="N"
warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for x64 instructions, so the machine will run about 10 times slower."
fi
fi

if [[ "$KVM" != [Nn]* ]]; then

KVM_ERR=""

if [ ! -e /dev/kvm ]; then
KVM_ERR="(/dev/kvm is missing)"
else
if ! sh -c 'echo -n > /dev/kvm' &> /dev/null; then
KVM_ERR="(/dev/kvm is unwriteable)"
else
flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo)
if ! grep -qw "vmx\|svm" <<< "$flags"; then
KVM_ERR="(not enabled in BIOS)"
fi
fi
fi

if [ -n "$KVM_ERR" ]; then
KVM="N"
if [[ "$OSTYPE" =~ ^darwin ]]; then
warn "you are using macOS which has no KVM support, so the machine will run about 10 times slower."
else
kernel=$(uname -a)
case "${kernel,,}" in
*"microsoft"* )
error "Please bind '/dev/kvm' as a volume in the optional container settings when using Docker Desktop." ;;
*"synology"* )
error "Please make sure that Synology VMM (Virtual Machine Manager) is installed and that '/dev/kvm' is binded to this container." ;;
*)
error "KVM acceleration is not available $KVM_ERR, this will cause the machine to run about 10 times slower."
error "See the FAQ for possible causes, or disable acceleration by adding the \"KVM=N\" variable (not recommended)." ;;
esac
[[ "$DEBUG" != [Yy1]* ]] && exit 88
fi
fi

fi

vendor=$(lscpu | awk '/Vendor ID/{print $3}')
flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo)

if [[ "$KVM" != [Nn]* ]]; then

Expand Down
2 changes: 1 addition & 1 deletion src/progress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ do
if [ -s "$file" ]; then
bytes=$(du -sb "$file" | cut -f1)
if (( bytes > 1000 )); then
if [ -z "$total" ] || [[ "$total" == "0" ]]; then
if [ -z "$total" ] || [[ "$total" == "0" ]] || [ "$bytes" -gt "$total" ]; then
size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/')
else
size="$(echo "$bytes" "$total" | awk '{printf "%.1f", $1 * 100 / $2}')"
Expand Down
102 changes: 50 additions & 52 deletions src/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR

# Docker environment variables

: "${KVM:="Y"}" # KVM acceleration
: "${BOOT:=""}" # Path of ISO file
: "${DEBUG:="N"}" # Disable debugging
: "${MACHINE:="q35"}" # Machine selection
Expand Down Expand Up @@ -148,66 +149,63 @@ if [[ "$RAM_CHECK" != [Nn]* ]] && (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); th
info "$msg"
fi

addPackage() {
local pkg=$1
local desc=$2
# Check KVM support

if apt-mark showinstall | grep -qx "$pkg"; then
return 0
fi

MSG="Installing $desc..."
info "$MSG" && html "$MSG"

DEBIAN_FRONTEND=noninteractive apt-get -qq update
DEBIAN_FRONTEND=noninteractive apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null

return 0
}

: "${VNC_PORT:="5900"}" # VNC port
: "${MON_PORT:="7100"}" # Monitor port
: "${WEB_PORT:="8006"}" # Webserver port
: "${WSS_PORT:="5700"}" # Websockets port

if (( VNC_PORT < 5900 )); then
warn "VNC port cannot be set lower than 5900, ignoring value $VNC_PORT."
VNC_PORT="5900"
if [[ "${PLATFORM,,}" == "x64" ]]; then
TARGET="amd64"
else
TARGET="arm64"
fi

cp -r /var/www/* /run/shm
html "Starting $APP for $ENGINE..."

if [[ "${WEB:-}" != [Nn]* ]]; then

mkdir -p /etc/nginx/sites-enabled
cp /etc/nginx/default.conf /etc/nginx/sites-enabled/web.conf

user="admin"
[ -n "${USER:-}" ] && user="${USER:-}"

if [ -n "${PASS:-}" ]; then

# Set password
echo "$user:{PLAIN}${PASS:-}" > /etc/nginx/.htpasswd

sed -i "s/auth_basic off/auth_basic \"NoVNC\"/g" /etc/nginx/sites-enabled/web.conf

if [[ "$KVM" == [Nn]* ]]; then
warn "KVM acceleration is disabled, this will cause the machine to run about 10 times slower!"
else
if [[ "${ARCH,,}" != "$TARGET" ]]; then
KVM="N"
warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for ${PLATFORM^^} instructions, so the machine will run about 10 times slower."
fi
fi

sed -i "s/listen 8006 default_server;/listen $WEB_PORT default_server;/g" /etc/nginx/sites-enabled/web.conf
sed -i "s/proxy_pass http:\/\/127.0.0.1:5700\/;/proxy_pass http:\/\/127.0.0.1:$WSS_PORT\/;/g" /etc/nginx/sites-enabled/web.conf

# shellcheck disable=SC2143
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then

sed -i "s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf

if [[ "$KVM" != [Nn]* ]]; then

KVM_ERR=""

if [ ! -e /dev/kvm ]; then
KVM_ERR="(/dev/kvm is missing)"
else
if ! sh -c 'echo -n > /dev/kvm' &> /dev/null; then
KVM_ERR="(/dev/kvm is unwriteable)"
else
if [[ "${PLATFORM,,}" == "x64" ]]; then
flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo)
if ! grep -qw "vmx\|svm" <<< "$flags"; then
KVM_ERR="(not enabled in BIOS)"
fi
fi
fi
fi

# Start webserver
nginx -e stderr
if [ -n "$KVM_ERR" ]; then
KVM="N"
if [[ "$OSTYPE" =~ ^darwin ]]; then
warn "you are using macOS which has no KVM support, so the machine will run about 10 times slower."
else
kernel=$(uname -a)
case "${kernel,,}" in
*"microsoft"* )
error "Please bind '/dev/kvm' as a volume in the optional container settings when using Docker Desktop." ;;
*"synology"* )
error "Please make sure that Synology VMM (Virtual Machine Manager) is installed and that '/dev/kvm' is binded to this container." ;;
*)
error "KVM acceleration is not available $KVM_ERR, this will cause the machine to run about 10 times slower."
error "See the FAQ for possible causes, or disable acceleration by adding the \"KVM=N\" variable (not recommended)." ;;
esac
[[ "$DEBUG" != [Yy1]* ]] && exit 88
fi
fi

fi

html "Starting $APP for $ENGINE..."

return 0
55 changes: 55 additions & 0 deletions src/server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -Eeuo pipefail

: "${VNC_PORT:="5900"}" # VNC port
: "${MON_PORT:="7100"}" # Monitor port
: "${WEB_PORT:="8006"}" # Webserver port
: "${WSD_PORT:="8004"}" # Websockets port
: "${WSS_PORT:="5700"}" # Websockets port

if (( VNC_PORT < 5900 )); then
warn "VNC port cannot be set lower than 5900, ignoring value $VNC_PORT."
VNC_PORT="5900"
fi

cp -r /var/www/* /run/shm
rm -f /var/run/websocketd.pid

if [[ "${WEB:-}" != [Nn]* ]]; then

mkdir -p /etc/nginx/sites-enabled
cp /etc/nginx/default.conf /etc/nginx/sites-enabled/web.conf

user="admin"
[ -n "${USER:-}" ] && user="${USER:-}"

if [ -n "${PASS:-}" ]; then

# Set password
echo "$user:{PLAIN}${PASS:-}" > /etc/nginx/.htpasswd

sed -i "s/auth_basic off/auth_basic \"NoVNC\"/g" /etc/nginx/sites-enabled/web.conf

fi

sed -i "s/listen 8006 default_server;/listen $WEB_PORT default_server;/g" /etc/nginx/sites-enabled/web.conf
sed -i "s/proxy_pass http:\/\/127.0.0.1:5700\/;/proxy_pass http:\/\/127.0.0.1:$WSS_PORT\/;/g" /etc/nginx/sites-enabled/web.conf
sed -i "s/proxy_pass http:\/\/127.0.0.1:8004\/;/proxy_pass http:\/\/127.0.0.1:$WSD_PORT\/;/g" /etc/nginx/sites-enabled/web.conf

# shellcheck disable=SC2143
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then

sed -i "s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf

fi

# Start webserver
nginx -e stderr

# Start websocket server
websocketd --address 127.0.0.1 --port="$WSD_PORT" /run/socket.sh >/var/log/websocketd.log &
echo "$!" > /var/run/websocketd.pid

fi

return 0
12 changes: 12 additions & 0 deletions src/socket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -Eeuo pipefail

path="/run/shm/msg.html"

inotifywait -m "$path" |
while read -r fp event fn; do
case "${event,,}" in
"modify" ) echo -n "s: " && cat "$path" ;;
"delete_self" ) echo "c: vnc" ;;
esac
done
4 changes: 3 additions & 1 deletion src/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
set -Eeuo pipefail

# Override this placeholder file using a Docker bind to execute a script during startup!
# You can override this hook to execute a script before startup!

return 0
17 changes: 17 additions & 0 deletions src/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,21 @@ hasDisk() {
return 1
}

addPackage() {
local pkg=$1
local desc=$2

if apt-mark showinstall | grep -qx "$pkg"; then
return 0
fi

local msg="Installing $desc..."
info "$msg" && html "$msg"

DEBIAN_FRONTEND=noninteractive apt-get -qq update
DEBIAN_FRONTEND=noninteractive apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null

return 0
}

return 0
14 changes: 14 additions & 0 deletions web/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ server {

}

location /status {

proxy_http_version 1.1;

proxy_set_header Connection 'upgrade';
proxy_set_header Upgrade $http_upgrade;

proxy_buffering off;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;

proxy_pass http://127.0.0.1:8004/;
}

location /websockify {

proxy_http_version 1.1;
Expand Down
Loading