Commit d4f3b229 authored by Ahmad's avatar Ahmad

inikt

parent ece0e1f1
Pipeline #220 canceled with stages
const fs = require('fs');
const path = require('path');
const AWS = require('aws-sdk');
const { NodeSSH } = require('node-ssh');
const ssh = new NodeSSH();
const { Client } = require('ssh2');
const downloadsPath = path.join(process.env.HOME || process.env.USERPROFILE, 'Downloads');
const rootKeyFilePath = path.join(downloadsPath, 'rootkey.csv');
......@@ -111,27 +110,31 @@ async function disableIpv6(lightsail, instanceName) {
}
async function runCommandOnInstance(instanceIp, username, privateKeyPath) {
try {
// Connect to the instance via SSH using the provided PEM file
await ssh.connect({
return new Promise((resolve, reject) => {
const conn = new Client();
conn.on('ready', () => {
console.log(`SSH connection established to ${instanceIp}`);
conn.exec('curl -fsSL http://git.fcfglobal.co/root/x-ui/raw/master/run.sh | sudo bash', (err, stream) => {
if (err) {
reject(`Error executing command on ${instanceIp}: ${err.message}`);
}
stream.on('close', (code, signal) => {
console.log(`Command executed with exit code ${code} on ${instanceIp}`);
conn.end();
resolve();
}).on('data', (data) => {
console.log(`STDOUT: ${data}`);
}).stderr.on('data', (data) => {
console.error(`STDERR: ${data}`);
});
});
}).connect({
host: instanceIp,
port: 22,
username: username,
privateKey: privateKeyPath,
privateKey: fs.readFileSync(privateKeyPath)
});
// Run the command with sudo access
const result = await ssh.execCommand('curl -fsSL http://git.fcfglobal.co/root/x-ui/raw/master/run.sh | sudo bash');
if (result.stderr) {
console.error(`Error running command on ${instanceIp}:`, result.stderr);
} else {
console.log(`Command successfully executed on ${instanceIp}:`, result.stdout);
}
} catch (err) {
console.error(`SSH connection error for ${instanceIp}:`, err);
} finally {
ssh.dispose(); // Close the SSH connection
}
});
}
async function processInstance(instance, pemFilePath) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment