chassis() type, assetTag, sku improved parsing (macOS)

This commit is contained in:
Sebastian Hildebrandt
2024-03-14 05:02:18 +01:00
parent f1f2ccd927
commit 1744982db0
4 changed files with 47 additions and 7 deletions
+40 -6
View File
@@ -215,12 +215,14 @@ function system(callback) {
exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
if (!error) {
let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
const model = splitByNumber(util.getValue(lines, 'model', '=', true));
const version = util.getValue(lines, 'version', '=', true);
result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
result.model = util.getValue(lines, 'model', '=', true, true);
result.version = util.getValue(lines, 'version', '=', true);
result.model = version ? util.getValue(lines, 'model', '=', true) : model[0];
result.version = version || model[1];
result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
result.uuid = util.getValue(lines, 'ioplatformuuid', '=', true).toLowerCase();
result.sku = util.getValue(lines, 'board-id', '=', true);
result.sku = util.getValue(lines, 'board-id', '=', true) || util.getValue(lines, 'target-sub-type', '=', true);
}
if (callback) { callback(result); }
resolve(result);
@@ -602,6 +604,33 @@ function baseboard(callback) {
exports.baseboard = baseboard;
function macOsChassisType(model) {
model = model.toLowerCase();
if (model.startsWith('macbookair')) { return 'Notebook'; }
if (model.startsWith('macbookpro')) { return 'Laptop'; }
if (model.startsWith('macbook')) { return 'Notebook'; }
if (model.startsWith('macmini')) { return 'Desktop'; }
if (model.startsWith('imac')) { return 'Desktop'; }
if (model.startsWith('macstudio')) { return 'Desktop'; }
if (model.startsWith('macpro')) { return 'Tower'; }
return 'Other';
}
function splitByNumber(str) {
let numberStarted = false;
let num = '';
let cpart = '';
for (const c of str) {
if ((c >= '0' && c <= '9') || numberStarted) {
numberStarted = true;
num += c;
} else {
cpart += c;
}
}
return [cpart, num];
}
function chassis(callback) {
const chassisTypes = ['Other',
'Unknown',
@@ -680,11 +709,16 @@ function chassis(callback) {
exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
if (!error) {
let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
const model = util.getValue(lines, 'model', '=', true);
const modelParts = splitByNumber(model);
const version = util.getValue(lines, 'version', '=', true);
result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
result.model = util.getValue(lines, 'model', '=', true);
result.version = util.getValue(lines, 'version', '=', true);
result.model = version ? util.getValue(lines, 'model', '=', true) : modelParts[0];
result.type = macOsChassisType(result.model);
result.version = version || model;
result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
result.assetTag = util.getValue(lines, 'board-id', '=', true);
result.assetTag = util.getValue(lines, 'board-id', '=', true) || util.getValue(lines, 'target-type', '=', true);
result.sku = util.getValue(lines, 'target-sub-type', '=', true);
}
if (callback) { callback(result); }