Files
bare-operating-system/packages/bare-os-booter/lib/bare-os-host-ota-boot.mjs
T
Raven Scott d30b918442
Release rolling / release (push) Canceled after 1m44s
booter fixes
2026-07-31 13:44:53 -04:00

48 lines
1.4 KiB
JavaScript

/**
* Host OTA + --datadir prelude. Statically imported first from index.js so it
* runs before main(), and bare-pack embeds it without dynamic import().
*/
import { name, version, upgrade } from '../../../bin/meta/booter.mjs'
import { startPearOta, parseOtaFlags } from '../../../lib/bare-os-ota.mjs'
import { applyHostFlagsFromArgv } from '../../../lib/bare-os-host-flags.mjs'
function pathBasename(p) {
const s = String(p || '')
const i = Math.max(s.lastIndexOf('/'), s.lastIndexOf('\\'))
return i >= 0 ? s.slice(i + 1) : s
}
function hostArgv() {
const isBare = typeof globalThis.Bare !== 'undefined'
if (isBare) {
const a0 = globalThis.Bare.argv?.[0]
return globalThis.Bare.argv.slice(pathBasename(a0) === 'bare' ? 2 : 1)
}
return (globalThis.process?.argv || []).slice(2)
}
const argv = hostArgv()
const { rest: afterHost } = applyHostFlagsFromArgv(argv)
const { updates, storage } = parseOtaFlags(afterHost)
export const hostOta = await startPearOta({
upgrade,
version,
name: name || 'bare-os-booter',
updates,
storage,
})
if (typeof process !== 'undefined' && process.on) {
const onExit = async (code = 0) => {
await hostOta.close()
if (typeof globalThis.Bare !== 'undefined') globalThis.Bare.exit(code)
else process.exit(code)
}
for (const sig of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
process.on(sig, () => {
onExit(sig === 'SIGINT' ? 130 : 143).catch(() => {})
})
}
}