Guest User

Improved tutorial startup script

a guest
Mar 7th, 2024
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** @param {NS} ns */
  2. export async function main(ns) {
  3.     // Array of all servers that don't need any ports opened
  4.     // to gain root access. These have 16 GB of RAM
  5.     const servers0Port = ["sigma-cosmetics",
  6.                         "joesguns",
  7.                         "nectar-net",
  8.                         "hong-fang-tea",
  9.                         "harakiri-sushi"];
  10.  
  11.     // Array of all servers that only need 1 port opened
  12.     // to gain root access. These have 32 GB of RAM
  13.     const servers1Port = ["neo-net",
  14.                         "zer0",
  15.                         "max-hardware",
  16.                         "iron-gym"];
  17.  
  18.         const script_filename = 'early-hack-template.js';
  19.  
  20.         //const script_ram = 2.6;       // GB, Memory usage of original original script.
  21.         const script_ram = ns.getScriptRam(script_filename);
  22.  
  23.         // Calculate how many threads of the script we can run on a system
  24.         // with 16 and 32 GB of RAM.
  25.         const threads16 = Math.max(1, Math.floor(script_ram / 16) );
  26.         const threads32 = Math.max(1, Math.floor(script_ram / 32) );
  27.  
  28.     // Copy our scripts onto each server that requires 0 ports
  29.     // to gain root access. Then use nuke() to gain admin access and
  30.     // run the scripts.
  31.     for (let i = 0; i < servers0Port.length; ++i) {
  32.         const serv = servers0Port[i];
  33.  
  34.         if (ns.scp(script_filename, serv) === false) {
  35.                     ns.tprint(`ERROR: copying '${script_filename} to "${serv}"`);
  36.                     continue;   // Skip to next server in the for loop
  37.                 }
  38.        ns.nuke(serv);
  39.        let pid = ns.exec(script_filename, serv, threads16);
  40.                 if (pid === 0) {
  41.                     ns.tprint(`ERROR: Unable to execute ${script_filename} on "${serv}"`);
  42.                 }
  43.    }
  44.  
  45.    // Wait until we acquire the "BruteSSH.exe" program
  46.    while (!ns.fileExists("BruteSSH.exe")) {
  47.                 ns.print("Waiting for BruteSSH.exe to be purchased or created.");
  48.         await ns.sleep(60 * 1000);  // 60 secs or 60000 milliseconds
  49.    }
  50.  
  51.  
  52.  
  53.    // Copy our scripts onto each server that requires 1 port
  54.    // to gain root access. Then use brutessh() and nuke()
  55.    // to gain admin access and run the scripts.
  56.    for (let i = 0; i < servers1Port.length; ++i) {
  57.        const serv = servers1Port[i];
  58.  
  59.        if (ns.scp(script_filename, serv) === false) {
  60.                     ns.tprint(`ERROR: copying '${script_filename} to "${serv}"`);
  61.                     continue;   // Skip to next server in the for loop
  62.                 }
  63.         ns.brutessh(serv);
  64.         ns.nuke(serv);
  65.         let pid = ns.exec(script_filename, serv, threads32);
  66.                 if (pid === 0) {
  67.                     ns.tprint(`ERROR: Unable to execute ${script_filename} on "${serv}"`);
  68.                 }
  69.     }
  70. }
Add Comment
Please, Sign In to add comment