forked from doublerebel/nvram-cfg-parser
-
Notifications
You must be signed in to change notification settings - Fork 3
/
nvramcfg.js
executable file
·53 lines (44 loc) · 1.03 KB
/
nvramcfg.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
#!/usr/bin/env node
var NvramParser, action, die, filename, print,
spawn = require('child_process').spawn,
jsonDiffPath = "node_modules/json-diff/bin/json-diff.js";
print = function(s) {
console.log(s);
};
dump = function(b) {
process.stdout.write(b);
}
NvramParser = require("./nvram-parser");
NvramParser.pretty = true;
die = function(e) {
NvramParser.error(e);
process.exit(1);
};
action = process.argv[2];
if (!action) {
die("must specify action");
}
filename = process.argv[3];
if (!filename) {
die("must specify filename");
}
switch (action) {
case "decode":
NvramParser.decode(filename, print);
break;
case "encode":
var format = filename;
if (!(filename = process.argv[4])) {
die("must specify format: original or arm");
}
NvramParser.encode(filename, format, dump);
break;
case "diff":
if (!process.argv[4]) {
die("must specify 2nd filename");
}
require('json-diff/lib/cli')(process.argv.slice(3));
break;
default:
die("invalid action " + action);
}