'use strict' /** * platform-linux.js — Linux-specific runtime adapter * Loaded exclusively when process.platform === 'linux' */ const path = require('path') const os = require('os') const PLATFORM = 'linux' // ── Writable path candidates for app userData ───────────────────────────────── function getWritableCandidates(appDirName) { const candidates = [] const xdgData = process.env.XDG_DATA_HOME if (xdgData) { candidates.push(path.join(xdgData, 'chahuadev', appDirName)) } candidates.push(path.join(os.homedir(), '.local', 'share', 'chahuadev', appDirName)) candidates.push(path.join(os.tmpdir(), appDirName)) return candidates } // ── Command name normalization ──────────────────────────────────────────────── // Linux: no .cmd suffix needed — npm/npx/pnpm/yarn are native shell scripts. function normalizeExecName(cmd) { return String(cmd || '').trim() } // ── Shell wrapping ──────────────────────────────────────────────────────────── // Linux commands run directly via node-pty — no cmd.exe-style wrapping needed. function shouldUseShell(cmd) { // eslint-disable-line no-unused-vars return false } // Not called on Linux (shouldUseShell always false), but satisfies interface. function buildShellSpawn(cmd, args) { return { file: cmd, args: args || [] } } // ── node-pty spawn extra options ────────────────────────────────────────────── // useConpty is a Windows-only (ConPTY) option. On Linux use standard PTY. function getPtySpawnOptions() { return {} } // ── Node.js runtime path ────────────────────────────────────────────────────── function resolveNodeRuntime() { return 'node' } // ── Linux build command ─────────────────────────────────────────────────────── // On Linux the AppImage runs natively — no WSL bridge required. function _quoteBash(s) { return `'${String(s || '').replace(/'/g, `'"'"'`)}'` } function rewriteLinuxBuildCommand(cwd) { const script = [ 'set -euo pipefail', `cd ${_quoteBash(cwd)}`, 'npm install', 'if npm run | grep -q "build:linux"; then npm run build:linux; else npx electron-builder --linux AppImage --x64 --publish never; fi' ].join('; ') return { cmd: 'bash', args: ['-lc', script], rewriteInfo: { applied: true, kind: 'launcher-linux-build-inline-bash', targetProjectPath: cwd } } } // ── Protected OS path bases ─────────────────────────────────────────────────── // Base list covers standard FHS paths. // We also scan /proc/mounts at runtime to catch non-standard system-level // mount points (e.g. bind mounts, external drives at /mnt/*, /media/*, // or custom rootfs at depth-1 like /data, /storage). // Only "system-ish" mounts are protected — /home and /tmp are intentionally left open. const _OPEN_ROOTS = new Set(['home', 'tmp', 'root']) function _readMountRoots() { try { const fs = require('fs') const lines = fs.readFileSync('/proc/mounts', 'utf8').split('\n') const extra = new Set() for (const line of lines) { const mountPoint = line.split(' ')[1] if (!mountPoint || mountPoint === '/') continue const parts = mountPoint.split('/').filter(Boolean) // Protect any depth-1 non-user mount (e.g. /data, /storage) if (parts.length === 1 && !_OPEN_ROOTS.has(parts[0])) { extra.add(mountPoint) } // Protect anything under /mnt/* or /media/* (external drives, images) if (parts.length === 2 && (parts[0] === 'mnt' || parts[0] === 'media')) { extra.add(mountPoint) } } return [...extra] } catch { return [] } } function getProtectedPathBases() { return [ '/bin', '/sbin', '/lib', '/lib64', '/usr', '/var', '/etc', '/boot', '/proc', '/sys', '/dev', '/run', '/snap', ..._readMountRoots() ] } module.exports = { PLATFORM, getWritableCandidates, normalizeExecName, shouldUseShell, buildShellSpawn, getPtySpawnOptions, resolveNodeRuntime, rewriteLinuxBuildCommand, getProtectedPathBases }