fsSize() alpine linux support

This commit is contained in:
Sebastian Hildebrandt 2020-01-04 23:45:41 +01:00
parent 8a5f36816e
commit e682abb657
7 changed files with 61 additions and 31 deletions

View File

@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
| Version | Date | Comment | | Version | Date | Comment |
| -------------- | -------------- | -------- | | -------------- | -------------- | -------- |
| 4.17.1 | 2020-01-04 | `fsSize()` alpine linux support |
| 4.17.0 | 2020-01-04 | `networkInterfaces()` added dhcp, dnsSuffix, ieee8021xAuth, ieee8021xState | | 4.17.0 | 2020-01-04 | `networkInterfaces()` added dhcp, dnsSuffix, ieee8021xAuth, ieee8021xState |
| 4.16.1 | 2020-01-02 | `networkInterfaces()` bug fix (osx) | | 4.16.1 | 2020-01-02 | `networkInterfaces()` bug fix (osx) |
| 4.16.0 | 2019-11-27 | `networkGatewayDefault()` added | | 4.16.0 | 2019-11-27 | `networkGatewayDefault()` added |

View File

@ -83,6 +83,11 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr>
<th scope="row">4.17.1</th>
<td>2020-01-04</td>
<td><span class="code">fsSize()</span> alpine linux support</td>
</tr>
<tr> <tr>
<th scope="row">4.17.0</th> <th scope="row">4.17.0</th>
<td>2020-01-04</td> <td>2020-01-04</td>

View File

@ -168,7 +168,7 @@
<img class="logo" src="assets/logo.png"> <img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div> <div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div> <div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.17.0</span></div> <div class="version">Current Version: <span id="version">4.17.1</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button> <button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div> </div>
<div class="down"> <div class="down">

View File

@ -37,6 +37,34 @@ let _disk_io = {};
function fsSize(callback) { function fsSize(callback) {
function parseDf(lines) {
let data = [];
lines.forEach(function (line) {
if (line !== '') {
line = line.replace(/ +/g, ' ').split(' ');
if (line && (line[0].startsWith('/')) || (line[6] && line[6] === '/')) {
const fs = line[0];
const fstype = ((_linux || _freebsd || _openbsd || _netbsd) ? line[1] : 'HFS');
const size = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[2] : line[1])) * 1024;
const used = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[3] : line[2])) * 1024;
const use = parseFloat((100.0 * ((_linux || _freebsd || _openbsd || _netbsd) ? line[3] : line[2]) / ((_linux || _freebsd || _openbsd || _netbsd) ? line[2] : line[1])).toFixed(2));
const mount = line[line.length - 1];
if (!data.find(el => (el.fs === fs && el.type === fstype))) {
data.push({
fs,
type: fstype,
size,
used,
use,
mount
});
}
}
}
});
return data;
}
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
let data = []; let data = [];
@ -48,22 +76,16 @@ function fsSize(callback) {
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
//lines.splice(0, 1); data = parseDf(lines);
lines.forEach(function (line) { if (callback) {
if (line !== '') { callback(data);
line = line.replace(/ +/g, ' ').split(' ');
if (line && (line[0].startsWith('/')) || (line[6] && line[6] === '/')) {
data.push({
'fs': line[0],
'type': ((_linux || _freebsd || _openbsd || _netbsd) ? line[1] : 'HFS'),
'size': parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[2] : line[1])) * 1024,
'used': parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[3] : line[2])) * 1024,
'use': parseFloat((100.0 * ((_linux || _freebsd || _openbsd || _netbsd) ? line[3] : line[2]) / ((_linux || _freebsd || _openbsd || _netbsd) ? line[2] : line[1])).toFixed(2)),
'mount': line[line.length - 1]
});
} }
} resolve(data);
}); } else {
exec('df -kPT', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
data = parseDf(lines);
} }
if (callback) { if (callback) {
callback(data); callback(data);
@ -71,6 +93,8 @@ function fsSize(callback) {
resolve(data); resolve(data);
}); });
} }
});
}
if (_sunos) { if (_sunos) {
if (callback) { callback(data); } if (callback) { callback(data); }
resolve(data); resolve(data);
@ -282,7 +306,7 @@ function blockDevices(callback) {
if (_linux) { if (_linux) {
// see https://wiki.ubuntuusers.de/lsblk/ // see https://wiki.ubuntuusers.de/lsblk/
// exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) { // exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) {
exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER', function (error, stdout) { exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER 2>/dev/null', function (error, stdout) {
if (!error) { if (!error) {
let lines = blkStdoutToObject(stdout).split('\n'); let lines = blkStdoutToObject(stdout).split('\n');
data = parseBlk(lines); data = parseBlk(lines);
@ -291,7 +315,7 @@ function blockDevices(callback) {
} }
resolve(data); resolve(data);
} else { } else {
exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER', function (error, stdout) { exec('lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER 2>/dev/null', function (error, stdout) {
if (!error) { if (!error) {
let lines = blkStdoutToObject(stdout).split('\n'); let lines = blkStdoutToObject(stdout).split('\n');
data = parseBlk(lines); data = parseBlk(lines);
@ -439,7 +463,7 @@ function fsStats(callback) {
if ((_fs_speed && !_fs_speed.ms) || (_fs_speed && _fs_speed.ms && Date.now() - _fs_speed.ms >= 500)) { if ((_fs_speed && !_fs_speed.ms) || (_fs_speed && _fs_speed.ms && Date.now() - _fs_speed.ms >= 500)) {
if (_linux) { if (_linux) {
// exec("df -k | grep /dev/", function(error, stdout) { // exec("df -k | grep /dev/", function(error, stdout) {
exec('lsblk | grep /', function (error, stdout) { exec('lsblk 2>/dev/null | grep /', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
let fs_filter = []; let fs_filter = [];
@ -594,7 +618,7 @@ function disksIO(callback) {
// prints Block layer statistics for all mounted volumes // prints Block layer statistics for all mounted volumes
// var cmd = "for mount in `lsblk | grep / | sed -r 's/│ └─//' | cut -d ' ' -f 1`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done"; // var cmd = "for mount in `lsblk | grep / | sed -r 's/│ └─//' | cut -d ' ' -f 1`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done";
// var cmd = "for mount in `lsblk | grep / | sed 's/[│└─├]//g' | awk '{$1=$1};1' | cut -d ' ' -f 1 | sort -u`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done"; // var cmd = "for mount in `lsblk | grep / | sed 's/[│└─├]//g' | awk '{$1=$1};1' | cut -d ' ' -f 1 | sort -u`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done";
let cmd = 'for mount in `lsblk | grep " disk " | sed "s/[│└─├]//g" | awk \'{$1=$1};1\' | cut -d " " -f 1 | sort -u`; do cat /sys/block/$mount/stat | sed -r "s/ +/;/g" | sed -r "s/^;//"; done'; let cmd = 'for mount in `lsblk 2>/dev/null | grep " disk " | sed "s/[│└─├]//g" | awk \'{$1=$1};1\' | cut -d " " -f 1 | sort -u`; do cat /sys/block/$mount/stat | sed -r "s/ +/;/g" | sed -r "s/^;//"; done';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
@ -713,7 +737,7 @@ function diskLayout(callback) {
let cmd = ''; let cmd = '';
if (_linux) { if (_linux) {
exec('export LC_ALL=C; lsblk -ablJO; unset LC_ALL', function (error, stdout) { exec('export LC_ALL=C; lsblk -ablJO 2>/dev/null; unset LC_ALL', function (error, stdout) {
if (!error) { if (!error) {
try { try {
const out = stdout.toString().trim(); const out = stdout.toString().trim();
@ -725,7 +749,7 @@ function diskLayout(callback) {
} }
} catch (e) { } catch (e) {
// fallback to older version of lsblk // fallback to older version of lsblk
const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP; unset LC_ALL').toString(); const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL').toString();
let lines = blkStdoutToObject(out2).split('\n'); let lines = blkStdoutToObject(out2).split('\n');
const data = parseBlk(lines); const data = parseBlk(lines);
devices = data.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null && item.model !== ''; }); devices = data.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null && item.model !== ''; });

View File

@ -474,7 +474,7 @@ function getDarwinNics() {
function getLinuxIfaceConnectionName(interfaceName) { function getLinuxIfaceConnectionName(interfaceName) {
const cmd = `nmcli device status | grep ${interfaceName}`; const cmd = `nmcli device status 2>/dev/null | grep ${interfaceName}`;
try { try {
const result = execSync(cmd).toString(); const result = execSync(cmd).toString();
@ -490,7 +490,7 @@ function getLinuxIfaceConnectionName(interfaceName) {
function getLinuxIfaceDHCPstatus(connectionName) { function getLinuxIfaceDHCPstatus(connectionName) {
let result = false; let result = false;
if (connectionName) { if (connectionName) {
const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.method;`; const cmd = `nmcli connection show "${connectionName}" 2>/dev/null \| grep ipv4.method;`;
try { try {
const result = execSync(cmd).toString(); const result = execSync(cmd).toString();
const resultFormat = result.replace(/\s+/g, ' ').trim(); const resultFormat = result.replace(/\s+/g, ' ').trim();
@ -516,7 +516,7 @@ function getLinuxIfaceDHCPstatus(connectionName) {
function getLinuxIfaceDNSsuffix(connectionName) { function getLinuxIfaceDNSsuffix(connectionName) {
if (connectionName) { if (connectionName) {
const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.dns-search;`; const cmd = `nmcli connection show "${connectionName}" 2>/dev/null \| grep ipv4.dns-search;`;
try { try {
const result = execSync(cmd).toString(); const result = execSync(cmd).toString();
const resultFormat = result.replace(/\s+/g, ' ').trim(); const resultFormat = result.replace(/\s+/g, ' ').trim();
@ -532,7 +532,7 @@ function getLinuxIfaceDNSsuffix(connectionName) {
function getLinuxIfaceIEEE8021xAuth(connectionName) { function getLinuxIfaceIEEE8021xAuth(connectionName) {
if (connectionName) { if (connectionName) {
const cmd = `nmcli connection show "${connectionName}" \| grep 802-1x.eap;`; const cmd = `nmcli connection show "${connectionName}" 2>/dev/null \| grep 802-1x.eap;`;
try { try {
const result = execSync(cmd).toString(); const result = execSync(cmd).toString();
const resultFormat = result.replace(/\s+/g, ' ').trim(); const resultFormat = result.replace(/\s+/g, ' ').trim();

View File

@ -155,7 +155,7 @@ function getLogoFile(distro) {
else if (distro.indexOf('robolinux') !== -1) { else if (distro.indexOf('robolinux') !== -1) {
result = 'robolinux'; result = 'robolinux';
} else if (_linux && distro) { } else if (_linux && distro) {
result = distro.toLowerCase(); result = distro.toLowerCase().trim().replace(/\s+/g, '-');
} }
return result; return result;
} }

View File

@ -117,7 +117,7 @@ function wifiNetworks(callback) {
process.nextTick(() => { process.nextTick(() => {
let result = []; let result = [];
if (_linux) { if (_linux) {
let cmd = 'nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags device wifi list'; let cmd = 'nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags device wifi list 2>/dev/null';
exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) { exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
const parts = stdout.toString().split('ACTIVE:'); const parts = stdout.toString().split('ACTIVE:');