summaryrefslogtreecommitdiff
path: root/fbgl_test_virtual_fb.sh
diff options
context:
space:
mode:
authorLevent Kaya <42411502+lvntky@users.noreply.github.com>2025-04-20 02:41:46 +0300
committerGitHub <noreply@github.com>2025-04-20 02:41:46 +0300
commit1d5c368baeba7f0f18e73da32ac083374da535b2 (patch)
tree5230f62ba648a9a65e9bbd329705b83a100cbeb6 /fbgl_test_virtual_fb.sh
parenta0538f6cd956612caefc032352f082a2f80bc6da (diff)
[test] virtual fb script updated
Diffstat (limited to 'fbgl_test_virtual_fb.sh')
-rw-r--r--fbgl_test_virtual_fb.sh104
1 files changed, 64 insertions, 40 deletions
diff --git a/fbgl_test_virtual_fb.sh b/fbgl_test_virtual_fb.sh
index 501b7e1..948ad4d 100644
--- a/fbgl_test_virtual_fb.sh
+++ b/fbgl_test_virtual_fb.sh
@@ -1,42 +1,66 @@
#!/bin/bash
-# Check if Xvfb is installed
-if ! command -v Xvfb &> /dev/null; then
- echo "Xvfb not found. Install it with your package manager (e.g., sudo pacman -S xorg-server-xvfb)."
- exit 1
-fi
-
-# Set variables
-PRECOMPILED_BINARY="./fbgl_test" # Replace with your precompiled binary's path
-DISPLAY_NUMBER=":99" # Virtual framebuffer display number
-
-# Check if the precompiled binary exists
-if [ ! -f "$PRECOMPILED_BINARY" ]; then
- echo "Precompiled binary '$PRECOMPILED_BINARY' not found."
- exit 1
-fi
-
-# Start virtual framebuffer
-echo "Starting Xvfb on display ${DISPLAY_NUMBER}..."
-Xvfb $DISPLAY_NUMBER -screen 0 1024x768x24 &
-XVFB_PID=$!
-
-# Wait for Xvfb to start
-sleep 2
-
-# Set the DISPLAY environment variable
-export DISPLAY=$DISPLAY_NUMBER
-
-# Run the precompiled binary inside the virtual framebuffer
-echo "Running $PRECOMPILED_BINARY in the virtual framebuffer environment..."
-$PRECOMPILED_BINARY
-
-# Capture the exit code of the binary
-BINARY_EXIT_CODE=$?
-
-# Stop Xvfb
-echo "Stopping Xvfb..."
-kill $XVFB_PID
-
-# Exit with the binary's exit code
-exit $BINARY_EXIT_CODE
+# ----------- CONFIGURATION -----------
+XVFB_DISPLAY_NUM=99
+XVFB_RESOLUTION="1280x800x24"
+XVFB_DISPLAY=":$XVFB_DISPLAY_NUM"
+VNC_PORT=5900
+LOG_DIR="./logs"
+APP_COMMAND="./fbgl_app"
+WM_COMMAND="fluxbox"
+# -------------------------------------
+
+mkdir -p "$LOG_DIR"
+
+XVFB_LOG="$LOG_DIR/xvfb.log"
+VNC_LOG="$LOG_DIR/x11vnc.log"
+APP_LOG="$LOG_DIR/app.log"
+
+function check_dependencies {
+ echo "[*] Checking dependencies..."
+ for cmd in Xvfb x11vnc $WM_COMMAND; do
+ if ! command -v "$cmd" &> /dev/null; then
+ echo "[!] Missing dependency: $cmd"
+ exit 1
+ fi
+ done
+}
+
+function cleanup {
+ echo "[*] Cleaning up..."
+ pkill -f "Xvfb $XVFB_DISPLAY"
+ pkill -f "x11vnc.*$XVFB_DISPLAY"
+ pkill -f "$WM_COMMAND"
+ echo "[*] Done."
+}
+
+function start_xvfb {
+ echo "[*] Starting Xvfb on display $XVFB_DISPLAY..."
+ Xvfb "$XVFB_DISPLAY" -screen 0 "$XVFB_RESOLUTION" > "$XVFB_LOG" 2>&1 &
+ sleep 1
+}
+
+function start_window_manager {
+ echo "[*] Starting window manager: $WM_COMMAND..."
+ DISPLAY="$XVFB_DISPLAY" $WM_COMMAND > /dev/null 2>&1 &
+ sleep 1
+}
+
+function start_vnc {
+ echo "[*] Starting x11vnc on port $VNC_PORT..."
+ x11vnc -display "$XVFB_DISPLAY" -nopw -forever -bg -quiet -rfbport "$VNC_PORT" > "$VNC_LOG" 2>&1
+}
+
+function run_app {
+ echo "[*] Running GUI application: $APP_COMMAND"
+ DISPLAY="$XVFB_DISPLAY" $APP_COMMAND > "$APP_LOG" 2>&1
+}
+
+# ------- Main Execution -------
+trap cleanup EXIT
+check_dependencies
+cleanup
+start_xvfb
+start_window_manager
+start_vnc
+run_app