-
Notifications
You must be signed in to change notification settings - Fork 47
/
deploy.js
29 lines (26 loc) · 1.06 KB
/
deploy.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
/** @param {NS} ns **/
export async function main(ns) {
const args = ns.flags([["help", false]]);
if (args.help || args._.length < 2) {
ns.tprint("This script deploys another script on a server with maximum threads possible.");
ns.tprint(`Usage: run ${ns.getScriptName()} HOST SCRIPT ARGUMENTS`);
ns.tprint("Example:");
ns.tprint(`> run ${ns.getScriptName()} n00dles basic_hack.js foodnstuff`);
return;
}
const host = args._[0];
const script = args._[1];
const script_args = args._.slice(2);
if (!ns.serverExists(host)) {
ns.tprint(`Server '${host}' does not exist. Aborting.`);
return;
}
if (!ns.ls(ns.getHostname()).find(f => f === script)) {
ns.tprint(`Script '${script}' does not exist. Aborting.`);
return;
}
const threads = Math.floor((ns.getServerMaxRam(host) - ns.getServerUsedRam(host)) / ns.getScriptRam(script));
ns.tprint(`Launching script '${script}' on server '${host}' with ${threads} threads and the following arguments: ${script_args}`);
await ns.scp(script, ns.getHostname(), host);
ns.exec(script, host, threads, ...script_args);
}