-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathu_deploy.js
More file actions
29 lines (27 loc) · 1 KB
/
Copy pathu_deploy.js
File metadata and controls
29 lines (27 loc) · 1 KB
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],
["target", ""],
["script", ""],
["threads", 0]
]);
if (!args.script || !args.target || args.help) {
ns.tprint("This script deploys a script to a target server.");
ns.tprint(`Usage: run ${ns.getScriptName()} --target HOSTNAME --script SCRIPT --threads 2`);
ns.tprint("Example:");
ns.tprint(`> run ${ns.getScriptName()} --target n00dles --script run_me.js`);
return;
}
const maxThreads = Math.floor((ns.getServerMaxRam(args.target) - ns.getServerUsedRam(args.target)) / ns.getScriptRam(args.script));
let threads = args.threads;
if(threads < 1 || threads > maxThreads){
threads = maxThreads;
}
if(threads < 1){
ns.tprint(`${args.target} cannot support this script, not enough RAM.`)
}
ns.tprint(`Launching ${args.script} on ${args.target} with ${threads} threads.`);
await ns.scp(args.script, "home", args.target);
ns.exec(args.script, args.target, threads);
}