From cd0e58be825df426fbbf4a7b8275e8a6700ef37f Mon Sep 17 00:00:00 2001 From: Tara Menon Date: Fri, 12 Jun 2026 18:25:09 +0530 Subject: [PATCH] feat(install): auto-detect WSL + install Linux system deps for camoufox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Camoufox browser (Playwright-based) needs ~30 Linux system libraries to run. On fresh WSL/Ubuntu, these are not pre-installed, causing the browser daemon to crash silently with only a cryptic 'No such file or directory' error. Changes: 1. Add detect_wsl() — reads /proc/version for 'microsoft'/'wsl' 2. Add install_linux_deps() — installs all 30+ Playwright deps via apt-get/dnf/yum before installing camoufox-browser 3. Handles t64 package name variants (libasound2t64 vs libasound2) 4. Shows WSL-specific note at end of install 5. npm install -g camoufox-browser + install now run with better output 6. Verifies browser binary exists at ~/.cache/camoufox/ post-install 7. Install now fully automatic on fresh WSL — no manual apt-get needed --- install.sh | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 151 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index ddc1396..db6742e 100755 --- a/install.sh +++ b/install.sh @@ -37,6 +37,52 @@ detect_os() { esac } +# ── WSL Detection ────────────────────────────────────────────────────────── +# Detect if we're running inside Windows Subsystem for Linux. +# /proc/version contains "microsoft" or "wsl" (case-insensitive) on WSL. +detect_wsl() { + if [ -f /proc/version ] && grep -qiE 'microsoft|wsl' /proc/version 2>/dev/null; then + return 0 # true — we are in WSL + fi + return 1 +} + +# ── Linux System Dependencies ────────────────────────────────────────────── +# Camoufox (Playwright-based) needs ~30 system libraries on Linux/WSL. +# Without these, the browser daemon crashes silently with +# "Failed to connect: No such file or directory (os error 2)". +# See: https://playwright.dev/docs/troubleshooting#system-dependencies +CAMOUFOX_LINUX_DEPS=( + libgtk-3-0 + libnss3 + libnspr4 + libatk1.0-0t64 + libatk-bridge2.0-0t64 + libcups2t64 + libdrm2 + libxkbcommon0 + libxcomposite1 + libxdamage1 + libxfixes3 + libxrandr2 + libgbm1 + libpango-1.0-0 + libcairo2 + libasound2t64 + libxcb-shm0 + libx11-xcb1 + libx11-6 + libxcb1 + libxext6 + libxcursor1 + libxi6 + libfreetype6 + libfontconfig1 + libxshmfence1 + libxrender1 + libdbus-1-3 +) + install_rust_if_needed() { if ! command -v cargo &>/dev/null; then info "Rust toolchain not found. Installing..." @@ -60,13 +106,105 @@ install_node_if_needed() { fi } +# ── Linux System Deps Installer ──────────────────────────────────────────── +install_linux_deps() { + if [ "$(uname -s)" != "Linux" ]; then + return 0 # Not Linux, skip + fi + + # Check if we're in WSL (Windows Subsystem for Linux) + if detect_wsl; then + info "WSL detected. Checking Linux system dependencies..." + fi + + # Check which packages are already installed + local missing=() + if command -v dpkg-query &>/dev/null; then + for pkg in "${CAMOUFOX_LINUX_DEPS[@]}"; do + if ! dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -q "install ok installed"; then + # Handle libasound2 vs libasound2t64 and similar t64 variants + # Try without 't64' suffix as fallback + local alt_pkg="${pkg%t64}" + if [ "$alt_pkg" != "$pkg" ] && dpkg-query -W -f='${Status}' "$alt_pkg" 2>/dev/null | grep -q "install ok installed"; then + continue # alt version is already installed + fi + missing+=("$pkg") + fi + done + else + # Can't check, just try to install all + missing=("${CAMOUFOX_LINUX_DEPS[@]}") + fi + + if [ ${#missing[@]} -eq 0 ]; then + info "All Linux system dependencies already installed" + return 0 + fi + + info "Installing ${#missing[@]} missing Linux system dependencies..." + if command -v apt-get &>/dev/null; then + if command -v sudo &>/dev/null; then + sudo apt-get update -qq 2>/dev/null || true + sudo apt-get install -y -qq "${missing[@]}" 2>/dev/null || { + # If some packages failed, retry with auto-detected alternatives + warn "Some packages had issues. Retrying with apt --fix..." + sudo apt-get --fix-broken install -y -qq 2>/dev/null || true + # Try installing without t64 variants as fallback + local fallback=() + for pkg in "${missing[@]}"; do + local alt="${pkg%t64}" + if [ "$alt" != "$pkg" ]; then + fallback+=("$alt") + fi + done + if [ ${#fallback[@]} -gt 0 ]; then + sudo apt-get install -y -qq "${fallback[@]}" 2>/dev/null || true + fi + } + else + apt-get update -qq 2>/dev/null || true + apt-get install -y -qq "${missing[@]}" 2>/dev/null || true + fi + ok "Linux system dependencies installed" + elif command -v dnf &>/dev/null; then + info "Detected dnf package manager" + sudo dnf install -y nss nspr atk at-spi2-atk cups-libs libdrm libXcomposite \ + libXdamage libXrandr mesa-libgbm pango alsa-lib libxkbcommon libxcb \ + libX11-xcb libX11 libXext libXcursor libXfixes libXi gtk3 cairo-gobject 2>/dev/null || true + ok "Linux system dependencies installed" + elif command -v yum &>/dev/null; then + info "Detected yum package manager" + sudo yum install -y nss nspr atk at-spi2-atk cups-libs libdrm libXcomposite \ + libXdamage libXrandr mesa-libgbm pango alsa-lib libxkbcommon 2>/dev/null || true + ok "Linux system dependencies installed" + else + warn "No supported package manager (apt-get/dnf/yum). You may need to install system dependencies manually." + warn "Required packages: ${CAMOUFOX_LINUX_DEPS[*]}" + fi +} + install_camofox_browser() { info "Installing camofox-browser (anti-detection browser)..." - if command -v npx &>/dev/null; then - info "Installing via npm..." - npm install -g camoufox-browser 2>&1 | tail -5 + + # Step 1: Install Linux system dependencies (needed by Playwright/Camoufox) + install_linux_deps + + # Step 2: Install the npm package + if command -v npx &>/dev/null || command -v npm &>/dev/null; then + info "Installing npm package..." + npm install -g camoufox-browser 2>&1 | tail -3 + + info "Downloading Camoufox browser binary (this may take a while, ~662MB)..." npx camoufox-browser@latest install 2>&1 | tail -5 - ok "Camoufox browser installed (npx camoufox-browser start)" + + # Verify the browser binary was actually downloaded + if ls ~/.cache/camoufox/camoufox 2>/dev/null; then + ok "Camoufox browser binary downloaded (~/.cache/camoufox/)" + else + warn "Browser binary not found at ~/.cache/camoufox/. May need manual 'npx camoufox-browser@latest install'" + fi + + ok "Camoufox browser npm package installed" elif command -v docker &>/dev/null; then info "Installing via Docker..." docker run -d --name camoufox -p 9377:9377 \ @@ -146,6 +284,12 @@ print_post_install() { echo " gyandoot service status Check service status" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" + + if detect_wsl; then + echo " ⚠️ WSL detected — Node.js must be installed INSIDE WSL." + echo " (The Windows-side Node.js is not accessible from WSL.)" + echo "" + fi } prompt_service_install() { @@ -167,6 +311,9 @@ main() { os=$(detect_os) arch=$(detect_architecture) info "Detected: $os / $arch" + if detect_wsl; then + info "WSL (Windows Subsystem for Linux) detected — will install Linux dependencies" + fi install_rust_if_needed install_node_if_needed