Skip to content

Commit 262d839

Browse files
committed
fix(cli): explain missing libatomic dependency during Linux installation
This commit fixes the missing libatomic dependency during Linux installation. When the libatomic.so.1 is missing, the installer now tells users to install the package that provides it and rerun the installer. Works across Linux distributions. Signed-off-by: Vibhu Prashar <[email protected]>
1 parent 28a8d2b commit 262d839

2 files changed

Lines changed: 167 additions & 2 deletions

File tree

‎scripts/install.sh‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
2-
# Installs the T3 Code CLI from a GitHub Release archive. Needs only sh, tar,
2+
# Installs the T3 Code CLI from a GitHub Release archive. Needs sh, tar,
33
# sha256sum or shasum, and curl or wget; no Node, npm, or compiler.
4+
# On Linux, the executable also needs system libraries including libatomic.so.1.
45
#
56
# curl -fsSL https://t3.codes/install.sh | sh
67
#
@@ -208,7 +209,23 @@ else
208209
step "Extracting T3 Code..."
209210
tar -xzf "${staging}/${archive}" -C "$staging" --strip-components=1
210211
rm -f "${staging}/${archive}" "${staging}/SHA256SUMS"
211-
"${staging}/t3" --version >/dev/null || fail "the downloaded executable does not run"
212+
if LC_ALL=C "${staging}/t3" --version >/dev/null 2>"${staging}/version.errors"; then
213+
cat "${staging}/version.errors" >&2
214+
rm -f "${staging}/version.errors"
215+
else
216+
if "$interactive"; then printf '\n' >&2; fi
217+
cat "${staging}/version.errors" >&2
218+
if [ "$platform" = linux ] && grep -Fq 'error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory' "${staging}/version.errors"; then
219+
printf '%s\n' \
220+
'' \
221+
't3 install: the downloaded executable requires libatomic.so.1' \
222+
'' \
223+
' Use your Linux package manager to install the package' \
224+
' providing libatomic.so.1 (commonly named libatomic or libatomic1).' >&2
225+
fail "install the library, then rerun the installer"
226+
fi
227+
fail "the downloaded executable does not run"
228+
fi
212229
printf '%s\n' "$version" > "${staging}/.install-complete"
213230

214231
rm -rf "$target_dir"

‎scripts/install.test.ts‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// @effect-diagnostics nodeBuiltinImport:off - Exercises the real shell installer against a local HTTP fixture.
2+
import * as HostProcess from "@t3tools/shared/HostProcess";
3+
import * as NodeChildProcess from "node:child_process";
4+
import * as NodeCrypto from "node:crypto";
5+
import * as NodeFSP from "node:fs/promises";
6+
import * as NodeHttp from "node:http";
7+
import * as NodeOS from "node:os";
8+
import * as NodePath from "node:path";
9+
import { describe, expect, it } from "vite-plus/test";
10+
11+
const missingAtomicError =
12+
"t3: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory";
13+
14+
// Stub uname so the Linux diagnostic can also be exercised on macOS.
15+
describe.skipIf(HostProcess.Platform.defaultValue() === "win32")(
16+
"installer executable validation",
17+
() => {
18+
it.each([
19+
{
20+
platform: "Linux",
21+
diagnostic: missingAtomicError,
22+
exitCode: 127,
23+
hint: true,
24+
},
25+
{
26+
platform: "Linux",
27+
diagnostic:
28+
"t3: error while loading shared libraries: libatomic.so.1: cannot open shared object file: Permission denied",
29+
exitCode: 127,
30+
hint: false,
31+
},
32+
{
33+
platform: "Darwin",
34+
diagnostic: missingAtomicError,
35+
exitCode: 127,
36+
hint: false,
37+
},
38+
{
39+
platform: "Linux",
40+
diagnostic: "t3: startup warning",
41+
exitCode: 0,
42+
hint: false,
43+
},
44+
])(
45+
"handles $platform validation: $diagnostic",
46+
async ({ platform, diagnostic, exitCode, hint }) => {
47+
const root = await NodeFSP.mkdtemp(
48+
NodePath.join(NodeOS.tmpdir(), "t3-install-validation-"),
49+
);
50+
const version = "1.2.3";
51+
const stem = `t3-${version}-${platform.toLowerCase()}-x64`;
52+
const archiveName = `${stem}.tar.gz`;
53+
const home = NodePath.join(root, "home");
54+
const bin = NodePath.join(root, "bin");
55+
const versions = NodePath.join(home, "runtime/versions");
56+
const server = NodeHttp.createServer((request, response) => {
57+
if (request.url?.endsWith("/SHA256SUMS")) {
58+
response.end(`${checksum} ${archiveName}\n`);
59+
} else if (request.url?.endsWith(`/${archiveName}`)) {
60+
response.end(archive);
61+
} else {
62+
response.writeHead(404).end();
63+
}
64+
});
65+
let archive: Buffer;
66+
let checksum: string;
67+
try {
68+
await NodeFSP.mkdir(NodePath.join(root, stem));
69+
await NodeFSP.writeFile(
70+
NodePath.join(root, stem, "t3"),
71+
`#!/bin/sh\nprintf '%s\\n' '${diagnostic}' >&2\nexit ${exitCode}\n`,
72+
{ mode: 0o755 },
73+
);
74+
NodeChildProcess.execFileSync("tar", [
75+
"-czf",
76+
NodePath.join(root, archiveName),
77+
"-C",
78+
root,
79+
stem,
80+
]);
81+
archive = await NodeFSP.readFile(NodePath.join(root, archiveName));
82+
checksum = NodeCrypto.createHash("sha256").update(archive).digest("hex");
83+
await NodeFSP.mkdir(bin);
84+
await NodeFSP.writeFile(
85+
NodePath.join(bin, "uname"),
86+
`#!/bin/sh\ncase "$1" in -s) echo '${platform}';; -m) echo x86_64;; *) exit 1;; esac\n`,
87+
{ mode: 0o755 },
88+
);
89+
await new Promise<void>((resolve, reject) => {
90+
server.once("error", reject);
91+
server.listen(0, "127.0.0.1", resolve);
92+
});
93+
const address = server.address();
94+
if (!address || typeof address === "string") throw new Error("Expected a TCP listener");
95+
const result = await new Promise<{
96+
code: number | null;
97+
stdout: string;
98+
stderr: string;
99+
}>((resolve, reject) => {
100+
const child = NodeChildProcess.spawn(
101+
"sh",
102+
[NodePath.resolve(import.meta.dirname, "install.sh")],
103+
{
104+
env: {
105+
...process.env,
106+
PATH: `${bin}:${process.env.PATH}`,
107+
T3CODE_VERSION: version,
108+
T3CODE_HOME: home,
109+
T3CODE_INSTALL_BIN_DIR: bin,
110+
T3CODE_RELEASE_BASE_URL: `http://127.0.0.1:${address.port}`,
111+
},
112+
stdio: ["ignore", "pipe", "pipe"],
113+
},
114+
);
115+
let stdout = "";
116+
let stderr = "";
117+
child.stdout.on("data", (chunk: Buffer) => {
118+
stdout += chunk.toString();
119+
});
120+
child.stderr.on("data", (chunk: Buffer) => {
121+
stderr += chunk.toString();
122+
});
123+
child.on("error", reject);
124+
child.on("close", (code) => resolve({ code, stdout, stderr }));
125+
});
126+
expect(result.stderr).toContain(diagnostic);
127+
expect(result.stderr.includes("providing libatomic.so.1")).toBe(hint);
128+
expect(result.stdout).not.toContain(diagnostic);
129+
if (exitCode === 0) {
130+
expect(result.code).toBe(0);
131+
expect(await NodeFSP.readdir(NodePath.join(versions, version))).not.toContain(
132+
"version.errors",
133+
);
134+
} else {
135+
expect(result.code).toBe(1);
136+
expect(result.stderr).toContain(
137+
hint ? "rerun the installer" : "the downloaded executable does not run",
138+
);
139+
}
140+
} finally {
141+
server.closeAllConnections();
142+
await new Promise<void>((resolve) => server.close(() => resolve()));
143+
await NodeFSP.rm(root, { recursive: true, force: true });
144+
}
145+
},
146+
);
147+
},
148+
);

0 commit comments

Comments
 (0)