@bsdkrun/cli 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/bin/bsdkrun.js +45 -0
- package/package.json +49 -0
- package/scripts/platform.js +81 -0
- package/scripts/postinstall.js +180 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @bsdkrun/cli
|
|
2
|
+
|
|
3
|
+
Install the [`bsdkrun`](https://github.com/tsirysndr/bsdkrun) host binary via npm.
|
|
4
|
+
|
|
5
|
+
`bsdkrun` is a Firecracker-style **microVM launcher for BSD and Linux (OCI) guests**,
|
|
6
|
+
built on [libkrun](https://github.com/containers/libkrun) (Hypervisor.framework on
|
|
7
|
+
macOS, KVM on Linux).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install -g @bsdkrun/cli
|
|
13
|
+
# then
|
|
14
|
+
bsdkrun --help
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or run it without a global install:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npx @bsdkrun/cli linux alpine -- echo hello
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
On install, a prebuilt `bsdkrun` for your platform is downloaded from the matching
|
|
24
|
+
[GitHub release](https://github.com/tsirysndr/bsdkrun/releases) and its SHA-256
|
|
25
|
+
verified. The **Linux** archive bundles libkrun (see below); the **macOS** archive
|
|
26
|
+
is just the binary and links Homebrew's libkrun.
|
|
27
|
+
|
|
28
|
+
## Supported platforms
|
|
29
|
+
|
|
30
|
+
| OS | Arch | Notes |
|
|
31
|
+
| ------ | ------------- | ------------------------------ |
|
|
32
|
+
| macOS | `arm64` | Apple Silicon only (no Intel) |
|
|
33
|
+
| Linux | `x64` | KVM (`/dev/kvm`) |
|
|
34
|
+
| Linux | `arm64` | KVM (`/dev/kvm`) |
|
|
35
|
+
|
|
36
|
+
Any other platform/arch (Windows, Intel macOS, 32-bit, …) is **unsupported** and
|
|
37
|
+
the install will fail with a clear message.
|
|
38
|
+
|
|
39
|
+
## Runtime prerequisites
|
|
40
|
+
|
|
41
|
+
- **macOS:** install **libkrun** (the binary links it at runtime):
|
|
42
|
+
`brew tap libkrun/krun && brew install libkrun`.
|
|
43
|
+
- **Linux:** **libkrun is bundled** — the archive ships `libkrun.so`/`libkrunfw.so`
|
|
44
|
+
(from the [PVH-enabled fork](https://github.com/tsirysndr/libkrun/tree/feat/pvh-boot))
|
|
45
|
+
next to `bsdkrun`, rpath'd to `$ORIGIN`, so no separate libkrun install is needed.
|
|
46
|
+
You also need KVM access (`/dev/kvm`).
|
|
47
|
+
|
|
48
|
+
**Guest networking (`gvproxy`) is auto-installed.** Postinstall also downloads the
|
|
49
|
+
matching [`gvproxy`](https://github.com/containers/gvisor-tap-vsock) for your
|
|
50
|
+
platform into the package and wires `bsdkrun` to it, so user-mode networking works
|
|
51
|
+
out of the box. It's best-effort — if the download fails the guest still boots
|
|
52
|
+
without a NIC, and you can install gvproxy yourself (`brew install gvproxy`) or set
|
|
53
|
+
`BSDKRUN_GVPROXY`. Skip it with `BSDKRUN_SKIP_GVPROXY=1`.
|
|
54
|
+
|
|
55
|
+
## Environment variables
|
|
56
|
+
|
|
57
|
+
| Variable | Effect |
|
|
58
|
+
| ------------------------- | ------------------------------------------------------------ |
|
|
59
|
+
| `BSDKRUN_SKIP_DOWNLOAD` | Skip the postinstall download entirely. |
|
|
60
|
+
| `BSDKRUN_BINARY` | Install a local binary (path) instead of downloading. |
|
|
61
|
+
| `BSDKRUN_DOWNLOAD_BASE` | Override the release download base URL (for mirrors/testing).|
|
|
62
|
+
| `BSDKRUN_SKIP_GVPROXY` | Skip the gvproxy (user-mode networking) download. |
|
|
63
|
+
| `BSDKRUN_GVPROXY` | Path to an existing gvproxy; skips its download and is used at runtime. |
|
|
64
|
+
| `BSDKRUN_GVPROXY_VERSION` | Pin a gvproxy release tag (default: latest). |
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
package/bin/bsdkrun.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// Thin launcher: exec the platform-native `bsdkrun` binary that postinstall
|
|
5
|
+
// downloaded into ./binaries/, forwarding argv, stdio, and the exit status.
|
|
6
|
+
|
|
7
|
+
const fs = require("node:fs");
|
|
8
|
+
const { spawnSync } = require("node:child_process");
|
|
9
|
+
const { binaryPath, gvproxyPath } = require("../scripts/platform.js");
|
|
10
|
+
|
|
11
|
+
const bin = binaryPath();
|
|
12
|
+
|
|
13
|
+
// Point bsdkrun at the gvproxy postinstall bundled, unless the user already
|
|
14
|
+
// picked one (BSDKRUN_GVPROXY takes precedence in the native binary too, but
|
|
15
|
+
// setting it here also wins over a different gvproxy on PATH).
|
|
16
|
+
if (!process.env.BSDKRUN_GVPROXY) {
|
|
17
|
+
const gv = gvproxyPath();
|
|
18
|
+
if (fs.existsSync(gv)) {
|
|
19
|
+
process.env.BSDKRUN_GVPROXY = gv;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!fs.existsSync(bin)) {
|
|
24
|
+
console.error(
|
|
25
|
+
"[bsdkrun] native binary not found at " +
|
|
26
|
+
bin +
|
|
27
|
+
"\nThe postinstall download may have been skipped (e.g. `npm install --ignore-scripts`).\n" +
|
|
28
|
+
"Reinstall @bsdkrun/cli, or run its install script manually:\n" +
|
|
29
|
+
" node " +
|
|
30
|
+
require("node:path").join(__dirname, "..", "scripts", "postinstall.js")
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const res = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
36
|
+
|
|
37
|
+
if (res.error) {
|
|
38
|
+
console.error("[bsdkrun] failed to launch: " + res.error.message);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
// Propagate a terminating signal as the conventional 128+signal exit code.
|
|
42
|
+
if (res.signal) {
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
process.exit(res.status === null ? 1 : res.status);
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bsdkrun/cli",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Firecracker-style microVM launcher for BSD and Linux (OCI) guests, built on libkrun. Installs the prebuilt bsdkrun host binary for your platform.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/tsirysndr/bsdkrun#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/tsirysndr/bsdkrun.git",
|
|
10
|
+
"directory": "npm"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/tsirysndr/bsdkrun/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"bsdkrun",
|
|
17
|
+
"microvm",
|
|
18
|
+
"libkrun",
|
|
19
|
+
"freebsd",
|
|
20
|
+
"netbsd",
|
|
21
|
+
"vm",
|
|
22
|
+
"sandbox",
|
|
23
|
+
"firecracker",
|
|
24
|
+
"cli"
|
|
25
|
+
],
|
|
26
|
+
"bin": {
|
|
27
|
+
"bsdkrun": "bin/bsdkrun.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin/bsdkrun.js",
|
|
31
|
+
"scripts/postinstall.js",
|
|
32
|
+
"scripts/platform.js",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"postinstall": "node scripts/postinstall.js"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"os": [
|
|
42
|
+
"darwin",
|
|
43
|
+
"linux"
|
|
44
|
+
],
|
|
45
|
+
"cpu": [
|
|
46
|
+
"x64",
|
|
47
|
+
"arm64"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Maps the running platform/arch onto the bsdkrun host-binary release asset.
|
|
4
|
+
//
|
|
5
|
+
// Supported (mirrors the project's own platform support):
|
|
6
|
+
// macOS : arm64 only (Apple Silicon / Hypervisor.framework)
|
|
7
|
+
// Linux : x64 + arm64 (KVM)
|
|
8
|
+
// Everything else — Windows, macOS on Intel, 32-bit, etc. — is unsupported.
|
|
9
|
+
|
|
10
|
+
const path = require("node:path");
|
|
11
|
+
|
|
12
|
+
// process.platform + process.arch -> release asset (a .tar.gz holding a single
|
|
13
|
+
// `bsdkrun` executable). Keep these names in lockstep with the `release`
|
|
14
|
+
// workflow's packaging step.
|
|
15
|
+
const ASSETS = {
|
|
16
|
+
"darwin arm64": "bsdkrun-aarch64-apple-darwin.tar.gz",
|
|
17
|
+
"linux x64": "bsdkrun-x86_64-unknown-linux-gnu.tar.gz",
|
|
18
|
+
"linux arm64": "bsdkrun-aarch64-unknown-linux-gnu.tar.gz",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// process.platform + process.arch -> gvproxy release asset (a raw executable
|
|
22
|
+
// published by containers/gvisor-tap-vsock). gvproxy provides the guest's
|
|
23
|
+
// user-mode networking; bsdkrun degrades gracefully without it, so its download
|
|
24
|
+
// is best-effort. macOS ships a single universal `gvproxy-darwin`.
|
|
25
|
+
const GVPROXY_ASSETS = {
|
|
26
|
+
"darwin arm64": "gvproxy-darwin",
|
|
27
|
+
"linux x64": "gvproxy-linux-amd64",
|
|
28
|
+
"linux arm64": "gvproxy-linux-arm64",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Human-readable list of what we do support, for error messages. */
|
|
32
|
+
const SUPPORTED = "macOS/arm64, Linux/x64, Linux/arm64";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the release asset for the current platform, or throw a clear error
|
|
36
|
+
* naming what's supported. Returns { platform, arch, asset }.
|
|
37
|
+
*/
|
|
38
|
+
function detect() {
|
|
39
|
+
const platform = process.platform;
|
|
40
|
+
const arch = process.arch;
|
|
41
|
+
const key = platform + " " + arch;
|
|
42
|
+
const asset = ASSETS[key];
|
|
43
|
+
if (!asset) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`@bsdkrun/cli: unsupported platform ${platform}/${arch}.\n` +
|
|
46
|
+
`bsdkrun ships prebuilt binaries only for: ${SUPPORTED}.\n` +
|
|
47
|
+
(platform === "darwin"
|
|
48
|
+
? "macOS support is Apple Silicon (arm64) only — Intel Macs are not supported.\n"
|
|
49
|
+
: "") +
|
|
50
|
+
"If you're on a supported platform seeing this, please file an issue:\n" +
|
|
51
|
+
" https://github.com/tsirysndr/bsdkrun/issues"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return { platform, arch, asset };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Absolute path to where the downloaded native binary lives inside the package. */
|
|
58
|
+
function binaryPath() {
|
|
59
|
+
const name = process.platform === "win32" ? "bsdkrun.exe" : "bsdkrun";
|
|
60
|
+
return path.join(__dirname, "..", "binaries", name);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The gvproxy release asset for the current platform, or null if none maps. */
|
|
64
|
+
function gvproxyAsset() {
|
|
65
|
+
return GVPROXY_ASSETS[process.platform + " " + process.arch] || null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Absolute path to where the downloaded gvproxy binary lives inside the package. */
|
|
69
|
+
function gvproxyPath() {
|
|
70
|
+
return path.join(__dirname, "..", "binaries", "gvproxy");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = {
|
|
74
|
+
detect,
|
|
75
|
+
binaryPath,
|
|
76
|
+
gvproxyAsset,
|
|
77
|
+
gvproxyPath,
|
|
78
|
+
ASSETS,
|
|
79
|
+
GVPROXY_ASSETS,
|
|
80
|
+
SUPPORTED,
|
|
81
|
+
};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Runs after `npm install @bsdkrun/cli`. Downloads the prebuilt `bsdkrun` host
|
|
4
|
+
// binary for this platform from the matching GitHub release, verifies its
|
|
5
|
+
// SHA-256, and unpacks it into ./binaries/ where the bin shim expects it.
|
|
6
|
+
//
|
|
7
|
+
// Escape hatches (env vars):
|
|
8
|
+
// BSDKRUN_SKIP_DOWNLOAD=1 skip everything (e.g. developing this package)
|
|
9
|
+
// BSDKRUN_BINARY=/path copy a local binary instead of downloading
|
|
10
|
+
// BSDKRUN_DOWNLOAD_BASE=url override the release download base URL
|
|
11
|
+
// BSDKRUN_SKIP_GVPROXY=1 skip the gvproxy (user-mode networking) download
|
|
12
|
+
// BSDKRUN_GVPROXY=/path already have gvproxy — skip its download
|
|
13
|
+
// BSDKRUN_GVPROXY_VERSION=vX pin a gvproxy release tag (default: latest)
|
|
14
|
+
|
|
15
|
+
const fs = require("node:fs");
|
|
16
|
+
const path = require("node:path");
|
|
17
|
+
const crypto = require("node:crypto");
|
|
18
|
+
const { execFileSync } = require("node:child_process");
|
|
19
|
+
const { detect, binaryPath, gvproxyAsset, gvproxyPath } = require("./platform.js");
|
|
20
|
+
|
|
21
|
+
const VERSION = require("../package.json").version;
|
|
22
|
+
const REPO = "tsirysndr/bsdkrun";
|
|
23
|
+
const DEFAULT_BASE = `https://github.com/${REPO}/releases/download/v${VERSION}`;
|
|
24
|
+
|
|
25
|
+
// gvproxy (gvisor-tap-vsock) provides the guest's user-mode networking. bsdkrun
|
|
26
|
+
// boots fine without it (just no NIC), so this download is best-effort.
|
|
27
|
+
const GVPROXY_REPO = "containers/gvisor-tap-vsock";
|
|
28
|
+
|
|
29
|
+
async function main() {
|
|
30
|
+
if (process.env.BSDKRUN_SKIP_DOWNLOAD) {
|
|
31
|
+
console.log("[bsdkrun] BSDKRUN_SKIP_DOWNLOAD set — skipping binary download.");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// detect() throws on unsupported platform/arch — surface that as a failed
|
|
36
|
+
// install with a clear message (this is the real gate; `npm i -f` bypasses
|
|
37
|
+
// the package.json os/cpu fields).
|
|
38
|
+
const { asset } = detect();
|
|
39
|
+
|
|
40
|
+
const dest = binaryPath();
|
|
41
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
42
|
+
|
|
43
|
+
// Already installed (e.g. a rebuild in the same tree)? Nothing to do.
|
|
44
|
+
if (fs.existsSync(dest) && !process.env.BSDKRUN_BINARY) {
|
|
45
|
+
console.log(`[bsdkrun] binary already present at ${dest}`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Local binary override — copy it in, no network.
|
|
50
|
+
if (process.env.BSDKRUN_BINARY) {
|
|
51
|
+
fs.copyFileSync(process.env.BSDKRUN_BINARY, dest);
|
|
52
|
+
fs.chmodSync(dest, 0o755);
|
|
53
|
+
console.log(`[bsdkrun] installed from BSDKRUN_BINARY=${process.env.BSDKRUN_BINARY}`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const base = process.env.BSDKRUN_DOWNLOAD_BASE || DEFAULT_BASE;
|
|
58
|
+
const url = `${base}/${asset}`;
|
|
59
|
+
|
|
60
|
+
console.log(`[bsdkrun] downloading ${url}`);
|
|
61
|
+
const archive = await download(url);
|
|
62
|
+
|
|
63
|
+
// Verify against the .sha256 sidecar the release publishes. If the sidecar is
|
|
64
|
+
// missing (older releases), warn but continue; if present and mismatched, fail.
|
|
65
|
+
await verifyChecksum(archive, `${url}.sha256`, asset);
|
|
66
|
+
|
|
67
|
+
// Unpack the whole archive into the binaries dir. On macOS that's just
|
|
68
|
+
// `bsdkrun`; on Linux it also carries the bundled libkrun/libkrunfw shared
|
|
69
|
+
// objects, which must land next to the binary (its rpath is $ORIGIN).
|
|
70
|
+
const destDir = path.dirname(dest);
|
|
71
|
+
const tgz = path.join(destDir, asset);
|
|
72
|
+
fs.writeFileSync(tgz, archive);
|
|
73
|
+
try {
|
|
74
|
+
// tar + gzip are present on every supported platform (macOS, Linux).
|
|
75
|
+
execFileSync("tar", ["-xzf", tgz, "-C", destDir], { stdio: "inherit" });
|
|
76
|
+
} finally {
|
|
77
|
+
fs.rmSync(tgz, { force: true });
|
|
78
|
+
}
|
|
79
|
+
if (!fs.existsSync(dest)) {
|
|
80
|
+
throw new Error(`archive ${asset} did not contain a 'bsdkrun' binary`);
|
|
81
|
+
}
|
|
82
|
+
fs.chmodSync(dest, 0o755);
|
|
83
|
+
|
|
84
|
+
console.log(`[bsdkrun] installed bsdkrun ${VERSION} -> ${dest}`);
|
|
85
|
+
|
|
86
|
+
// Best-effort: also fetch gvproxy for user-mode guest networking. Never fail
|
|
87
|
+
// the install over it — bsdkrun degrades gracefully to a NIC-less boot.
|
|
88
|
+
await installGvproxy();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Download the gvproxy binary for this platform into ./binaries/gvproxy so guest
|
|
93
|
+
* networking works out of the box. Best-effort: any failure just warns, since
|
|
94
|
+
* the guest can still boot without a NIC and users can `brew install gvproxy`
|
|
95
|
+
* or set BSDKRUN_GVPROXY themselves.
|
|
96
|
+
*/
|
|
97
|
+
async function installGvproxy() {
|
|
98
|
+
if (process.env.BSDKRUN_SKIP_GVPROXY) {
|
|
99
|
+
console.log("[bsdkrun] BSDKRUN_SKIP_GVPROXY set — skipping gvproxy download.");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (process.env.BSDKRUN_GVPROXY) {
|
|
103
|
+
console.log(
|
|
104
|
+
`[bsdkrun] BSDKRUN_GVPROXY=${process.env.BSDKRUN_GVPROXY} set — skipping gvproxy download.`
|
|
105
|
+
);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const asset = gvproxyAsset();
|
|
110
|
+
if (!asset) return; // unsupported platform already handled by detect()
|
|
111
|
+
|
|
112
|
+
const dest = gvproxyPath();
|
|
113
|
+
if (fs.existsSync(dest)) {
|
|
114
|
+
console.log(`[bsdkrun] gvproxy already present at ${dest}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const version = process.env.BSDKRUN_GVPROXY_VERSION;
|
|
119
|
+
const base = version
|
|
120
|
+
? `https://github.com/${GVPROXY_REPO}/releases/download/${version}`
|
|
121
|
+
: `https://github.com/${GVPROXY_REPO}/releases/latest/download`;
|
|
122
|
+
const url = `${base}/${asset}`;
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
console.log(`[bsdkrun] downloading ${url}`);
|
|
126
|
+
const bin = await download(url);
|
|
127
|
+
// gvproxy assets are raw executables (no archive) — write and mark runnable.
|
|
128
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
129
|
+
fs.writeFileSync(dest, bin);
|
|
130
|
+
fs.chmodSync(dest, 0o755);
|
|
131
|
+
console.log(`[bsdkrun] installed gvproxy -> ${dest}`);
|
|
132
|
+
} catch (err) {
|
|
133
|
+
console.warn(
|
|
134
|
+
`[bsdkrun] could not download gvproxy (${err && err.message ? err.message : err}).\n` +
|
|
135
|
+
" Guest networking will be unavailable until you install gvproxy\n" +
|
|
136
|
+
" (`brew install gvproxy`) or set BSDKRUN_GVPROXY to its path."
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Fetch a URL to a Buffer, following redirects, with a clear error on failure. */
|
|
142
|
+
async function download(url) {
|
|
143
|
+
const res = await fetch(url, { redirect: "follow" });
|
|
144
|
+
if (!res.ok) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
`failed to download ${url}: HTTP ${res.status} ${res.statusText}.\n` +
|
|
147
|
+
`Is there a published release v${VERSION} with this asset?\n` +
|
|
148
|
+
` https://github.com/${REPO}/releases/tag/v${VERSION}`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return Buffer.from(await res.arrayBuffer());
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Verify `archive` against a `<asset>.sha256` sidecar (best-effort fetch, strict compare). */
|
|
155
|
+
async function verifyChecksum(archive, sidecarUrl, asset) {
|
|
156
|
+
let res;
|
|
157
|
+
try {
|
|
158
|
+
res = await fetch(sidecarUrl, { redirect: "follow" });
|
|
159
|
+
} catch {
|
|
160
|
+
res = null;
|
|
161
|
+
}
|
|
162
|
+
if (!res || !res.ok) {
|
|
163
|
+
console.warn(`[bsdkrun] no checksum sidecar for ${asset} — skipping verification.`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Sidecar is `shasum -a 256` output: "<hex> <filename>". Take the first field.
|
|
167
|
+
const expected = (await res.text()).trim().split(/\s+/)[0].toLowerCase();
|
|
168
|
+
const actual = crypto.createHash("sha256").update(archive).digest("hex");
|
|
169
|
+
if (expected !== actual) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`checksum mismatch for ${asset}:\n expected ${expected}\n actual ${actual}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
console.log(`[bsdkrun] checksum OK (${actual.slice(0, 12)}…)`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
main().catch((err) => {
|
|
178
|
+
console.error("\n[bsdkrun] install failed:\n" + (err && err.message ? err.message : err));
|
|
179
|
+
process.exit(1);
|
|
180
|
+
});
|