forked from 418sec/serial-number
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
34 lines (30 loc) · 971 Bytes
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
var serialNumber = require('./index');
var fail = function (err) {
console.error('Could not read serial number:', err);
};
serialNumber(function (err) {
if (process.platform !== 'win32' && err && err.toString().match(/Permission denied/i)) {
[
'\x1B[7m' + // inverse style
'Your system requires root/administrative priviledge to access the serial number.' +
'\x1B[27m',
'\x1B[31m' + // red
'Attempting to run command with `sudo` and cache your serial for future use.' +
'\x1B[39m'
].forEach(function (msg) {console.info(msg);});
serialNumber.useSudo(function (err, val) {
if (err) {return fail(err);}
require('fs').writeFile(__dirname + '/cache', val, function (err) {
if (err) {
console.error('Could not write serial number cache file:', err);
} else {
// green
console.info('\x1B[32m' + 'Successfully cached serial number' + '\x1B[39m');
}
});
});
} else if (err) {
fail(err);
}
});