-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
53 lines (47 loc) · 1.16 KB
/
index.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
var Step = require('step');
var KEYFILE = '/home/strider/keyfile';
function getErrorFromExitCode(exitCode) {
var err = null;
if (exitCode !== 0) {
err = "process exited with status " + exitCode;
}
return err;
}
function writeFiles(privKey, keyMode, cb, contextCmd) {
Step(
function() {
contextCmd({command: 'write-to-file', args: [privKey, KEYFILE]}, this);
},
function(exitCode) {
contextCmd({command: 'chmod', args: [keyMode, KEYFILE]}, this);
},
function(exitCode) {
cb(getErrorFromExitCode(exitCode));
}
);
return;
}
function run(options, cb) {
var contextCmd = options.contextCmd;
var split = options.cmd.split(/\s+/);
var cmd = split[0];
var args = split.slice(1);
Step(
function() {
writeFiles(options.privKey, '0600', this, contextCmd);
},
function(err) {
if (err) {
console.log("Error writing files: %s", err);
return cb(err, null);
}
contextCmd({ command : cmd, args : args }, this);
},
function(exitCode, stdout, stderr) {
cb(getErrorFromExitCode(exitCode), stdout, stderr, exitCode);
}
);
}
module.exports = {
run: run
}