46 lines
No EOL
1.4 KiB
TypeScript
46 lines
No EOL
1.4 KiB
TypeScript
import { NS, AutocompleteData } from '@ns'
|
|
import { installBatchFilePack, isBatchFilePackInstalled, scpBatchFilePack, growDaemon, requestGrow } from './lib/batchbase';
|
|
import { parse } from './lib/flag';
|
|
|
|
|
|
function help(ns:NS):void{
|
|
ns.tprint("run cmd [target(hostname)] --hostname hostname")
|
|
}
|
|
|
|
// eslint-disable-next-line require-await
|
|
export async function main(ns : NS) : Promise<void> {
|
|
const flag = parse(ns.args.map(String))
|
|
|
|
const hostname: string|undefined = flag.hostname ?? flag.n;
|
|
if(!hostname){
|
|
ns.tprint("hostname is not set");
|
|
help(ns);
|
|
return;
|
|
}
|
|
if(flag._.length == 0){
|
|
ns.tprint("target is not set");
|
|
help(ns);
|
|
return;
|
|
}
|
|
const target = flag._[0].toString();
|
|
ns.print("check batch file pack ...")
|
|
if(!isBatchFilePackInstalled(ns)){
|
|
await installBatchFilePack(ns);
|
|
}
|
|
const server = ns.getServer(hostname)
|
|
await scpBatchFilePack(ns,hostname);
|
|
ns.print("request hwgw ...")
|
|
requestGrow({
|
|
hostname,
|
|
usableRam: server.maxRam - server.ramUsed,
|
|
},target);
|
|
ns.print("request hwgw done")
|
|
ns.print("start batch daemon ...");
|
|
await growDaemon(ns, target);
|
|
ns.print("end grow daemon");
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
export function autocomplete(data : AutocompleteData, args : string[]) : string[] {
|
|
return [...data.servers]
|
|
} |