+ "value": "#!/bin/sh\nset -e\n\n# --- CONFIGURABLE SETTINGS ---\n\n# --- OPERATION MODE ---\n# 'FULL_START': Checks dependencies, cleans up, and starts everything from scratch.\n# 'REFRESH': Not applicable for Fluxbox, behaves like FULL_START.\n# 'CLEAN': Terminates all processes and stops (shutdown).\nOPERATION_MODE=\"FULL_START\"\n\n# --- DEPENDENCY MANAGEMENT ---\n# If 'true', the script will try to install missing dependencies.\n# On Alpine, this requires root privileges.\nAUTO_INSTALL_DEPS=\"true\"\n\n# --- CONNECTION SETTINGS ---\nVNC_PASSWORD=\"p\"\nVNC_PORT=\"2999\"\nWEBSOCKET_PORT=\"6080\"\n\n# --- GRAPHICAL ENVIRONMENT SETTINGS ---\nRESOLUTION=\"1920x1080x24\"\n\n# --- APPLICATION TO RUN ---\n# We start Fluxbox. Inside Fluxbox, the user can launch other applications (e.g., xterm).\nPROGRAM_TO_RUN=\"fluxbox\"\n\n\n# --- SCRIPT LOGIC (DO NOT MODIFY BELOW THIS LINE) ---\n\n# Function for a complete cleanup of the environment (uses pkill for Alpine)\ncleanup_all() {\n echo \"--- Full cleanup: Terminating all VNC environment processes... ---\"\n pkill -f \"x11vnc -display :0\" || true\n pkill -f \"Xvfb :0\" || true\n pkill -f \"websockify.*localhost:${VNC_PORT}\" || true\n pkill -f \"${PROGRAM_TO_RUN}\" || true\n echo \"--- Cleanup complete. ---\"\n}\n\n# Function to install dependencies on Alpine Linux\ninstall_dependencies() {\n if [ \"$AUTO_INSTALL_DEPS\" != \"true\" ]; then\n echo \"--- Dependency check skipped (disabled by configuration). ---\"\n return\n fi\n\n if ! command -v apk >/dev/null; then\n echo \"WARNING: This script is configured for Alpine Linux (apk) but 'apk' was not found.\"\n return\n fi\n\n if [ \"$(id -u)\" -ne 0 ]; then\n echo \"ERROR: To install dependencies on Alpine, run the script as the 'root' user.\"\n exit 1\n fi\n \n # APK dependencies: procps contains pkill, websockify\n APK_DEPS=\"xvfb x11vnc procps websockify\"\n PACKAGES_TO_INSTALL=\"\"\n echo \"--- Checking required APK dependencies... ---\"\n for pkg in $APK_DEPS; do\n if ! apk info -e \"$pkg\" >/dev/null 2>&1; then\n echo \"Missing APK dependency: $pkg\"\n PACKAGES_TO_INSTALL=\"$PACKAGES_TO_INSTALL $pkg\"\n fi\n done\n\n if [ -n \"$PACKAGES_TO_INSTALL\" ]; then\n echo \"Found missing APK dependencies. Updating and installing with 'apk add'...\"\n apk update\n apk add --no-cache $PACKAGES_TO_INSTALL\n else\n echo \"All required APK dependencies are already installed.\"\n fi\n}\n\n# Function to start the application\nstart_app() {\n echo \"--- Starting ${PROGRAM_TO_RUN}... ---\"\n nohup env DISPLAY=:0 ${PROGRAM_TO_RUN} &\n # For Fluxbox, the user can launch xterm manually from the menu\n}\n\n# --- OPERATION MODE HANDLING ---\nif [ \"$OPERATION_MODE\" = \"CLEAN\" ]; then\n echo \"--- OPERATION MODE: CLEAN ---\"\n cleanup_all\n exit 0\n\nelif [ \"$OPERATION_MODE\" = \"REFRESH\" ]; then\n echo \"--- OPERATION MODE: REFRESH (not applicable, executing FULL_START) ---\"\n OPERATION_MODE=\"FULL_START\" # Force FULL_START\nfi\n\nif [ \"$OPERATION_MODE\" = \"FULL_START\" ]; then\n echo \"--- OPERATION MODE: FULL_START ---\"\n install_dependencies\n cleanup_all\n trap 'echo; cleanup_all; exit 0' INT TERM\n echo \"--- Starting base services... ---\"\n nohup Xvfb :0 -screen 0 ${RESOLUTION} &\n sleep 1\n nohup x11vnc -display :0 -forever -rfbport ${VNC_PORT} -passwd \"$VNC_PASSWORD\" &\n sleep 1\n nohup websockify --web /usr/share/novnc/ ${WEBSOCKET_PORT} localhost:${VNC_PORT} &\n sleep 1\n echo \"Servers started.\"\n start_app\n echo\n echo \">>> VNC environment with Fluxbox started. <<<\"\n echo \"Open xterm from the Fluxbox menu (right-click on the desktop).\"\nelse\n echo \"ERROR: Invalid OPERATION_MODE. Choose 'FULL_START' or 'CLEAN'.\"\n exit 1\nfi"
0 commit comments