Install sl from self-contained tarball instead of bare binary

Anton Kaminsky12d agocd75344c51a0parent d8281c0
1 file changed+16-6
cli/src/commands/auth-login.ts
@@ -1,5 +1,5 @@
11import { intro, outro, spinner, log } from "@clack/prompts";
2import { mkdirSync, writeFileSync, readFileSync, existsSync, chmodSync } from "node:fs";
2import { mkdirSync, writeFileSync, readFileSync, existsSync, chmodSync, symlinkSync, unlinkSync } from "node:fs";
33import { join } from "node:path";
44import { homedir, platform, arch } from "node:os";
55import { execSync } from "node:child_process";
@@ -110,16 +110,26 @@
110110 s.start("Installing Sapling (sl)");
111111 try {
112112 const archName = arch() === "x64" ? "x86_64" : arch();
113 const binary = `sl-${os}-${archName}`;
114 const res = await fetch(`${hub}/downloads/${binary}`);
113 const tarball = `sl-${os}-${archName}.tar.gz`;
114 const res = await fetch(`${hub}/downloads/${tarball}`);
115115 if (!res.ok) {
116116 s.stop("Sapling binary not available yet (non-fatal)");
117117 return;
118118 }
119119 const buf = Buffer.from(await res.arrayBuffer());
120 const dest = "/usr/local/bin/sl";
121 writeFileSync(dest, buf);
122 chmodSync(dest, 0o755);
120 const installDir = "/usr/local/lib/sapling";
121 const symlink = "/usr/local/bin/sl";
122
123 // Write tarball to temp file and extract
124 const tmpTar = "/tmp/sl-install.tar.gz";
125 writeFileSync(tmpTar, buf);
126 execSync(`rm -rf ${installDir} && mkdir -p ${installDir} && tar xzf ${tmpTar} -C ${installDir}`, { stdio: "pipe" });
127 execSync(`rm -f ${tmpTar}`, { stdio: "pipe" });
128
129 // Create symlink at /usr/local/bin/sl -> wrapper script
130 try { unlinkSync(symlink); } catch {}
131 symlinkSync(join(installDir, "sl"), symlink);
132
123133 s.stop("Sapling (sl) installed");
124134 } catch {
125135 s.stop("Could not install Sapling (non-fatal)");
126136