-
Notifications
You must be signed in to change notification settings - Fork 0
/
jennic-burn-image.js
81 lines (72 loc) · 2.36 KB
/
jennic-burn-image.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
77
78
79
80
81
#!/usr/bin/env node
// Copyright (c) 2014, Łukasz Walukiewicz <lukasz@walukiewicz.eu>. Some Rights Reserved.
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// Part of the walkner-tools project <http://lukasz.walukiewicz.eu/p/walkner-tools>
var optimist = require('optimist');
var util = require('./lib/util');
var burnJennicImage = require('./lib/burnJennicImage');
var USAGE = [
"Burn Jennic Image",
"",
"1. If the kill argument is specified, executes the killall command ",
" with the specified process names on the remote host through Telnet.",
"2. Uploads the specified image file and all the files from the specified",
" burner directory.",
"3. Changes a mode of the burner utility files to executable.",
"4. Runs the burner utility with the image file as the first argument.",
"5. Deletes the image file and the burner utility files.",
"6. If the reboot option is specified, executes the reboot command on",
" the remote host through Telnet.",
"7. If a numeric value was specified for the reboot option, then the host",
" will be pinged until it responds or up to the specified number of seconds.",
"",
"NOTE: The burner utility directory must contain a jennic-burner.sh file,",
" which should burn a Jennic image file specified as the first argument",
" and then exit.",
"",
"Usage: jennic-burn-image.js [options] host"
];
var argv = optimist
.usage(USAGE.join('\n'))
.describe("user", "string Remote user (default: root)")
.describe("pass", "string Remote password (default: root)")
.describe("reboot", "number Reboot the device after all ops (default: -1)")
.describe("kill", "string Process to kill before burning")
.describe("burner", "string Path to the burner utility (default: data/jennic-burner/)")
.describe("image", "string Path to the Jennic image")
.argv;
if (argv._.length === 0)
{
optimist.showHelp();
util.errit("Host is required.");
}
var reboot = -1;
if (argv.reboot === true)
{
reboot = 0;
}
else if (/^[0-9]+$/.test(argv.reboot))
{
reboot = parseInt(argv.reboot);
}
burnJennicImage({
host: argv._[0],
user: argv.user,
pass: argv.pass,
pipe: true,
kill: argv.kill,
burner: argv.burner,
image: argv.image,
reboot: reboot
}, function(err)
{
console.log();
if (err)
{
console.error(err.message);
}
else
{
console.log("Done, bye!");
}
});