#!/bin/bash # Boots the desktop: X server, window manager, VNC and the noVNC web viewer. set -u mkdir -p /home/bot/.fluxbox /home/bot/Desktop && cp -n /etc/anybot/fluxbox-init /home/bot/.fluxbox/init 2>/dev/null cp -n /etc/anybot/overlay /home/bot/.fluxbox/overlay 2>/dev/null cp -n /etc/anybot/Xresources /home/bot/.Xresources 2>/dev/null cp /etc/anybot/menu /home/bot/.fluxbox/menu 2>/dev/null chown -R bot:bot /home/bot rm -f /tmp/.X1-lock /tmp/.X11-unix/X1 Xvfb :1 -screen 0 "${SCREEN_SIZE}" -nolisten tcp & XVFB_PID=$! for i in $(seq 1 50); do xdpyinfo -display :1 >/dev/null 2>&1 && break; sleep 0.1; done su bot -c "DISPLAY=:1 xrdb -nocpp -merge /home/bot/.Xresources" su bot -c "DISPLAY=:1 fluxbox >/tmp/fluxbox.log 2>&1 &" (sleep 1.5; xsetroot -display :1 -solid '#2b2f36') & xsetroot -display :1 -solid '#2b2f36' # VNC login key: the app starts the box with VNC_PASSWORD and opens the viewer with it. # Without it (an older app) the desktop stays keyless as before. if [ -n "${VNC_PASSWORD:-}" ]; then mkdir -p /home/bot/.vnc printf '%s' "$VNC_PASSWORD" | x11vnc -storepasswd /home/bot/.vnc/pass >/dev/null 2>&1 x11vnc -display :1 -forever -shared -quiet -rfbauth /home/bot/.vnc/pass -rfbport 5900 -localhost >/tmp/x11vnc.log 2>&1 & else x11vnc -display :1 -forever -shared -nopw -quiet -rfbport 5900 -localhost >/tmp/x11vnc.log 2>&1 & fi websockify --web /usr/share/novnc 6080 localhost:5900 >/tmp/novnc.log 2>&1 & WEBSOCKIFY_PID=$! # Say ready only once the viewer's port listens: the app opens noVNC on this flag, and a too # early file meant the first viewer load 404'd. ( for i in $(seq 1 100); do python3 -c "import socket; socket.create_connection(('127.0.0.1', 6080), 0.5)" 2>/dev/null && break sleep 0.2 done echo "anybot-box ready" > /tmp/anybot-box.ready ) & # When the desktop's heart stops, the container ends too (it used to sit there as Running # with a dead X server, and every screen action failed forever). wait $XVFB_PID kill $WEBSOCKIFY_PID 2>/dev/null pkill -f x11vnc 2>/dev/null pkill -u bot fluxbox 2>/dev/null exit 1