-
Notifications
You must be signed in to change notification settings - Fork 0
/
script1.js
67 lines (57 loc) · 1.79 KB
/
script1.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
const { Client } = require('ssh2');
const connSettings = {
host: '88.216.198.24',
port: 22,
username: 'root',
password: 'Cherry2024!!'
// privateKey: require('fs').readFileSync('path_to_private_key'),
};
const wakuNodeCommands = [
'git clone --recurse-submodules https://github.com/waku-org/nwaku',
'cd nwaku && make',
'./nwaku --listen :30303', // Adjust the port as needed
];
const ssh = new Client();
ssh.on('ready', () => {
console.log('SSH connection established');
executeCommands(wakuNodeCommands)
.then((endpoint) => {
console.log(`Waku node deployed successfully. Endpoint: ${endpoint}`);
ssh.end();
})
.catch((err) => {
console.error('Error deploying Waku node:', err);
ssh.end();
});
});
ssh.on('error', (err) => {
console.error('SSH connection error:', err);
ssh.end();
});
ssh.connect(connSettings);
function executeCommands(commands) {
return new Promise((resolve, reject) => {
let endpoint = '';
ssh.exec(commands.join(' && '), (err, stream) => {
if (err) {
reject(err);
return;
}
stream
.on('data', (data) => {
console.log(data.toString());
// Extract the endpoint if available
if (data.includes('Listening on')) {
endpoint = data.toString().match(/:(\d+)/)[0];
}
})
.on('close', (code) => {
if (code === 0) {
resolve(endpoint);
} else {
reject(`Command execution failed with code ${code}`);
}
});
});
});
}