mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2026-02-04 14:54:16 +02:00
attempt fix linux waitExit error
Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
@@ -18,7 +18,8 @@ function trimIdentifiers(val)
|
||||
{
|
||||
for(var v in val)
|
||||
{
|
||||
if (!val[v] || val[v] == 'None' || val[v] == '' || val[v].trim() == '') { delete val[v]; }
|
||||
if(typeof val[v] === 'string') val[v] = val[v].trim();
|
||||
if (!val[v] || val[v] == 'None' || val[v] == '') { delete val[v]; }
|
||||
}
|
||||
}
|
||||
function trimResults(val)
|
||||
@@ -68,6 +69,7 @@ function linux_identifiers()
|
||||
var identifiers = {};
|
||||
var ret = {};
|
||||
var values = {};
|
||||
var child = null;
|
||||
|
||||
if (!require('fs').existsSync('/sys/class/dmi/id')) {
|
||||
if (require('fs').existsSync('/sys/firmware/devicetree/base/model')) {
|
||||
@@ -76,7 +78,7 @@ function linux_identifiers()
|
||||
identifiers['board_name'] = require('fs').readFileSync('/sys/firmware/devicetree/base/model').toString().trim();
|
||||
identifiers['board_serial'] = require('fs').readFileSync('/sys/firmware/devicetree/base/serial-number').toString().trim();
|
||||
const memorySlots = [];
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = ''; child.stdout.on('data', dataHandler);
|
||||
child.stdin.write('vcgencmd get_mem arm && vcgencmd get_mem gpu\nexit\n');
|
||||
child.waitExit();
|
||||
@@ -122,20 +124,20 @@ function linux_identifiers()
|
||||
identifiers['bios_mode'] = (require('fs').statSync('/sys/firmware/efi').isDirectory() ? 'UEFI': 'Legacy');
|
||||
} catch (ex) { identifiers['bios_mode'] = 'Legacy'; }
|
||||
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = ''; child.stdout.on('data', dataHandler);
|
||||
child.stdin.write('cat /proc/cpuinfo | grep -i "model name" | ' + "tr '\\n' ':' | awk -F: '{ print $2 }'\nexit\n");
|
||||
child.waitExit();
|
||||
identifiers['cpu_name'] = child.stdout.str.trim();
|
||||
if (identifiers['cpu_name'] == "") { // CPU BLANK, check lscpu instead
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = ''; child.stdout.on('data', dataHandler);
|
||||
child.stdin.write('lscpu | grep -i "model name" | ' + "tr '\\n' ':' | awk -F: '{ print $2 }'\nexit\n");
|
||||
child.waitExit();
|
||||
try {
|
||||
identifiers['cpu_name'] = child.stdout.str.trim();
|
||||
}
|
||||
child = null;
|
||||
|
||||
if (identifiers['cpu_name'] == "") { // CPU BLANK, check lscpu instead
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = ''; child.stdout.on('data', dataHandler);
|
||||
child.stdin.write('lscpu | grep -i "model name" | ' + "tr '\\n' ':' | awk -F: '{ print $2 }'\nexit\n");
|
||||
child.waitExit();
|
||||
try { identifiers['cpu_name'] = child.stdout.str.trim(); } catch (xx) { }
|
||||
}
|
||||
} catch (xx) { }
|
||||
|
||||
// Fetch GPU info
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
@@ -143,7 +145,6 @@ function linux_identifiers()
|
||||
child.stdin.write("lspci | grep ' VGA ' | tr '\\n' '`' | awk '{ a=split($0,lines" + ',"`"); printf "["; for(i=1;i<a;++i) { split(lines[i],gpu,"r: "); printf "%s\\"%s\\"", (i==1?"":","),gpu[2]; } printf "]"; }\'\nexit\n');
|
||||
child.waitExit();
|
||||
try { identifiers['gpu_name'] = JSON.parse(child.stdout.str.trim()); } catch (xx) { }
|
||||
child = null;
|
||||
|
||||
// Fetch Storage Info
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
@@ -151,7 +152,6 @@ function linux_identifiers()
|
||||
child.stdin.write("lshw -class disk -disable network | tr '\\n' '`' | awk '" + '{ len=split($0,lines,"*"); printf "["; for(i=2;i<=len;++i) { model=""; caption=""; size=""; clen=split(lines[i],item,"`"); for(j=2;j<clen;++j) { split(item[j],tokens,":"); split(tokens[1],key," "); if(key[1]=="description") { caption=substr(tokens[2],2); } if(key[1]=="product") { model=substr(tokens[2],2); } if(key[1]=="size") { size=substr(tokens[2],2); } } if(model=="") { model=caption; } if(caption!="" || model!="") { printf "%s{\\"Caption\\":\\"%s\\",\\"Model\\":\\"%s\\",\\"Size\\":\\"%s\\"}",(i==2?"":","),caption,model,size; } } printf "]"; }\'\nexit\n');
|
||||
child.waitExit();
|
||||
try { identifiers['storage_devices'] = JSON.parse(child.stdout.str.trim()); } catch (xx) { }
|
||||
child = null;
|
||||
|
||||
// Fetch storage volumes using df
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
@@ -159,7 +159,6 @@ function linux_identifiers()
|
||||
child.stdin.write('df -T -x tmpfs -x devtmpfs -x efivarfs | awk \'NR==1 || $1 ~ ".+"{print $3, $4, $5, $7, $2}\' | awk \'NR>1 {printf "{\\"size\\":\\"%s\\",\\"used\\":\\"%s\\",\\"available\\":\\"%s\\",\\"mount_point\\":\\"%s\\",\\"type\\":\\"%s\\"},", $1, $2, $3, $4, $5}\' | sed \'$ s/,$//\' | awk \'BEGIN {printf "["} {printf "%s", $0} END {printf "]"}\'\nexit\n');
|
||||
child.waitExit();
|
||||
try { ret.volumes = JSON.parse(child.stdout.str.trim()); } catch (xx) { }
|
||||
child = null;
|
||||
|
||||
values.identifiers = identifiers;
|
||||
values.linux = ret;
|
||||
|
||||
Reference in New Issue
Block a user