diff --git a/src/lib/system-info.ts b/src/lib/system-info.ts index 0c28bfd8..6c1b4782 100644 --- a/src/lib/system-info.ts +++ b/src/lib/system-info.ts @@ -73,6 +73,7 @@ export async function getCpuTemp(): Promise { } export async function getSystemId(): Promise { + let systemId: undefined | string; try { // This will work on arm devices const buffer = await Promise.any([ @@ -81,14 +82,20 @@ export async function getSystemId(): Promise { fs.readFile('/sys/devices/soc0/serial_number'), ]); // Remove the null/newline bytes at the end - return buffer.toString('utf-8').replace(/\0/g, '').trim(); + systemId = buffer.toString('utf-8').replace(/\0/g, '').trim(); } catch { // Otherwise use dmidecode const [baseBoardInfo] = ( await dmidecode('baseboard').catch(() => [] as DmiDecodeInfo[]) ).filter((entry) => entry.type === 'Base Board Information'); - return baseBoardInfo?.values?.['Serial Number'] || undefined; + systemId = baseBoardInfo?.values?.['Serial Number'] || undefined; } + if (systemId == null) { + return; + } + // Always lower case so as not to jump between casing when jumping between eg /proc/device-tree/serial-number and /sys/devices/soc0/serial_number which can return different casing + // Lower case was chosen because that is what `/proc/device-tree/serial-number` usually returns and seems to be the more consistently available version + return systemId.toLowerCase(); } export async function getSystemModel(): Promise { diff --git a/test/unit/lib/system-info.spec.ts b/test/unit/lib/system-info.spec.ts index 753d7a2c..89842ff7 100644 --- a/test/unit/lib/system-info.spec.ts +++ b/test/unit/lib/system-info.spec.ts @@ -129,7 +129,7 @@ describe('System information', () => { stdout: mockCPU.dmidecode, }); const cpuId = await sysInfo.getSystemId(); - expect(cpuId).to.equal('GEBN94600PWW'); + expect(cpuId).to.equal('gebn94600pww'); }); it('gets system model', async () => {