/** @param {import(".").NS } ns */

export async function main(ns) {
    ns.disableLog('ALL');
    let script = 'grow-helper.js';


    let serverMaxRam = ns.getServerMaxRam(`home`);
    let serverUsedRam = ns.getServerUsedRam(`home`);
    let serverFreeRam = serverMaxRam - serverUsedRam;
    let scriptRam = ns.getScriptRam(script, `home`);
    let maxThreads = Math.floor(serverFreeRam / scriptRam);
    if (maxThreads > 0) ns.exec(script, `home`, maxThreads);

    for (let server = 0; ns.serverExists(`home-${server}`); server++) {
        let serverMaxRam = ns.getServerMaxRam(`home-${server}`);
        let serverUsedRam = ns.getServerUsedRam(`home-${server}`);
        let serverFreeRam = serverMaxRam - serverUsedRam;
        let scriptRam = ns.getScriptRam(script, `home-${server}`);
        let maxThreads = Math.floor(serverFreeRam / scriptRam);
        ns.scp(script, `home-${server}`, 'home');
        ns.exec(script, `home-${server}`, maxThreads);
    }
}