-
-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathinstall.js
More file actions
61 lines (42 loc) · 1.45 KB
/
Copy pathinstall.js
File metadata and controls
61 lines (42 loc) · 1.45 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
// For NPM publishing purposes
const fs = require("fs");
const path = require("path");
const version = require("./package.json").version;
const platform = process.platform;
const arch = process.arch;
function getAssetName() {
if (platform === "linux" && arch === "x64") {
return `noir-v${version}-linux-x86_64`;
}
if (platform === "linux" && arch === "arm64") {
return `noir-v${version}-linux-arm64`;
}
if (platform === "darwin" && arch === "arm64") {
return `noir-v${version}-osx-arm64`;
}
if (platform === "darwin" && arch === "x64") {
return `noir-v${version}-osx-x86_64`;
}
throw new Error(`Unsupported platform: ${platform} ${arch}`);
}
(async () => {
const asset = getAssetName();
const downloadUrl =
`https://github.com/owasp-noir/noir/releases/download/v${version}/${asset}`;
const binDir = path.join(__dirname, "bin");
const output = path.join(binDir, "noir");
fs.mkdirSync(binDir, { recursive: true });
console.log(`Downloading ${asset}...`);
const response = await fetch(downloadUrl);
if (!response.ok) {
throw new Error(`Download failed (${response.status})`);
}
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync(output, buffer);
fs.chmodSync(output, 0o755);
console.log("Binary installed.");
})().catch((err) => {
console.error(err.message);
process.exit(1);
});