@share2us/cli 0.1.0

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.
Files changed (4) hide show
  1. package/README.md +36 -0
  2. package/bin/s2u.js +23 -0
  3. package/install.js +100 -0
  4. package/package.json +31 -0
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @share2us/cli
2
+
3
+ The [Share2Us](https://share2.us) command-line client (`s2u`), distributed via npm.
4
+
5
+ Share files and text from your terminal, the browser, or an AI agent, and get back
6
+ one opaque, expiring link. Also does offline LAN / Tailscale / WireGuard direct
7
+ transfers with no account and no cloud.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install -g @share2us/cli
13
+ ```
14
+
15
+ This downloads the prebuilt binary for your platform (linux/macOS, x64/arm64) from
16
+ [GitHub Releases](https://github.com/share2us/cli/releases). Then:
17
+
18
+ ```sh
19
+ s2u login
20
+ s2u rca.md # upload -> get a share link
21
+ s2u get s.share2.us/7Kf9aQ2m
22
+ s2u help # full command reference
23
+ ```
24
+
25
+ Prefer a script installer instead? `curl -fsSL https://share2.us/install.sh | sh`
26
+
27
+ ## Notes
28
+
29
+ - The version you get is always the latest release. Pin one with
30
+ `SHARE2US_VERSION=v20260718173923 npm i -g @share2us/cli`.
31
+ - This is a thin wrapper around the Go binary; the source and full docs live at
32
+ **[github.com/share2us/cli](https://github.com/share2us/cli)**.
33
+
34
+ ## License
35
+
36
+ [MIT](https://github.com/share2us/cli/blob/main/LICENSE.md) © Share2Us
package/bin/s2u.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ // Thin launcher: exec the native Share2Us CLI binary that install.js placed here.
3
+ "use strict";
4
+
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const { spawnSync } = require("child_process");
8
+
9
+ const bin = path.join(__dirname, "share2us-bin");
10
+
11
+ if (!fs.existsSync(bin)) {
12
+ console.error("share2us: the CLI binary is missing (install scripts may have been skipped).");
13
+ console.error("Reinstall with `npm i -g @share2us/cli`, or run:");
14
+ console.error(" node " + path.join(__dirname, "..", "install.js"));
15
+ process.exit(1);
16
+ }
17
+
18
+ const res = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
19
+ if (res.error) {
20
+ console.error("share2us: " + res.error.message);
21
+ process.exit(1);
22
+ }
23
+ process.exit(res.status === null ? 1 : res.status);
package/install.js ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ // postinstall: download the prebuilt Share2Us CLI binary for this platform from
3
+ // GitHub Releases (built by CI for every platform) and place it next to the shim.
4
+ // Mirrors https://share2.us/install.sh (system tar + cksum; no runtime deps).
5
+ "use strict";
6
+
7
+ const fs = require("fs");
8
+ const os = require("os");
9
+ const path = require("path");
10
+ const https = require("https");
11
+ const { execFileSync } = require("child_process");
12
+
13
+ const REPO = process.env.SHARE2US_INSTALL_REPO || "share2us/cli";
14
+ const VERSION = process.env.SHARE2US_VERSION || "latest";
15
+
16
+ function fail(msg) {
17
+ console.error("share2us install: " + msg);
18
+ process.exit(1);
19
+ }
20
+
21
+ function platform() {
22
+ const osName = { linux: "linux", darwin: "darwin" }[process.platform];
23
+ const arch = { x64: "amd64", arm64: "arm64" }[process.arch];
24
+ if (!osName || !arch) {
25
+ fail(
26
+ `unsupported platform ${process.platform}/${process.arch}. ` +
27
+ "Build from source (https://github.com/share2us/cli) or use https://share2.us/install.sh"
28
+ );
29
+ }
30
+ return { archive: `share2us_${osName}_${arch}.tar.gz` };
31
+ }
32
+
33
+ function assetURL(archive) {
34
+ return VERSION === "latest"
35
+ ? `https://github.com/${REPO}/releases/latest/download/${archive}`
36
+ : `https://github.com/${REPO}/releases/download/${VERSION}/${archive}`;
37
+ }
38
+
39
+ function download(url, dest, redirects = 0) {
40
+ if (redirects > 8) return Promise.reject(new Error("too many redirects"));
41
+ return new Promise((resolve, reject) => {
42
+ https
43
+ .get(url, { headers: { "User-Agent": "share2us-npm-installer" } }, (res) => {
44
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
45
+ res.resume();
46
+ resolve(download(res.headers.location, dest, redirects + 1));
47
+ return;
48
+ }
49
+ if (res.statusCode !== 200) {
50
+ res.resume();
51
+ reject(new Error(`HTTP ${res.statusCode} for ${url}`));
52
+ return;
53
+ }
54
+ const out = fs.createWriteStream(dest);
55
+ res.pipe(out);
56
+ out.on("finish", () => out.close(() => resolve()));
57
+ out.on("error", reject);
58
+ })
59
+ .on("error", reject);
60
+ });
61
+ }
62
+
63
+ async function main() {
64
+ const { archive } = platform();
65
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "s2u-install-"));
66
+ const tgz = path.join(tmp, archive);
67
+ const crc = tgz + ".crc32";
68
+ const base = assetURL(archive);
69
+
70
+ console.log(`share2us: downloading ${archive} (${VERSION})...`);
71
+ await download(base, tgz);
72
+
73
+ // Integrity: system cksum against the .crc32 sidecar (same as install.sh).
74
+ try {
75
+ await download(base + ".crc32", crc);
76
+ const got = execFileSync("cksum", [tgz]).toString().trim().split(/\s+/);
77
+ const want = fs.readFileSync(crc, "utf8").trim().split(/\s+/);
78
+ if (got[0] !== want[0] || got[1] !== want[1]) {
79
+ fail(`CRC check failed for ${archive}`);
80
+ }
81
+ } catch (e) {
82
+ if (String(e && e.message).includes("CRC check failed")) throw e;
83
+ // sidecar/cksum unavailable: HTTPS already protects the transfer.
84
+ }
85
+
86
+ // Extract the `share2us` binary and place it beside the shim.
87
+ execFileSync("tar", ["-xzf", tgz, "-C", tmp]);
88
+ const src = path.join(tmp, "share2us");
89
+ if (!fs.existsSync(src)) fail("archive did not contain the share2us binary");
90
+ const binDir = path.join(__dirname, "bin");
91
+ fs.mkdirSync(binDir, { recursive: true });
92
+ const out = path.join(binDir, "share2us-bin");
93
+ fs.copyFileSync(src, out);
94
+ fs.chmodSync(out, 0o755);
95
+ fs.rmSync(tmp, { recursive: true, force: true });
96
+
97
+ console.log("share2us: installed. Run `s2u login` to get started.");
98
+ }
99
+
100
+ main().catch((e) => fail((e && e.message) || String(e)));
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@share2us/cli",
3
+ "version": "0.1.0",
4
+ "description": "Share2Us CLI (s2u) — share files and text from your terminal, browser, or AI agent via one opaque, expiring link.",
5
+ "keywords": ["share2us", "s2u", "file-sharing", "share", "cli", "p2p", "qr", "mcp", "e2e"],
6
+ "homepage": "https://share2.us",
7
+ "bugs": "https://github.com/share2us/cli/issues",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/share2us/cli.git",
11
+ "directory": "npm"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Share2Us",
15
+ "bin": {
16
+ "s2u": "bin/s2u.js",
17
+ "share2us": "bin/s2u.js"
18
+ },
19
+ "scripts": {
20
+ "postinstall": "node install.js"
21
+ },
22
+ "files": [
23
+ "bin/s2u.js",
24
+ "install.js"
25
+ ],
26
+ "os": ["linux", "darwin"],
27
+ "cpu": ["x64", "arm64"],
28
+ "engines": {
29
+ "node": ">=16"
30
+ }
31
+ }