@depup/systeminformation 5.31.4-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/osinfo.js ADDED
@@ -0,0 +1,1303 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // osinfo.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2026
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 3. Operating System
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const os = require('os');
17
+ const fs = require('fs');
18
+ const util = require('./util');
19
+ const exec = require('child_process').exec;
20
+ const execSync = require('child_process').execSync;
21
+
22
+ const _platform = process.platform;
23
+
24
+ const _linux = _platform === 'linux' || _platform === 'android';
25
+ const _darwin = _platform === 'darwin';
26
+ const _windows = _platform === 'win32';
27
+ const _freebsd = _platform === 'freebsd';
28
+ const _openbsd = _platform === 'openbsd';
29
+ const _netbsd = _platform === 'netbsd';
30
+ const _sunos = _platform === 'sunos';
31
+
32
+ // --------------------------
33
+ // Get current time and OS uptime
34
+
35
+ function time() {
36
+ const t = new Date().toString().split(' ');
37
+ let timezoneName = '';
38
+ try {
39
+ timezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
40
+ } catch {
41
+ timezoneName = t.length >= 7 ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : '';
42
+ }
43
+ const result = {
44
+ current: Date.now(),
45
+ uptime: os.uptime(),
46
+ timezone: t.length >= 7 ? t[5] : '',
47
+ timezoneName
48
+ };
49
+ if (_darwin || _linux) {
50
+ try {
51
+ const stdout = execSync('date +%Z && date +%z && ls -l /etc/localtime 2>/dev/null', util.execOptsLinux);
52
+ const lines = stdout.toString().split(os.EOL);
53
+ if (lines.length > 3 && !lines[0]) {
54
+ lines.shift();
55
+ }
56
+ let timezone = lines[0] || '';
57
+ if (timezone.startsWith('+') || timezone.startsWith('-')) {
58
+ timezone = 'GMT';
59
+ }
60
+ return {
61
+ current: Date.now(),
62
+ uptime: os.uptime(),
63
+ timezone: lines[1] ? timezone + lines[1] : timezone,
64
+ timezoneName: lines[2] && lines[2].indexOf('/zoneinfo/') > 0 ? lines[2].split('/zoneinfo/')[1] || '' : ''
65
+ };
66
+ } catch {
67
+ util.noop();
68
+ }
69
+ }
70
+ return result;
71
+ }
72
+
73
+ exports.time = time;
74
+
75
+ // --------------------------
76
+ // Get logo filename of OS distribution
77
+
78
+ function getLogoFile(distro) {
79
+ distro = distro || '';
80
+ distro = distro.toLowerCase();
81
+ let result = _platform;
82
+ if (_windows) {
83
+ result = 'windows';
84
+ } else if (distro.indexOf('mac os') !== -1 || distro.indexOf('macos') !== -1) {
85
+ result = 'apple';
86
+ } else if (distro.indexOf('arch') !== -1) {
87
+ result = 'arch';
88
+ } else if (distro.indexOf('cachy') !== -1) {
89
+ result = 'cachy';
90
+ } else if (distro.indexOf('centos') !== -1) {
91
+ result = 'centos';
92
+ } else if (distro.indexOf('coreos') !== -1) {
93
+ result = 'coreos';
94
+ } else if (distro.indexOf('debian') !== -1) {
95
+ result = 'debian';
96
+ } else if (distro.indexOf('deepin') !== -1) {
97
+ result = 'deepin';
98
+ } else if (distro.indexOf('elementary') !== -1) {
99
+ result = 'elementary';
100
+ } else if (distro.indexOf('endeavour') !== -1) {
101
+ result = 'endeavour';
102
+ } else if (distro.indexOf('fedora') !== -1) {
103
+ result = 'fedora';
104
+ } else if (distro.indexOf('gentoo') !== -1) {
105
+ result = 'gentoo';
106
+ } else if (distro.indexOf('mageia') !== -1) {
107
+ result = 'mageia';
108
+ } else if (distro.indexOf('mandriva') !== -1) {
109
+ result = 'mandriva';
110
+ } else if (distro.indexOf('manjaro') !== -1) {
111
+ result = 'manjaro';
112
+ } else if (distro.indexOf('mint') !== -1) {
113
+ result = 'mint';
114
+ } else if (distro.indexOf('mx') !== -1) {
115
+ result = 'mx';
116
+ } else if (distro.indexOf('openbsd') !== -1) {
117
+ result = 'openbsd';
118
+ } else if (distro.indexOf('freebsd') !== -1) {
119
+ result = 'freebsd';
120
+ } else if (distro.indexOf('opensuse') !== -1) {
121
+ result = 'opensuse';
122
+ } else if (distro.indexOf('pclinuxos') !== -1) {
123
+ result = 'pclinuxos';
124
+ } else if (distro.indexOf('puppy') !== -1) {
125
+ result = 'puppy';
126
+ } else if (distro.indexOf('popos') !== -1) {
127
+ result = 'popos';
128
+ } else if (distro.indexOf('raspbian') !== -1) {
129
+ result = 'raspbian';
130
+ } else if (distro.indexOf('reactos') !== -1) {
131
+ result = 'reactos';
132
+ } else if (distro.indexOf('redhat') !== -1) {
133
+ result = 'redhat';
134
+ } else if (distro.indexOf('slackware') !== -1) {
135
+ result = 'slackware';
136
+ } else if (distro.indexOf('sugar') !== -1) {
137
+ result = 'sugar';
138
+ } else if (distro.indexOf('steam') !== -1) {
139
+ result = 'steam';
140
+ } else if (distro.indexOf('suse') !== -1) {
141
+ result = 'suse';
142
+ } else if (distro.indexOf('mate') !== -1) {
143
+ result = 'ubuntu-mate';
144
+ } else if (distro.indexOf('lubuntu') !== -1) {
145
+ result = 'lubuntu';
146
+ } else if (distro.indexOf('xubuntu') !== -1) {
147
+ result = 'xubuntu';
148
+ } else if (distro.indexOf('ubuntu') !== -1) {
149
+ result = 'ubuntu';
150
+ } else if (distro.indexOf('solaris') !== -1) {
151
+ result = 'solaris';
152
+ } else if (distro.indexOf('tails') !== -1) {
153
+ result = 'tails';
154
+ } else if (distro.indexOf('feren') !== -1) {
155
+ result = 'ferenos';
156
+ } else if (distro.indexOf('robolinux') !== -1) {
157
+ result = 'robolinux';
158
+ } else if (_linux && distro) {
159
+ result = distro.toLowerCase().trim().replace(/\s+/g, '-');
160
+ }
161
+ return result;
162
+ }
163
+
164
+ const WINDOWS_RELEASES = [
165
+ [26200, '25H2'],
166
+ [26100, '24H2'],
167
+ [22631, '23H2'],
168
+ [22621, '22H2'],
169
+ [19045, '22H2'],
170
+ [22000, '21H2'],
171
+ [19044, '21H2'],
172
+ [19043, '21H1'],
173
+ [19042, '20H2'],
174
+ [19041, '2004'],
175
+ [18363, '1909'],
176
+ [18362, '1903'],
177
+ [17763, '1809'],
178
+ [17134, '1803']
179
+ ];
180
+
181
+ function getWindowsRelease(build) {
182
+ for (const [minBuild, label] of WINDOWS_RELEASES) {
183
+ if (build >= minBuild) return label;
184
+ }
185
+ return '';
186
+ }
187
+
188
+ // --------------------------
189
+ // FQDN
190
+
191
+ function getFQDN() {
192
+ let fqdn = os.hostname;
193
+ if (_linux || _darwin) {
194
+ try {
195
+ const stdout = execSync('hostname -f 2>/dev/null', util.execOptsLinux);
196
+ fqdn = stdout.toString().split(os.EOL)[0];
197
+ } catch {
198
+ util.noop();
199
+ }
200
+ }
201
+ if (_freebsd || _openbsd || _netbsd) {
202
+ try {
203
+ const stdout = execSync('hostname 2>/dev/null');
204
+ fqdn = stdout.toString().split(os.EOL)[0];
205
+ } catch {
206
+ util.noop();
207
+ }
208
+ }
209
+ if (_windows) {
210
+ try {
211
+ const stdout = execSync('echo %COMPUTERNAME%.%USERDNSDOMAIN%', util.execOptsWin);
212
+ fqdn = stdout.toString().replace('.%USERDNSDOMAIN%', '').split(os.EOL)[0];
213
+ } catch {
214
+ util.noop();
215
+ }
216
+ }
217
+ return fqdn;
218
+ }
219
+
220
+ // --------------------------
221
+ // OS Information
222
+
223
+ function osInfo(callback) {
224
+ return new Promise((resolve) => {
225
+ process.nextTick(() => {
226
+ let result = {
227
+ platform: _platform === 'win32' ? 'Windows' : _platform,
228
+ distro: 'unknown',
229
+ release: 'unknown',
230
+ codename: '',
231
+ kernel: os.release(),
232
+ arch: os.arch(),
233
+ hostname: os.hostname(),
234
+ fqdn: getFQDN(),
235
+ codepage: '',
236
+ logofile: '',
237
+ serial: '',
238
+ build: '',
239
+ servicepack: '',
240
+ uefi: false
241
+ };
242
+
243
+ if (_linux) {
244
+ exec('cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release', (error, stdout) => {
245
+ /**
246
+ * @namespace
247
+ * @property {string} DISTRIB_ID
248
+ * @property {string} NAME
249
+ * @property {string} DISTRIB_RELEASE
250
+ * @property {string} VERSION_ID
251
+ * @property {string} DISTRIB_CODENAME
252
+ */
253
+ let release = {};
254
+ let lines = stdout.toString().split('\n');
255
+ lines.forEach((line) => {
256
+ if (line.indexOf('=') !== -1) {
257
+ release[line.split('=')[0].trim().toUpperCase()] = line.split('=')[1].trim();
258
+ }
259
+ });
260
+ result.distro = (release.DISTRIB_ID || release.NAME || 'unknown').replace(/"/g, '');
261
+ result.logofile = getLogoFile(result.distro);
262
+ let releaseVersion = (release.VERSION || '').replace(/"/g, '');
263
+ let codename = (release.DISTRIB_CODENAME || release.VERSION_CODENAME || '').replace(/"/g, '');
264
+ const prettyName = (release.PRETTY_NAME || '').replace(/"/g, '');
265
+ if (prettyName.indexOf(result.distro + ' ') === 0) {
266
+ releaseVersion = prettyName.replace(result.distro + ' ', '').trim();
267
+ }
268
+ if (releaseVersion.indexOf('(') >= 0) {
269
+ codename = releaseVersion.split('(')[1].replace(/[()]/g, '').trim();
270
+ releaseVersion = releaseVersion.split('(')[0].trim();
271
+ }
272
+ result.release = (releaseVersion || release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, '');
273
+ result.codename = codename;
274
+ result.codepage = util.getCodepage();
275
+ result.build = (release.BUILD_ID || '').replace(/"/g, '').trim();
276
+ isUefiLinux().then((uefi) => {
277
+ result.uefi = uefi;
278
+ uuid().then((data) => {
279
+ result.serial = data.os;
280
+ if (callback) {
281
+ callback(result);
282
+ }
283
+ resolve(result);
284
+ });
285
+ });
286
+ });
287
+ }
288
+ if (_freebsd || _openbsd || _netbsd) {
289
+ exec('sysctl kern.ostype kern.osrelease kern.osrevision kern.hostuuid machdep.bootmethod kern.geom.confxml', (error, stdout) => {
290
+ let lines = stdout.toString().split('\n');
291
+ const distro = util.getValue(lines, 'kern.ostype');
292
+ const logofile = getLogoFile(distro);
293
+ const release = util.getValue(lines, 'kern.osrelease').split('-')[0];
294
+ const serial = util.getValue(lines, 'kern.uuid');
295
+ const bootmethod = util.getValue(lines, 'machdep.bootmethod');
296
+ const uefiConf = stdout.toString().indexOf('<type>efi</type>') >= 0;
297
+ const uefi = bootmethod ? bootmethod.toLowerCase().indexOf('uefi') >= 0 : uefiConf ? uefiConf : null;
298
+ result.distro = distro || result.distro;
299
+ result.logofile = logofile || result.logofile;
300
+ result.release = release || result.release;
301
+ result.serial = serial || result.serial;
302
+ result.codename = '';
303
+ result.codepage = util.getCodepage();
304
+ result.uefi = uefi || null;
305
+ if (callback) {
306
+ callback(result);
307
+ }
308
+ resolve(result);
309
+ });
310
+ }
311
+ if (_darwin) {
312
+ exec('sw_vers; sysctl kern.ostype kern.osrelease kern.osrevision kern.uuid', (error, stdout) => {
313
+ let lines = stdout.toString().split('\n');
314
+ result.serial = util.getValue(lines, 'kern.uuid');
315
+ result.distro = util.getValue(lines, 'ProductName');
316
+ result.release = (util.getValue(lines, 'ProductVersion', ':', true, true) + ' ' + util.getValue(lines, 'ProductVersionExtra', ':', true, true)).trim();
317
+ result.build = util.getValue(lines, 'BuildVersion');
318
+ result.logofile = getLogoFile(result.distro);
319
+ result.codename = 'macOS';
320
+ result.codename = result.release.indexOf('10.4') > -1 ? 'OS X Tiger' : result.codename;
321
+ result.codename = result.release.indexOf('10.5') > -1 ? 'OS X Leopard' : result.codename;
322
+ result.codename = result.release.indexOf('10.6') > -1 ? 'OS X Snow Leopard' : result.codename;
323
+ result.codename = result.release.indexOf('10.7') > -1 ? 'OS X Lion' : result.codename;
324
+ result.codename = result.release.indexOf('10.8') > -1 ? 'OS X Mountain Lion' : result.codename;
325
+ result.codename = result.release.indexOf('10.9') > -1 ? 'OS X Mavericks' : result.codename;
326
+ result.codename = result.release.indexOf('10.10') > -1 ? 'OS X Yosemite' : result.codename;
327
+ result.codename = result.release.indexOf('10.11') > -1 ? 'OS X El Capitan' : result.codename;
328
+ result.codename = result.release.indexOf('10.12') > -1 ? 'Sierra' : result.codename;
329
+ result.codename = result.release.indexOf('10.13') > -1 ? 'High Sierra' : result.codename;
330
+ result.codename = result.release.indexOf('10.14') > -1 ? 'Mojave' : result.codename;
331
+ result.codename = result.release.indexOf('10.15') > -1 ? 'Catalina' : result.codename;
332
+ result.codename = result.release.startsWith('11.') ? 'Big Sur' : result.codename;
333
+ result.codename = result.release.startsWith('12.') ? 'Monterey' : result.codename;
334
+ result.codename = result.release.startsWith('13.') ? 'Ventura' : result.codename;
335
+ result.codename = result.release.startsWith('14.') ? 'Sonoma' : result.codename;
336
+ result.codename = result.release.startsWith('15.') ? 'Sequoia' : result.codename;
337
+ result.codename = result.release.startsWith('26.') ? 'Tahoe' : result.codename;
338
+ result.uefi = true;
339
+ result.codepage = util.getCodepage();
340
+ if (callback) {
341
+ callback(result);
342
+ }
343
+ resolve(result);
344
+ });
345
+ }
346
+ if (_sunos) {
347
+ result.release = result.kernel;
348
+ exec('uname -o', (error, stdout) => {
349
+ const lines = stdout.toString().split('\n');
350
+ result.distro = lines[0];
351
+ result.logofile = getLogoFile(result.distro);
352
+ if (callback) {
353
+ callback(result);
354
+ }
355
+ resolve(result);
356
+ });
357
+ }
358
+ if (_windows) {
359
+ result.logofile = getLogoFile();
360
+ result.release = result.kernel;
361
+ try {
362
+ const workload = [];
363
+ workload.push(util.powerShell('Get-CimInstance Win32_OperatingSystem | select Caption,SerialNumber,BuildNumber,ServicePackMajorVersion,ServicePackMinorVersion | fl'));
364
+ workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
365
+ workload.push(util.powerShell('Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SystemInformation]::TerminalServerSession'));
366
+ workload.push(util.powerShell('reg query "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" /v DisplayVersion'));
367
+ util.promiseAll(workload).then((data) => {
368
+ const lines = data.results[0] ? data.results[0].toString().split('\r\n') : [''];
369
+ result.distro = util.getValue(lines, 'Caption', ':').trim();
370
+ result.serial = util.getValue(lines, 'SerialNumber', ':').trim();
371
+ result.build = util.getValue(lines, 'BuildNumber', ':').trim();
372
+ result.servicepack = util.getValue(lines, 'ServicePackMajorVersion', ':').trim() + '.' + util.getValue(lines, 'ServicePackMinorVersion', ':').trim();
373
+ result.codepage = util.getCodepage();
374
+ const hyperv = data.results[1] ? data.results[1].toString().toLowerCase() : '';
375
+ result.hypervisor = hyperv.indexOf('true') !== -1;
376
+ const term = data.results[2] ? data.results[2].toString() : '';
377
+ if (data.results[3]) {
378
+ const codenameParts = data.results[3].split('REG_SZ');
379
+ result.codename = codenameParts.length > 1 ? codenameParts[1].trim() : '';
380
+ }
381
+ if (!result.codename) {
382
+ const buildNum = parseInt(result.build, 10);
383
+ result.codename = getWindowsRelease(buildNum);
384
+ }
385
+ result.remoteSession = term.toString().toLowerCase().indexOf('true') >= 0;
386
+ isUefiWindows().then((uefi) => {
387
+ result.uefi = uefi;
388
+ if (callback) {
389
+ callback(result);
390
+ }
391
+ resolve(result);
392
+ });
393
+ });
394
+ } catch {
395
+ if (callback) {
396
+ callback(result);
397
+ }
398
+ resolve(result);
399
+ }
400
+ }
401
+ });
402
+ });
403
+ }
404
+
405
+ exports.osInfo = osInfo;
406
+
407
+ function isUefiLinux() {
408
+ return new Promise((resolve) => {
409
+ process.nextTick(() => {
410
+ fs.stat('/sys/firmware/efi', (err) => {
411
+ if (!err) {
412
+ return resolve(true);
413
+ } else {
414
+ exec('dmesg | grep -E "EFI v"', (error, stdout) => {
415
+ if (!error) {
416
+ const lines = stdout.toString().split('\n');
417
+ return resolve(lines.length > 0);
418
+ }
419
+ return resolve(false);
420
+ });
421
+ }
422
+ });
423
+ });
424
+ });
425
+ }
426
+
427
+ function isUefiWindows() {
428
+ return new Promise((resolve) => {
429
+ process.nextTick(() => {
430
+ try {
431
+ exec('findstr /C:"Detected boot environment" "%windir%\\Panther\\setupact.log"', util.execOptsWin, (error, stdout) => {
432
+ if (!error) {
433
+ const line = stdout.toString().split('\n\r')[0];
434
+ return resolve(line.toLowerCase().indexOf('efi') >= 0);
435
+ } else {
436
+ exec('echo %firmware_type%', util.execOptsWin, (error, stdout) => {
437
+ if (!error) {
438
+ const line = stdout.toString() || '';
439
+ return resolve(line.toLowerCase().indexOf('efi') >= 0);
440
+ } else {
441
+ return resolve(false);
442
+ }
443
+ });
444
+ }
445
+ });
446
+ } catch {
447
+ return resolve(false);
448
+ }
449
+ });
450
+ });
451
+ }
452
+
453
+ function versions(apps, callback) {
454
+ let versionObject = {
455
+ kernel: os.release(),
456
+ apache: '',
457
+ bash: '',
458
+ bun: '',
459
+ deno: '',
460
+ docker: '',
461
+ dotnet: '',
462
+ fish: '',
463
+ gcc: '',
464
+ git: '',
465
+ grunt: '',
466
+ gulp: '',
467
+ homebrew: '',
468
+ java: '',
469
+ mongodb: '',
470
+ mysql: '',
471
+ nginx: '',
472
+ node: '', //process.versions.node,
473
+ npm: '',
474
+ openssl: '',
475
+ perl: '',
476
+ php: '',
477
+ pip3: '',
478
+ pip: '',
479
+ pm2: '',
480
+ postfix: '',
481
+ postgresql: '',
482
+ powershell: '',
483
+ python3: '',
484
+ python: '',
485
+ redis: '',
486
+ systemOpenssl: '',
487
+ systemOpensslLib: '',
488
+ tsc: '',
489
+ v8: process.versions.v8,
490
+ virtualbox: '',
491
+ yarn: '',
492
+ zsh: ''
493
+ };
494
+
495
+ function checkVersionParam(apps) {
496
+ if (apps === '*') {
497
+ return {
498
+ versions: versionObject,
499
+ counter: 34
500
+ };
501
+ }
502
+ if (!Array.isArray(apps)) {
503
+ apps = apps.trim().toLowerCase().replace(/,+/g, '|').replace(/ /g, '|');
504
+ apps = apps.split('|');
505
+ const result = {
506
+ versions: {},
507
+ counter: 0
508
+ };
509
+ apps.forEach((el) => {
510
+ if (el) {
511
+ for (let key in versionObject) {
512
+ if ({}.hasOwnProperty.call(versionObject, key)) {
513
+ if (key.toLowerCase() === el.toLowerCase() && !{}.hasOwnProperty.call(result.versions, key)) {
514
+ result.versions[key] = versionObject[key];
515
+ if (key === 'openssl') {
516
+ result.versions.systemOpenssl = '';
517
+ result.versions.systemOpensslLib = '';
518
+ }
519
+
520
+ if (!result.versions[key]) {
521
+ result.counter++;
522
+ }
523
+ }
524
+ }
525
+ }
526
+ }
527
+ });
528
+ return result;
529
+ }
530
+ }
531
+
532
+ return new Promise((resolve) => {
533
+ process.nextTick(() => {
534
+ if (util.isFunction(apps) && !callback) {
535
+ callback = apps;
536
+ apps = '*';
537
+ } else {
538
+ apps = apps || '*';
539
+ if (typeof apps !== 'string') {
540
+ if (callback) {
541
+ callback({});
542
+ }
543
+ return resolve({});
544
+ }
545
+ }
546
+ const appsObj = checkVersionParam(apps);
547
+ let totalFunctions = appsObj.counter;
548
+
549
+ let functionProcessed = (() => {
550
+ return () => {
551
+ if (--totalFunctions === 0) {
552
+ if (callback) {
553
+ callback(appsObj.versions);
554
+ }
555
+ resolve(appsObj.versions);
556
+ }
557
+ };
558
+ })();
559
+
560
+ let cmd = '';
561
+ try {
562
+ if ({}.hasOwnProperty.call(appsObj.versions, 'openssl')) {
563
+ appsObj.versions.openssl = process.versions.openssl;
564
+ exec('openssl version', (error, stdout) => {
565
+ if (!error) {
566
+ let openssl_string = stdout.toString().split('\n')[0].trim();
567
+ let openssl = openssl_string.split(' ');
568
+ appsObj.versions.systemOpenssl = openssl.length > 0 ? openssl[1] : openssl[0];
569
+ appsObj.versions.systemOpensslLib = openssl.length > 0 ? openssl[0] : 'openssl';
570
+ }
571
+ functionProcessed();
572
+ });
573
+ }
574
+ if ({}.hasOwnProperty.call(appsObj.versions, 'npm')) {
575
+ exec('npm -v', (error, stdout) => {
576
+ if (!error) {
577
+ appsObj.versions.npm = stdout.toString().split('\n')[0];
578
+ }
579
+ functionProcessed();
580
+ });
581
+ }
582
+ if ({}.hasOwnProperty.call(appsObj.versions, 'pm2')) {
583
+ cmd = 'pm2';
584
+ if (_windows) {
585
+ cmd += '.cmd';
586
+ }
587
+ exec(`${cmd} -v`, (error, stdout) => {
588
+ if (!error) {
589
+ let pm2 = stdout.toString().split('\n')[0].trim();
590
+ if (!pm2.startsWith('[PM2]')) {
591
+ appsObj.versions.pm2 = pm2;
592
+ }
593
+ }
594
+ functionProcessed();
595
+ });
596
+ }
597
+ if ({}.hasOwnProperty.call(appsObj.versions, 'yarn')) {
598
+ exec('yarn --version', (error, stdout) => {
599
+ if (!error) {
600
+ appsObj.versions.yarn = stdout.toString().split('\n')[0];
601
+ }
602
+ functionProcessed();
603
+ });
604
+ }
605
+ if ({}.hasOwnProperty.call(appsObj.versions, 'gulp')) {
606
+ cmd = 'gulp';
607
+ if (_windows) {
608
+ cmd += '.cmd';
609
+ }
610
+ exec(`${cmd} --version`, (error, stdout) => {
611
+ if (!error) {
612
+ const gulp = stdout.toString().split('\n')[0] || '';
613
+ appsObj.versions.gulp = (gulp.toLowerCase().split('version')[1] || '').trim();
614
+ }
615
+ functionProcessed();
616
+ });
617
+ }
618
+ if ({}.hasOwnProperty.call(appsObj.versions, 'homebrew')) {
619
+ cmd = 'brew';
620
+ exec(`${cmd} --version`, (error, stdout) => {
621
+ if (!error) {
622
+ const brew = stdout.toString().split('\n')[0] || '';
623
+ appsObj.versions.homebrew = (brew.toLowerCase().split(' ')[1] || '').trim();
624
+ }
625
+ functionProcessed();
626
+ });
627
+ }
628
+ if ({}.hasOwnProperty.call(appsObj.versions, 'tsc')) {
629
+ cmd = 'tsc';
630
+ if (_windows) {
631
+ cmd += '.cmd';
632
+ }
633
+ exec(`${cmd} --version`, (error, stdout) => {
634
+ if (!error) {
635
+ const tsc = stdout.toString().split('\n')[0] || '';
636
+ appsObj.versions.tsc = (tsc.toLowerCase().split('version')[1] || '').trim();
637
+ }
638
+ functionProcessed();
639
+ });
640
+ }
641
+ if ({}.hasOwnProperty.call(appsObj.versions, 'grunt')) {
642
+ cmd = 'grunt';
643
+ if (_windows) {
644
+ cmd += '.cmd';
645
+ }
646
+ exec(`${cmd} --version`, (error, stdout) => {
647
+ if (!error) {
648
+ const grunt = stdout.toString().split('\n')[0] || '';
649
+ appsObj.versions.grunt = (grunt.toLowerCase().split('cli v')[1] || '').trim();
650
+ }
651
+ functionProcessed();
652
+ });
653
+ }
654
+ if ({}.hasOwnProperty.call(appsObj.versions, 'git')) {
655
+ if (_darwin) {
656
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/git') || fs.existsSync('/opt/homebrew/bin/git');
657
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
658
+ exec('git --version', (error, stdout) => {
659
+ if (!error) {
660
+ let git = stdout.toString().split('\n')[0] || '';
661
+ git = (git.toLowerCase().split('version')[1] || '').trim();
662
+ appsObj.versions.git = (git.split(' ')[0] || '').trim();
663
+ }
664
+ functionProcessed();
665
+ });
666
+ } else {
667
+ functionProcessed();
668
+ }
669
+ } else {
670
+ exec('git --version', (error, stdout) => {
671
+ if (!error) {
672
+ let git = stdout.toString().split('\n')[0] || '';
673
+ git = (git.toLowerCase().split('version')[1] || '').trim();
674
+ appsObj.versions.git = (git.split(' ')[0] || '').trim();
675
+ }
676
+ functionProcessed();
677
+ });
678
+ }
679
+ }
680
+ if ({}.hasOwnProperty.call(appsObj.versions, 'apache')) {
681
+ exec('apachectl -v 2>&1', (error, stdout) => {
682
+ if (!error) {
683
+ const apache = (stdout.toString().split('\n')[0] || '').split(':');
684
+ appsObj.versions.apache = apache.length > 1 ? apache[1].replace('Apache', '').replace('/', '').split('(')[0].trim() : '';
685
+ }
686
+ functionProcessed();
687
+ });
688
+ }
689
+ if ({}.hasOwnProperty.call(appsObj.versions, 'nginx')) {
690
+ exec('nginx -v 2>&1', (error, stdout) => {
691
+ if (!error) {
692
+ const nginx = stdout.toString().split('\n')[0] || '';
693
+ appsObj.versions.nginx = (nginx.toLowerCase().split('/')[1] || '').trim();
694
+ }
695
+ functionProcessed();
696
+ });
697
+ }
698
+ if ({}.hasOwnProperty.call(appsObj.versions, 'mysql')) {
699
+ exec('mysql -V', (error, stdout) => {
700
+ if (!error) {
701
+ let mysql = stdout.toString().split('\n')[0] || '';
702
+ mysql = mysql.toLowerCase();
703
+ if (mysql.indexOf(',') > -1) {
704
+ mysql = (mysql.split(',')[0] || '').trim();
705
+ const parts = mysql.split(' ');
706
+ appsObj.versions.mysql = (parts[parts.length - 1] || '').trim();
707
+ } else {
708
+ if (mysql.indexOf(' ver ') > -1) {
709
+ mysql = mysql.split(' ver ')[1];
710
+ appsObj.versions.mysql = mysql.split(' ')[0];
711
+ }
712
+ }
713
+ }
714
+ functionProcessed();
715
+ });
716
+ }
717
+ if ({}.hasOwnProperty.call(appsObj.versions, 'php')) {
718
+ exec('php -v', (error, stdout) => {
719
+ if (!error) {
720
+ const php = stdout.toString().split('\n')[0] || '';
721
+ let parts = php.split('(');
722
+ if (parts[0].indexOf('-')) {
723
+ parts = parts[0].split('-');
724
+ }
725
+ appsObj.versions.php = parts[0].replace(/[^0-9.]/g, '');
726
+ }
727
+ functionProcessed();
728
+ });
729
+ }
730
+ if ({}.hasOwnProperty.call(appsObj.versions, 'redis')) {
731
+ exec('redis-server --version', (error, stdout) => {
732
+ if (!error) {
733
+ const redis = stdout.toString().split('\n')[0] || '';
734
+ const parts = redis.split(' ');
735
+ appsObj.versions.redis = util.getValue(parts, 'v', '=', true);
736
+ }
737
+ functionProcessed();
738
+ });
739
+ }
740
+ if ({}.hasOwnProperty.call(appsObj.versions, 'docker')) {
741
+ exec('docker --version', (error, stdout) => {
742
+ if (!error) {
743
+ const docker = stdout.toString().split('\n')[0] || '';
744
+ const parts = docker.split(' ');
745
+ appsObj.versions.docker = parts.length > 2 && parts[2].endsWith(',') ? parts[2].slice(0, -1) : '';
746
+ }
747
+ functionProcessed();
748
+ });
749
+ }
750
+ if ({}.hasOwnProperty.call(appsObj.versions, 'postfix')) {
751
+ exec('postconf -d | grep mail_version', (error, stdout) => {
752
+ if (!error) {
753
+ const postfix = stdout.toString().split('\n') || [];
754
+ appsObj.versions.postfix = util.getValue(postfix, 'mail_version', '=', true);
755
+ }
756
+ functionProcessed();
757
+ });
758
+ }
759
+ if ({}.hasOwnProperty.call(appsObj.versions, 'mongodb')) {
760
+ exec('mongod --version', (error, stdout) => {
761
+ if (!error) {
762
+ const mongodb = stdout.toString().split('\n')[0] || '';
763
+ appsObj.versions.mongodb = (mongodb.toLowerCase().split(',')[0] || '').replace(/[^0-9.]/g, '');
764
+ }
765
+ functionProcessed();
766
+ });
767
+ }
768
+ if ({}.hasOwnProperty.call(appsObj.versions, 'postgresql')) {
769
+ if (_linux) {
770
+ exec('locate bin/postgres', (error, stdout) => {
771
+ if (!error) {
772
+ const safePath = /^[a-zA-Z0-9/_.-]+$/;
773
+ const postgresqlBin = stdout
774
+ .toString()
775
+ .split('\n')
776
+ .filter((p) => safePath.test(p.trim()))
777
+ .sort();
778
+ if (postgresqlBin.length) {
779
+ execFile(postgresqlBin[postgresqlBin.length - 1], ['-V'], (error, stdout) => {
780
+ if (!error) {
781
+ const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
782
+ appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
783
+ }
784
+ functionProcessed();
785
+ });
786
+ } else {
787
+ functionProcessed();
788
+ }
789
+ } else {
790
+ exec('psql -V', (error, stdout) => {
791
+ if (!error) {
792
+ const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
793
+ appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
794
+ appsObj.versions.postgresql = appsObj.versions.postgresql.split('-')[0];
795
+ }
796
+ functionProcessed();
797
+ });
798
+ }
799
+ });
800
+ } else {
801
+ if (_windows) {
802
+ util.powerShell('Get-CimInstance Win32_Service | select caption | fl').then((stdout) => {
803
+ let serviceSections = stdout.split(/\n\s*\n/);
804
+ serviceSections.forEach((item) => {
805
+ if (item.trim() !== '') {
806
+ let lines = item.trim().split('\r\n');
807
+ let srvCaption = util.getValue(lines, 'caption', ':', true).toLowerCase();
808
+ if (srvCaption.indexOf('postgresql') > -1) {
809
+ const parts = srvCaption.split(' server ');
810
+ if (parts.length > 1) {
811
+ appsObj.versions.postgresql = parts[1];
812
+ }
813
+ }
814
+ }
815
+ });
816
+ functionProcessed();
817
+ });
818
+ } else {
819
+ exec('postgres -V', (error, stdout) => {
820
+ if (!error) {
821
+ const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
822
+ appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
823
+ } else {
824
+ exec('pg_config --version', (error, stdout) => {
825
+ if (!error) {
826
+ const postgresql = stdout.toString().split('\n')[0].split(' ') || [];
827
+ appsObj.versions.postgresql = postgresql.length ? postgresql[postgresql.length - 1] : '';
828
+ }
829
+ });
830
+ }
831
+ functionProcessed();
832
+ });
833
+ }
834
+ }
835
+ }
836
+ if ({}.hasOwnProperty.call(appsObj.versions, 'perl')) {
837
+ exec('perl -v', (error, stdout) => {
838
+ if (!error) {
839
+ const perl = stdout.toString().split('\n') || '';
840
+ while (perl.length > 0 && perl[0].trim() === '') {
841
+ perl.shift();
842
+ }
843
+ if (perl.length > 0) {
844
+ appsObj.versions.perl = perl[0].split('(').pop().split(')')[0].replace('v', '');
845
+ }
846
+ }
847
+ functionProcessed();
848
+ });
849
+ }
850
+ if ({}.hasOwnProperty.call(appsObj.versions, 'python')) {
851
+ if (_darwin) {
852
+ try {
853
+ const stdout = execSync('sw_vers');
854
+ const lines = stdout.toString().split('\n');
855
+ const osVersion = util.getValue(lines, 'ProductVersion', ':');
856
+ const gitHomebrewExists1 = fs.existsSync('/usr/local/Cellar/python');
857
+ const gitHomebrewExists2 = fs.existsSync('/opt/homebrew/bin/python');
858
+ if ((util.darwinXcodeExists() && util.semverCompare('12.0.1', osVersion) < 0) || gitHomebrewExists1 || gitHomebrewExists2) {
859
+ const cmd = gitHomebrewExists1 ? '/usr/local/Cellar/python -V 2>&1' : gitHomebrewExists2 ? '/opt/homebrew/bin/python -V 2>&1' : 'python -V 2>&1';
860
+ exec(cmd, (error, stdout) => {
861
+ if (!error) {
862
+ const python = stdout.toString().split('\n')[0] || '';
863
+ appsObj.versions.python = python.toLowerCase().replace('python', '').trim();
864
+ }
865
+ functionProcessed();
866
+ });
867
+ } else {
868
+ functionProcessed();
869
+ }
870
+ } catch {
871
+ functionProcessed();
872
+ }
873
+ } else {
874
+ exec('python -V 2>&1', (error, stdout) => {
875
+ if (!error) {
876
+ const python = stdout.toString().split('\n')[0] || '';
877
+ appsObj.versions.python = python.toLowerCase().replace('python', '').trim();
878
+ }
879
+ functionProcessed();
880
+ });
881
+ }
882
+ }
883
+ if ({}.hasOwnProperty.call(appsObj.versions, 'python3')) {
884
+ if (_darwin) {
885
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/python3') || fs.existsSync('/opt/homebrew/bin/python3');
886
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
887
+ exec('python3 -V 2>&1', (error, stdout) => {
888
+ if (!error) {
889
+ const python = stdout.toString().split('\n')[0] || '';
890
+ appsObj.versions.python3 = python.toLowerCase().replace('python', '').trim();
891
+ }
892
+ functionProcessed();
893
+ });
894
+ } else {
895
+ functionProcessed();
896
+ }
897
+ } else {
898
+ exec('python3 -V 2>&1', (error, stdout) => {
899
+ if (!error) {
900
+ const python = stdout.toString().split('\n')[0] || '';
901
+ appsObj.versions.python3 = python.toLowerCase().replace('python', '').trim();
902
+ }
903
+ functionProcessed();
904
+ });
905
+ }
906
+ }
907
+ if ({}.hasOwnProperty.call(appsObj.versions, 'pip')) {
908
+ if (_darwin) {
909
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip') || fs.existsSync('/opt/homebrew/bin/pip');
910
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
911
+ exec('pip -V 2>&1', (error, stdout) => {
912
+ if (!error) {
913
+ const pip = stdout.toString().split('\n')[0] || '';
914
+ const parts = pip.split(' ');
915
+ appsObj.versions.pip = parts.length >= 2 ? parts[1] : '';
916
+ }
917
+ functionProcessed();
918
+ });
919
+ } else {
920
+ functionProcessed();
921
+ }
922
+ } else {
923
+ exec('pip -V 2>&1', (error, stdout) => {
924
+ if (!error) {
925
+ const pip = stdout.toString().split('\n')[0] || '';
926
+ const parts = pip.split(' ');
927
+ appsObj.versions.pip = parts.length >= 2 ? parts[1] : '';
928
+ }
929
+ functionProcessed();
930
+ });
931
+ }
932
+ }
933
+ if ({}.hasOwnProperty.call(appsObj.versions, 'pip3')) {
934
+ if (_darwin) {
935
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip3') || fs.existsSync('/opt/homebrew/bin/pip3');
936
+ if (util.darwinXcodeExists() || gitHomebrewExists) {
937
+ exec('pip3 -V 2>&1', (error, stdout) => {
938
+ if (!error) {
939
+ const pip = stdout.toString().split('\n')[0] || '';
940
+ const parts = pip.split(' ');
941
+ appsObj.versions.pip3 = parts.length >= 2 ? parts[1] : '';
942
+ }
943
+ functionProcessed();
944
+ });
945
+ } else {
946
+ functionProcessed();
947
+ }
948
+ } else {
949
+ exec('pip3 -V 2>&1', (error, stdout) => {
950
+ if (!error) {
951
+ const pip = stdout.toString().split('\n')[0] || '';
952
+ const parts = pip.split(' ');
953
+ appsObj.versions.pip3 = parts.length >= 2 ? parts[1] : '';
954
+ }
955
+ functionProcessed();
956
+ });
957
+ }
958
+ }
959
+ if ({}.hasOwnProperty.call(appsObj.versions, 'java')) {
960
+ if (_darwin) {
961
+ // check if any JVM is installed but avoid dialog box that Java needs to be installed
962
+ exec('/usr/libexec/java_home -V 2>&1', (error, stdout) => {
963
+ if (!error && stdout.toString().toLowerCase().indexOf('no java runtime') === -1) {
964
+ // now this can be done savely
965
+ exec('java -version 2>&1', (error, stdout) => {
966
+ if (!error) {
967
+ const java = stdout.toString().split('\n')[0] || '';
968
+ const parts = java.split('"');
969
+ appsObj.versions.java = parts.length === 3 ? parts[1].trim() : '';
970
+ }
971
+ functionProcessed();
972
+ });
973
+ } else {
974
+ functionProcessed();
975
+ }
976
+ });
977
+ } else {
978
+ exec('java -version 2>&1', (error, stdout) => {
979
+ if (!error) {
980
+ const java = stdout.toString().split('\n')[0] || '';
981
+ const parts = java.split('"');
982
+ appsObj.versions.java = parts.length === 3 ? parts[1].trim() : '';
983
+ }
984
+ functionProcessed();
985
+ });
986
+ }
987
+ }
988
+ if ({}.hasOwnProperty.call(appsObj.versions, 'gcc')) {
989
+ if ((_darwin && util.darwinXcodeExists()) || !_darwin) {
990
+ exec('gcc -dumpversion', (error, stdout) => {
991
+ if (!error) {
992
+ appsObj.versions.gcc = stdout.toString().split('\n')[0].trim() || '';
993
+ }
994
+ if (appsObj.versions.gcc.indexOf('.') > -1) {
995
+ functionProcessed();
996
+ } else {
997
+ exec('gcc --version', (error, stdout) => {
998
+ if (!error) {
999
+ const gcc = stdout.toString().split('\n')[0].trim();
1000
+ if (gcc.indexOf('gcc') > -1 && gcc.indexOf(')') > -1) {
1001
+ const parts = gcc.split(')');
1002
+ appsObj.versions.gcc = parts[1].trim() || appsObj.versions.gcc;
1003
+ }
1004
+ }
1005
+ functionProcessed();
1006
+ });
1007
+ }
1008
+ });
1009
+ } else {
1010
+ functionProcessed();
1011
+ }
1012
+ }
1013
+ if ({}.hasOwnProperty.call(appsObj.versions, 'virtualbox')) {
1014
+ exec(util.getVboxmanage() + ' -v 2>&1', (error, stdout) => {
1015
+ if (!error) {
1016
+ const vbox = stdout.toString().split('\n')[0] || '';
1017
+ const parts = vbox.split('r');
1018
+ appsObj.versions.virtualbox = parts[0];
1019
+ }
1020
+ functionProcessed();
1021
+ });
1022
+ }
1023
+ if ({}.hasOwnProperty.call(appsObj.versions, 'bash')) {
1024
+ exec('bash --version', (error, stdout) => {
1025
+ if (!error) {
1026
+ const line = stdout.toString().split('\n')[0];
1027
+ const parts = line.split(' version ');
1028
+ if (parts.length > 1) {
1029
+ appsObj.versions.bash = parts[1].split(' ')[0].split('(')[0];
1030
+ }
1031
+ }
1032
+ functionProcessed();
1033
+ });
1034
+ }
1035
+ if ({}.hasOwnProperty.call(appsObj.versions, 'zsh')) {
1036
+ exec('zsh --version', (error, stdout) => {
1037
+ if (!error) {
1038
+ const line = stdout.toString().split('\n')[0];
1039
+ const parts = line.split('zsh ');
1040
+ if (parts.length > 1) {
1041
+ appsObj.versions.zsh = parts[1].split(' ')[0];
1042
+ }
1043
+ }
1044
+ functionProcessed();
1045
+ });
1046
+ }
1047
+ if ({}.hasOwnProperty.call(appsObj.versions, 'fish')) {
1048
+ exec('fish --version', (error, stdout) => {
1049
+ if (!error) {
1050
+ const line = stdout.toString().split('\n')[0];
1051
+ const parts = line.split(' version ');
1052
+ if (parts.length > 1) {
1053
+ appsObj.versions.fish = parts[1].split(' ')[0];
1054
+ }
1055
+ }
1056
+ functionProcessed();
1057
+ });
1058
+ }
1059
+ if ({}.hasOwnProperty.call(appsObj.versions, 'bun')) {
1060
+ exec('bun -v', (error, stdout) => {
1061
+ if (!error) {
1062
+ const line = stdout.toString().split('\n')[0].trim();
1063
+ appsObj.versions.bun = line;
1064
+ }
1065
+ functionProcessed();
1066
+ });
1067
+ }
1068
+ if ({}.hasOwnProperty.call(appsObj.versions, 'deno')) {
1069
+ exec('deno -v', (error, stdout) => {
1070
+ if (!error) {
1071
+ const line = stdout.toString().split('\n')[0].trim();
1072
+ const parts = line.split(' ');
1073
+ if (parts.length > 1) {
1074
+ appsObj.versions.deno = parts[1];
1075
+ }
1076
+ }
1077
+ functionProcessed();
1078
+ });
1079
+ }
1080
+ if ({}.hasOwnProperty.call(appsObj.versions, 'node')) {
1081
+ exec('node -v', (error, stdout) => {
1082
+ if (!error) {
1083
+ let line = stdout.toString().split('\n')[0].trim();
1084
+ if (line.startsWith('v')) {
1085
+ line = line.slice(1);
1086
+ }
1087
+ appsObj.versions.node = line;
1088
+ }
1089
+ functionProcessed();
1090
+ });
1091
+ }
1092
+ if ({}.hasOwnProperty.call(appsObj.versions, 'powershell')) {
1093
+ if (_windows) {
1094
+ util.powerShell('$PSVersionTable').then((stdout) => {
1095
+ const lines = stdout
1096
+ .toString()
1097
+ .toLowerCase()
1098
+ .split('\n')
1099
+ .map((line) => line.replace(/ +/g, ' ').replace(/ +/g, ':'));
1100
+ appsObj.versions.powershell = util.getValue(lines, 'psversion');
1101
+ functionProcessed();
1102
+ });
1103
+ } else {
1104
+ functionProcessed();
1105
+ }
1106
+ }
1107
+ if ({}.hasOwnProperty.call(appsObj.versions, 'dotnet')) {
1108
+ if (_windows) {
1109
+ util
1110
+ .powerShell(
1111
+ 'gci "HKLM:\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP" -recurse | gp -name Version,Release -EA 0 | where { $_.PSChildName -match "^(?!S)\\p{L}"} | select PSChildName, Version, Release'
1112
+ )
1113
+ .then((stdout) => {
1114
+ const lines = stdout.toString().split('\r\n');
1115
+ let dotnet = '';
1116
+ lines.forEach((line) => {
1117
+ line = line.replace(/ +/g, ' ');
1118
+ const parts = line.split(' ');
1119
+ dotnet =
1120
+ dotnet ||
1121
+ (parts[0].toLowerCase().startsWith('client') && parts.length > 2 ? parts[1].trim() : parts[0].toLowerCase().startsWith('full') && parts.length > 2 ? parts[1].trim() : '');
1122
+ });
1123
+ appsObj.versions.dotnet = dotnet.trim();
1124
+ functionProcessed();
1125
+ });
1126
+ } else {
1127
+ functionProcessed();
1128
+ }
1129
+ }
1130
+ } catch {
1131
+ if (callback) {
1132
+ callback(appsObj.versions);
1133
+ }
1134
+ resolve(appsObj.versions);
1135
+ }
1136
+ });
1137
+ });
1138
+ }
1139
+
1140
+ exports.versions = versions;
1141
+
1142
+ function shell(callback) {
1143
+ return new Promise((resolve) => {
1144
+ process.nextTick(() => {
1145
+ if (_windows) {
1146
+ try {
1147
+ const result = 'CMD';
1148
+ util.powerShell(`Get-CimInstance -className win32_process | where-object {$_.ProcessId -eq ${process.ppid} } | select Name`).then((stdout) => {
1149
+ let result = 'CMD';
1150
+ if (stdout) {
1151
+ if (stdout.toString().toLowerCase().indexOf('powershell') >= 0) {
1152
+ result = 'PowerShell';
1153
+ }
1154
+ }
1155
+ if (callback) {
1156
+ callback(result);
1157
+ }
1158
+ resolve(result);
1159
+ });
1160
+ } catch {
1161
+ if (callback) {
1162
+ callback(result);
1163
+ }
1164
+ resolve(result);
1165
+ }
1166
+ } else {
1167
+ let result = '';
1168
+ exec('echo $SHELL', (error, stdout) => {
1169
+ if (!error) {
1170
+ result = stdout.toString().split('\n')[0];
1171
+ }
1172
+ if (callback) {
1173
+ callback(result);
1174
+ }
1175
+ resolve(result);
1176
+ });
1177
+ }
1178
+ });
1179
+ });
1180
+ }
1181
+
1182
+ exports.shell = shell;
1183
+
1184
+ function getUniqueMacAdresses() {
1185
+ let macs = [];
1186
+ try {
1187
+ const ifaces = os.networkInterfaces();
1188
+ for (let dev in ifaces) {
1189
+ if ({}.hasOwnProperty.call(ifaces, dev)) {
1190
+ ifaces[dev].forEach((details) => {
1191
+ if (details && details.mac && details.mac !== '00:00:00:00:00:00') {
1192
+ const mac = details.mac.toLowerCase();
1193
+ if (macs.indexOf(mac) === -1) {
1194
+ macs.push(mac);
1195
+ }
1196
+ }
1197
+ });
1198
+ }
1199
+ }
1200
+ macs = macs.sort((a, b) => {
1201
+ if (a < b) {
1202
+ return -1;
1203
+ }
1204
+ if (a > b) {
1205
+ return 1;
1206
+ }
1207
+ return 0;
1208
+ });
1209
+ } catch {
1210
+ macs.push('00:00:00:00:00:00');
1211
+ }
1212
+ return macs;
1213
+ }
1214
+
1215
+ function uuid(callback) {
1216
+ return new Promise((resolve) => {
1217
+ process.nextTick(() => {
1218
+ let result = {
1219
+ os: '',
1220
+ hardware: '',
1221
+ macs: getUniqueMacAdresses()
1222
+ };
1223
+ let parts;
1224
+
1225
+ if (_darwin) {
1226
+ exec('system_profiler SPHardwareDataType -json', (error, stdout) => {
1227
+ if (!error) {
1228
+ try {
1229
+ const jsonObj = JSON.parse(stdout.toString());
1230
+ if (jsonObj.SPHardwareDataType && jsonObj.SPHardwareDataType.length > 0) {
1231
+ const spHardware = jsonObj.SPHardwareDataType[0];
1232
+ result.os = spHardware.platform_UUID.toLowerCase();
1233
+ result.hardware = spHardware.serial_number;
1234
+ }
1235
+ } catch {
1236
+ util.noop();
1237
+ }
1238
+ }
1239
+ if (callback) {
1240
+ callback(result);
1241
+ }
1242
+ resolve(result);
1243
+ });
1244
+ }
1245
+ if (_linux) {
1246
+ const cmd = `echo -n "os: "; cat /var/lib/dbus/machine-id 2> /dev/null ||
1247
+ cat /etc/machine-id 2> /dev/null; echo;
1248
+ echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
1249
+ exec(cmd, (error, stdout) => {
1250
+ const lines = stdout.toString().split('\n');
1251
+ result.os = util.getValue(lines, 'os').toLowerCase();
1252
+ result.hardware = util.getValue(lines, 'hardware').toLowerCase();
1253
+ if (!result.hardware) {
1254
+ const lines = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
1255
+ const serial = util.getValue(lines, 'serial');
1256
+ result.hardware = serial || '';
1257
+ }
1258
+ if (callback) {
1259
+ callback(result);
1260
+ }
1261
+ resolve(result);
1262
+ });
1263
+ }
1264
+ if (_freebsd || _openbsd || _netbsd) {
1265
+ exec('sysctl -i kern.hostid kern.hostuuid', (error, stdout) => {
1266
+ const lines = stdout.toString().split('\n');
1267
+ result.hardware = util.getValue(lines, 'kern.hostid', ':').toLowerCase();
1268
+ result.os = util.getValue(lines, 'kern.hostuuid', ':').toLowerCase();
1269
+ if (result.os.indexOf('unknown') >= 0) {
1270
+ result.os = '';
1271
+ }
1272
+ if (result.hardware.indexOf('unknown') >= 0) {
1273
+ result.hardware = '';
1274
+ }
1275
+ if (callback) {
1276
+ callback(result);
1277
+ }
1278
+ resolve(result);
1279
+ });
1280
+ }
1281
+ if (_windows) {
1282
+ let sysdir = '%windir%\\System32';
1283
+ if (process.arch === 'ia32' && Object.prototype.hasOwnProperty.call(process.env, 'PROCESSOR_ARCHITEW6432')) {
1284
+ sysdir = '%windir%\\sysnative\\cmd.exe /c %windir%\\System32';
1285
+ }
1286
+ util.powerShell('Get-CimInstance Win32_ComputerSystemProduct | select UUID | fl').then((stdout) => {
1287
+ let lines = stdout.split('\r\n');
1288
+ result.hardware = util.getValue(lines, 'uuid', ':').toLowerCase();
1289
+ exec(`${sysdir}\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid`, util.execOptsWin, (error, stdout) => {
1290
+ parts = stdout.toString().split('\n\r')[0].split('REG_SZ');
1291
+ result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/gi, '').toLowerCase() : '';
1292
+ if (callback) {
1293
+ callback(result);
1294
+ }
1295
+ resolve(result);
1296
+ });
1297
+ });
1298
+ }
1299
+ });
1300
+ });
1301
+ }
1302
+
1303
+ exports.uuid = uuid;