| 'use strict'
|
| |
| |
| |
|
|
|
|
| const path = require('path')
|
| const os = require('os')
|
|
|
| const PLATFORM = 'linux'
|
|
|
|
|
| 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
|
| }
|
|
|
|
|
|
|
| function normalizeExecName(cmd) {
|
| return String(cmd || '').trim()
|
| }
|
|
|
|
|
|
|
| function shouldUseShell(cmd) {
|
| return false
|
| }
|
|
|
|
|
| function buildShellSpawn(cmd, args) {
|
| return { file: cmd, args: args || [] }
|
| }
|
|
|
|
|
|
|
| function getPtySpawnOptions() {
|
| return {}
|
| }
|
|
|
|
|
| function resolveNodeRuntime() {
|
| return 'node'
|
| }
|
|
|
|
|
|
|
| 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
|
| }
|
| |