// electron-builder afterPack hook — wraps the Electron binary in a small // shell script that always passes --no-sandbox to the real binary. // // Why this exists: Linux AppImages mount a squashfs volume that strips the // SUID bit from chrome-sandbox. Chromium aborts at FATAL before any of our // own code runs: // // FATAL:setuid_sandbox_host.cc(163)] The SUID sandbox helper binary was // found, but is not configured correctly. ... You need to make sure that // ... chrome-sandbox is owned by root and has mode 4755. // // electron-builder's `linux.executableArgs` only injects --no-sandbox into // the generated .desktop file's Exec= line, NOT into the AppRun script, // so direct launches of the AppImage binary (double-click in a file // manager, `./Fleet-Runner-*.AppImage` from a shell) still crash. // // app.commandLine.appendSwitch('no-sandbox') in main.ts runs too late — // chrome-sandbox aborts before Electron's main process loads. // // This hook adds the only working layer: wrap the real binary in a tiny // shell stub that bakes --no-sandbox into argv before exec'ing the real // thing. Pattern used by Slack, Discord, VSCode, Cursor, Obsidian. // // Scoped to Linux because mac .dmg and Windows .exe don't have the SUID // wrinkle (.deb installs handle it via dpkg postinst chmod 4755). const fs = require('fs'); const path = require('path'); /** @param {import('electron-builder').AfterPackContext} context */ exports.default = async function afterPack(context) { if (context.electronPlatformName !== 'linux') return; // electron-builder copies the Electron binary into appOutDir at the // executable name (defaults to product name lowercased and dasherized). // For "Fleet Runner" → "fleet-runner". const execName = context.packager.executableName; const appOutDir = context.appOutDir; const realBinaryPath = path.join(appOutDir, execName); const wrappedBinaryPath = path.join(appOutDir, `${execName}-bin`); if (!fs.existsSync(realBinaryPath)) { console.warn(`[afterPack] expected Electron binary at ${realBinaryPath} but it's missing — skipping no-sandbox wrap`); return; } // Avoid double-wrap if afterPack runs twice (multi-arch build, retries). if (fs.existsSync(wrappedBinaryPath)) { console.log(`[afterPack] ${execName} appears already wrapped (${execName}-bin exists) — skipping`); return; } // Move the real Electron binary aside. fs.renameSync(realBinaryPath, wrappedBinaryPath); // Write a wrapper shell script under the original name. The AppRun // script generated by app-builder will exec this wrapper, which adds // --no-sandbox to argv before exec'ing the real binary. // // Notes: // - `exec` so the wrapper process is replaced (no extra layer). // - `"$@"` preserves any args the user passed. // - `--no-sandbox` is appended BEFORE user args so it can't be undone. // - The HERE_DIR trick handles both AppImage-mounted paths and direct // execution from a deb install (no relative-path fragility). const wrapper = `#!/bin/bash # Auto-generated by desktop/scripts/afterPack.cjs. # Wraps the real Electron binary with --no-sandbox so the AppImage launches # on Linux without the SUID-sandbox helper FATAL. See afterPack.cjs for # the why. HERE_DIR="$(dirname "$(readlink -f "$0")")" exec "$HERE_DIR/${execName}-bin" --no-sandbox "$@" `; fs.writeFileSync(realBinaryPath, wrapper, { mode: 0o755 }); console.log(`[afterPack] wrapped ${execName} with --no-sandbox stub (real binary moved to ${execName}-bin)`); };