Update script update's itself first

This commit is contained in:
Zakary Timson 2022-02-10 20:25:21 +00:00
parent c9f99fd36c
commit 28b2000489
2 changed files with 35 additions and 16 deletions

View File

@ -84,16 +84,20 @@ Options:
Automatically download the latest versions of all scripts using wget.
```
[home ~/]> run scripts/update.js
Running script with 1 thread(s), pid 142 and args: [].
Running script with 1 thread(s), pid 18 and args: [].
/scripts/update.js: Updating self:
/scripts/update.js: update.js [==================>] 100% (14.9 MB/s)
/scripts/update.js:
/scripts/update.js: Restarting...
/scripts/update.js: Downloading scripts:
/scripts/update.js:
/scripts/update.js: lib/arg-parser.js [==================>] 100% (15 MB/s)
/scripts/update.js: auto-pwn.js [==================>] 100% (22.3 MB/s)
/scripts/update.js: bruteforce.js [==================>] 100% (22 MB/s)
/scripts/update.js: crawler.js [==================>] 100% (26.2 MB/s)
/scripts/update.js: miner.js [==================>] 100% (10.8 MB/s)
/scripts/update.js: node-manager.js [==================>] 100% (14.6 MB/s)
/scripts/update.js: update.js [==================>] 100% (11.1 MB/s)
/scripts/update.js:
/scripts/update.js:
/scripts/update.js: lib/arg-parser.js [==================>] 100% (13.4 MB/s)
/scripts/update.js: auto-pwn.js [==================>] 100% (15.8 MB/s)
/scripts/update.js: bruteforce.js [==================>] 100% (18 MB/s)
/scripts/update.js: crawler.js [==================>] 100% (23.5 MB/s)
/scripts/update.js: miner.js [==================>] 100% (18.4 MB/s)
/scripts/update.js: node-manager.js [==================>] 100% (22 MB/s)
/scripts/update.js: update.js [==================>] 100% (22.7 MB/s)
/scripts/update.js:
/scripts/update.js: ✅ Done!
```

View File

@ -2,27 +2,42 @@
* Automatically download all the scripts in the repository.
*/
export async function main(ns) {
async function download(file) {
await ns.wget(`${src}${file}`, `${dest}${file}`);
const speed = ~~((Math.random() * 200) + 100) / 10;
ns.tprint(`${file} ${file.length <= 10 ? '\t' : ''}\t [==================>] 100% \t (${speed} MB/s)`);
}
// Setup
const src = 'https://gitlab.zakscode.com/ztimson/BitBurner/-/raw/develop/scripts/';
const dist = '/scripts/';
const dest = '/scripts/';
const fileList = [
'lib/arg-parser.js',
'auto-pwn.js',
'bruteforce.js',
'crawler.js',
'miner.js',
'node-manager.js',
'update.js'
'node-manager.js'
];
// Update self & restart
if(!ns.args.length) {
ns.tprint("Updating self:");
await ns.sleep(1000);
await download('update.js');
await ns.sleep(500);
ns.tprint('');
ns.tprint("Restarting...");
await ns.sleep(2000);
return ns.exec(`${dest}update.js`, ns.getHostname(), 1, 1);
}
// Download each file
ns.tprint("Downloading scripts:");
ns.tprint('');
for(const file of fileList) {
await ns.sleep(500);
await ns.wget(`${src}${file}`, `${dist}${file}`);
const speed = ~~((Math.random() * 200) + 100) / 10;
ns.tprint(`${file} ${file.length <= 10 ? '\t' : ''}\t [==================>] 100% \t (${speed} MB/s)`);
await download(file);
}
ns.tprint('');
ns.tprint('✅ Done!');