~ Tested and working!
This commit is contained in:
53
index.ts
53
index.ts
@@ -1,27 +1,30 @@
|
|||||||
const { pathExists, copy, readJSON } = require('fs-extra');
|
const { pathExists, copy, readJSON, writeFile, ensureDir } = require('fs-extra');
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
const { Client } = require('ssh2');
|
const { Client } = require('ssh2');
|
||||||
|
|
||||||
|
var outputDir = join(__filename, '..', 'output');
|
||||||
|
|
||||||
var configPath = join(__filename, '..', 'config.json');
|
var configPath = join(__filename, '..', 'config.json');
|
||||||
var defaultConfigPath = join(__filename, '..', 'defaultConfig.json');
|
var defaultConfigPath = join(__filename, '..', 'defaultConfig.json');
|
||||||
|
|
||||||
var config: Config = null;
|
var config: Config = null;
|
||||||
|
|
||||||
pathExists(configPath, (exists, err) => {
|
console.log('S T A R T I N G M U L T I S S H D E P L O Y E R');
|
||||||
if (err) throw err;
|
var prepareDeploy = async () => {
|
||||||
if (exists) {
|
await ensureDir(outputDir);
|
||||||
readJSON(config, (configJson, err) => {
|
|
||||||
if (err) throw err;
|
|
||||||
config = configJson;
|
|
||||||
|
|
||||||
|
var exists = await pathExists(configPath);
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
config = await readJSON(configPath);
|
||||||
startPrepare();
|
startPrepare();
|
||||||
});
|
} else {
|
||||||
} else
|
|
||||||
copy(defaultConfigPath, configPath, (err) => {
|
copy(defaultConfigPath, configPath, (err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(`----- Default config has been copied -----`);
|
console.log(`----- Default config has been copied -----`);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function startPrepare() {
|
function startPrepare() {
|
||||||
console.log(`----- STARTING PREPARE ON ${config.addresses.length} DEVICES -----`);
|
console.log(`----- STARTING PREPARE ON ${config.addresses.length} DEVICES -----`);
|
||||||
@@ -38,19 +41,33 @@ function startPrepare() {
|
|||||||
conn
|
conn
|
||||||
.on('ready', () => {
|
.on('ready', () => {
|
||||||
console.log(' Client :: ready');
|
console.log(' Client :: ready');
|
||||||
|
|
||||||
|
var output = `Device=${address}\n--- Starting ${new Date().toLocaleTimeString('NL-nl')} ---\n`;
|
||||||
|
|
||||||
conn.shell((err, stream) => {
|
conn.shell((err, stream) => {
|
||||||
if (err) throw err;
|
if (err) {
|
||||||
|
console.error(' Error starting shell:', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.on('close', () => {
|
.on('close', (code, signal) => {
|
||||||
console.log(' Stream :: close');
|
console.log(' Stream :: close :: code: ' + code + ', signal: ' + signal);
|
||||||
conn.end();
|
conn.end();
|
||||||
|
output = `${output}\n--- Finished ${new Date().toLocaleTimeString('NL-nl')} ---`;
|
||||||
|
writeFile(join(outputDir, `${address}.log`), output, (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
console.log(`Finished device ${address}`);
|
console.log(`Finished device ${address}`);
|
||||||
handle(i + 1);
|
handle(i + 1);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.on('data', (data) => {
|
.on('data', (data) => {
|
||||||
console.log(' Output: ' + data);
|
output = `${output}${data}`;
|
||||||
|
console.log(data.toString());
|
||||||
});
|
});
|
||||||
stream.end(`${config.payload.join('\n')}\nexit\n`);
|
|
||||||
|
stream.write(`${config.payload.join('\n')}\nexit\n`);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.connect({
|
.connect({
|
||||||
@@ -58,11 +75,17 @@ function startPrepare() {
|
|||||||
port: port,
|
port: port,
|
||||||
username: config.username,
|
username: config.username,
|
||||||
password: config.password
|
password: config.password
|
||||||
|
})
|
||||||
|
.on('error', (error) => {
|
||||||
|
console.log(`Error whilst connecting to address ${address}`, error);
|
||||||
|
handle(i + 1);
|
||||||
});
|
});
|
||||||
} else console.log('----- FINISHED ALL DEVICES -----');
|
} else console.log('----- FINISHED ALL DEVICES -----');
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepareDeploy();
|
||||||
|
|
||||||
interface Config {
|
interface Config {
|
||||||
addresses: string[];
|
addresses: string[];
|
||||||
username: string;
|
username: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user