-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-to-all.js
40 lines (35 loc) · 1.48 KB
/
deploy-to-all.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
import { scanAndRun } from 'common.js'
/** @param {NS} ns **/
export async function main(ns) {
const args = ns.flags([['help', false]]);
if (args.help || args._.length < 1) {
ns.tprint('This script deploys another script to all servers and runs it with maximum threads possible.');
ns.tprint(`Usage: run ${ns.getScriptName()} script [arguments]`);
ns.tprint('Example:');
ns.tprint(`> run ${ns.getScriptName()} hack-self.js`);
return;
}
// TODO: Don't run on my own servers
//const boughtServers = ns.getPurchasedServers(ns);
const script = args._[0];
const scriptArgs = args._.slice(1);
if (ns.ls(ns.getHostname()).find(f => f === script) == false) {
ns.tprint(`Script '${script}' does not exist. Aborting.`);
return;
}
await scanAndRun(ns, async function(host) {
const threads = Math.max(1, Math.floor((ns.getServerMaxRam(host) - ns.getServerUsedRam(host)) / ns.getScriptRam(script)));
if (scriptArgs.length > 0) {
ns.tprint(`Launching script '${script}' on server '${host}' with ${threads} threads and the following arguments: ${scriptArgs}`);
} else {
ns.tprint(`Launching script '${script}' on server '${host}' with ${threads} threads`);
}
if (threads > 0) {
await ns.scp(script, host);
ns.exec(script, host, threads, ...scriptArgs);
}
else {
// ???????????????????????????
}
});
}