Files
bare-operating-system/packages/bare-os-seeder/kernel/bin/uname
T
Raven Scott db3aece34d Implemented all plan to-dos end-to-end, including regeneration of staged bins, and verified with build + booter tests.
What changed
Fixed /bin generation for AsyncFunction execution in build pipeline:
Added appctl preamble wiring (p2p-suite.js) in packages/bare-os-coreutils/build.mjs.
Added a stripRunExport transform to remove trailing export { run } from generated /bin scripts.
Updated cut delimiter parsing in packages/bare-os-coreutils/src/cut.js:
Supports both -d X and attached -dX forms (including -d' ').
Validates -d argument presence and enforces single-character delimiter.
Improved uname -a output in packages/bare-os-coreutils/src/uname.js:
Better release/version derivation from env and /etc/os-release.
Uses env-backed machine architecture fallback instead of hardcoded unknown where available.
Added help aliases in packages/bare-os-coreutils/src/git-pear.js:
git-pear --help and git-pear -h now map to help output.
Reduced persistent invalid timer spam in packages/bare-os-booter/lib/bare-cron.js:
Added per-file parse-error dedupe/rate-limiting (first-seen, content-change, then hourly).
Added actionable invalid timer format hint in log message.
2026-04-27 07:59:00 -04:00

165 lines
4.7 KiB
Plaintext

/* BARE_OS_BIN_API 1.0.0 — bump when staged /bin script semantics change (see developer guide). */
/** Shared helpers for drive-resident /bin scripts (prepended before each command). */
function bareStdin(ctx) {
return typeof ctx.shellStdin === 'string' ? ctx.shellStdin : ''
}
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
function bareFormatModeString(mode, type) {
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
const perm = mode & 0o777
const r = (bit) => (perm & bit ? 'r' : '-')
const w = (bit) => (perm & bit ? 'w' : '-')
const x = (bit) => (perm & bit ? 'x' : '-')
return (
typeChar +
r(0o400) +
w(0o200) +
x(0o100) +
r(0o040) +
w(0o020) +
x(0o010) +
r(0o004) +
w(0o002) +
x(0o001)
)
}
/** @param {number} mtimeMs @param {number} [nowMs] */
function bareFormatLsMtime(mtimeMs, nowMs) {
const now = nowMs != null ? nowMs : Date.now()
const d = new Date(mtimeMs)
const months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
]
const mon = months[d.getMonth()]
const day = String(d.getDate()).padStart(2, ' ')
const sixMo = 180 * 24 * 3600 * 1000
if (Math.abs(now - mtimeMs) > sixMo) {
const yr = String(d.getFullYear()).padStart(4, ' ')
return mon + ' ' + day + ' ' + yr
}
const hh = String(d.getHours()).padStart(2, '0')
const mm = String(d.getMinutes()).padStart(2, '0')
return mon + ' ' + day + ' ' + hh + ':' + mm
}
/** @param {number} size */
function barePosixBlocks(size) {
return Math.ceil(Number(size) / 512) || 0
}
/**
* Raw stdout for NUL/binary when **`process.stdout.write`** is missing.
* If **`ctx.bareOsBinWrite(Uint8Array|string)`** is set (tests / host), use it.
* @param {Record<string, unknown>} ctx
* @param {string | Uint8Array} chunk
* @returns {boolean}
*/
function bareOsEmitRaw(ctx, chunk) {
if (typeof ctx.bareOsBinWrite === 'function') {
const b4 = ctx.b4a
const u8 =
typeof chunk === 'string'
? b4 && typeof b4.from === 'function'
? b4.from(chunk)
: new TextEncoder().encode(chunk)
: chunk
ctx.bareOsBinWrite(u8 instanceof Uint8Array ? u8 : new Uint8Array(u8))
return true
}
const w = globalThis.process?.stdout?.write
if (typeof w === 'function') {
w.call(globalThis.process.stdout, chunk)
return true
}
return false
}
async function run(ctx, argv) {
const e = ctx.vfs.env || {}
const nodename = e.HOSTNAME || e.NAME || 'bare-os'
let all = false
let wantS = false
let wantN = false
let wantR = false
let wantM = false
let wantV = false
for (let i = 1; i < argv.length; i++) {
const a = argv[i]
if (a === '--') break
if (a === '-a' || a === '--all') {
all = true
continue
}
if (!a.startsWith('-') || a === '-') {
ctx.console.error('uname: unexpected argument ' + a)
ctx.exitCode = 1
return
}
for (let j = 1; j < a.length; j++) {
const c = a[j]
if (c === 'a') all = true
else if (c === 's') wantS = true
else if (c === 'n') wantN = true
else if (c === 'r') wantR = true
else if (c === 'm') wantM = true
else if (c === 'v') wantV = true
else {
ctx.console.error('uname: invalid option -- ' + c)
ctx.exitCode = 1
return
}
}
}
if (all) {
wantS = wantN = wantR = wantM = wantV = true
} else if (!wantS && !wantN && !wantR && !wantM && !wantV) {
wantS = true
}
let name = 'BareOS'
let release = e.BARE_OS_KERNEL_VERSION || e.BARE_OS_RELEASE || '0.1'
let version = e.BARE_OS_USERLAND_VERSION || e.BARE_OS_BUILD || 'bare-userland'
let prettyName = ''
const buf = await ctx.vfs.readFile('/etc/os-release')
if (buf) {
const t = ctx.b4a.toString(buf)
for (const line of t.split('\n')) {
const keyVal = /^([A-Z0-9_]+)=(.*)$/.exec(line.trim())
if (!keyVal) continue
const key = keyVal[1]
const value = keyVal[2].replace(/^"|"$/g, '')
if (key === 'NAME' && value) name = value
if (key === 'VERSION' && value) prettyName = value
if (key === 'PRETTY_NAME' && value) prettyName = value
if (key === 'VERSION_ID' && value && !e.BARE_OS_KERNEL_VERSION) release = value
}
}
if (prettyName && !e.BARE_OS_USERLAND_VERSION && !e.BARE_OS_BUILD) {
version = prettyName
}
const machine =
e.PROCESSOR_ARCHITECTURE || e.MACHINE || e.BARE_OS_ARCH || 'unknown'
const parts = []
if (wantS) parts.push(name)
if (wantN) parts.push(nodename)
if (wantR) parts.push(release)
if (wantM) parts.push(machine)
if (wantV) parts.push(version)
ctx.console.log(parts.join(' '))
}