Repository navigation
Expand file tree
/
Copy pathremote.js
More file actions
executable file
·101 lines (87 loc) · 2.9 KB
/
Copy pathremote.js
File metadata and controls
executable file
·101 lines (87 loc) · 2.9 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const exec = require('child_process').exec;
const spawn = require('child_process').spawn;
const execPush = () => {
return new Promise(function(resolve, reject) {
const yourscript = exec('~/Git/CloudNotes/push "new code"',
(error, stdout, stderr) => {
// console.log(`${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
yourscript.stdout.on('data', (data) => {
console.log('PUSH', data);
});
yourscript.stderr.on('data', (data) => {
console.error('PUSH', data);
});
yourscript.on('close', (code) => {
resolve({
result: 'success',
code: code,
});
});
yourscript.on('error', (code) => {
reject({
result: 'error',
code: code,
});
});
});
};
const execSend = () => {
return new Promise(function(resolve, reject) {
const yourscript = spawn(process.env.HOME + '/Git/CloudNotes/send', ['test args']);
// var yourscript = spawn('/home/charlie/Git/CloudNotes/send test args');
yourscript.stdout.on('data', (data) => {
console.log(`child stdout:\n${data}`);
// console.log("SEND", data);
});
yourscript.stderr.on('data', (data) => {
console.log(`child stderr:\n${data}`);
// console.error("SEND", data);
});
yourscript.on('close', (code) => {
// console.log(`send exited with code ${code}`);
resolve({
result: 'success',
code: code,
});
});
yourscript.on('error', (code) => {
reject(code);
// console.log(`send errored with code ${code}`);
});
});
};
const ssher = () => {
const Client = require('ssh2').Client;
const conn = new Client();
conn.on('ready', function() {
console.log('Client :: ready');
conn.exec('~/bin/pull-key-repos', function(err, stream) {
if (err) throw err;
stream.on('close', function(code, signal) {
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
conn.end();
}).on('data', function(data) {
console.log('STDOUT: ' + data);
}).stderr.on('data', function(data) {
console.log('STDERR: ' + data);
});
});
}).connect({
host: '52.35.150.195',
port: 22,
username: 'ubuntu',
privateKey: require('fs').readFileSync(process.env.HOME + '/.ssh/Home-2016-03'),
});
};
Promise.all([execPush(), execSend()])
.then((code) => {
console.log(code);
ssher();
})
.catch((code) => {
console.log(`send errored with code ${code}`);
});