forked from volumio/Volumio2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogsubmit.js
executable file
·76 lines (60 loc) · 1.9 KB
/
logsubmit.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var execSync = require('child_process').execSync;
var exec = require('child_process').exec;
var fs = require('fs');
var commandArray = [
"cat /proc/version",
"cat /etc/os-release",
"ifconfig",
"iwconfig",
"aplay -l",
"ps -ef",
"sudo journalctl -p 7"
];
var logFile = "/tmp/logondemand";
// Let's start fresh!
execSync("date >" + logFile);
if (process.argv.slice(2)) {
var args = process.argv.slice(2);
} else {
var args = ['Unknown'];
}
try {
var args = process.argv.slice(2);
//If description is supplied, add it
execSync("echo " + args[0] + " >>" + logFile);
} catch (e) {
console.log(error)
}
execSync("cat /tmp/logfields >> " + logFile);
for (var itemN in commandArray) {
var item = commandArray[itemN];
var itemWithoutput = item + " >>" + logFile + " 2>&1"
execSync(itemWithoutput);
}
var variant = getSystemVersion();
var command = '/usr/bin/curl -X POST -H "Content-Type: multipart/form-data" -F "logFile=@'+logFile+'" -F "desc='+args[0]+'" -F "variant='+variant+'" "http://logs.volumio.org:7171/logs/v1"';
exec(command , {uid: 1000, gid: 1000, encoding: 'utf8'}, function (error, stdout, stderr) {
if (error !== null) {
console.log('Canot send bug report: ' + error);
} else {
console.log(stdout)
}
execSync("rm " + logFile);
execSync("rm /tmp/logfields");
});
function randomIntInc (low, high) {
return Math.floor(Math.random() * (high - low + 1) + low);
}
function getSystemVersion () {
var self = this;
var file = fs.readFileSync('/etc/os-release').toString().split('\n');
var nLines = file.length;
var str;
for (var l = 0; l < nLines; l++) {
if (file[l].match(/VOLUMIO_VARIANT/i)) {
str = file[l].split('=');
var variant = str[1].replace(/\"/gi, "");
return variant;
}
}
};