From 0d8874c367516d33edca6694842aa54e1f8bae86 Mon Sep 17 00:00:00 2001 From: merith-tk Date: Mon, 2 Jun 2025 23:27:05 +0100 Subject: [PATCH] Add vnc.sh --- vnc.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 vnc.sh diff --git a/vnc.sh b/vnc.sh new file mode 100644 index 0000000..c1ba222 --- /dev/null +++ b/vnc.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Prepare variables +: "${VNC_BUILTIN_WIDTH:=1280}" +: "${VNC_BUILTIN_HEIGHT:=720}" +: "${VNC_BUILTIN_PIXELDEPTH:=24}" +: "${VNC_BUILTIN_DISABLED:=false}" + +if [ "${VNC_BUILTIN_DISABLED}" = true ]; then + echo "Builtin VNC is disabled. You must ensure the DISPLAY variable is set and the target display is accessible" + echo "Using display ${DISPLAY}" +else + echo "Builtin VNC is enabled. The DISPLAY variable will be ignored and overwritten" + export DISPLAY=":0" + + echo "Using display ${DISPLAY} with size of ${VNC_BUILTIN_WIDTH}x${VNC_BUILTIN_HEIGHT} and pixel depth ${VNC_BUILTIN_PIXELDEPTH}" + Xvfb ${DISPLAY} -screen 0 "${VNC_BUILTIN_WIDTH}x${VNC_BUILTIN_HEIGHT}x${VNC_BUILTIN_PIXELDEPTH}" & +fi + +# Wait for the display to become ready +while true +do + if xdpyinfo -display "${DISPLAY}" > /dev/null 2>&1; then + echo "Display ${DISPLAY} is ready!" + break + else + echo "Waiting for display ${DISPLAY} to become ready..." + sleep 0.25 + fi +done + +# Launch the VNC server if enabled +if [ "${VNC_BUILTIN_DISABLED}" != true ]; then + x11vnc -bg -forever -nopw -display ${DISPLAY} & +fi + +# Launch OpenBox +openbox &