install-script.ts
This file
Path
scripts/lib/release/install-script.ts
97 lines · 3.4 KiB · TypeScript
Last changed by
Merge cli/default-platform into mainoscabrielbefore adoptionb9fc54b
History of this fileTake it
The walk stopped after 200 commits: lines older than f2215bd point at it.
Add bun infra/teardown.ts: it prints which of the ledger's throwaways still exist, and deletes exactly those only with --applyoscabrielbefore adoptionf2215bd
lines 1–4why, one step back1import type { Brand } from "@repo/brand";23const quoted = (value: string) => `'${value.replaceAll("'", `'\\''`)}'`;4Merge build/comments-ops into mainoscabrielbefore adoptione4c407e
line 5why, one step back5// The one binary is also git's credential helper when started as `git-credential-<slug>`.Add bun infra/teardown.ts: it prints which of the ledger's throwaways still exist, and deletes exactly those only with --applyoscabrielbefore adoptionf2215bd
lines 6–89why, one step back6export const installScriptFor = (input: {7 readonly brand: typeof Brand;8 readonly version: string;9 readonly baseUrl: string;10 readonly machines: readonly string[];11}): string => {12 const { brand, machines } = input;13 const installDir = `${brand.slug.toUpperCase()}_INSTALL_DIR`;1415 return [16 "#!/bin/sh",17 `# Installs ${brand.cli} ${input.version}, the ${brand.name} command line, from`,18 `# ${input.baseUrl}.`,19 "#",20 "# It downloads the binary for this machine, checks it against the",21 "# release's SHA256SUMS, and installs it as <dir>/" +22 `${brand.cli}, with <dir>/${brand.gitCredentialHelper}`,23 `# beside it (git's credential helper). <dir> is $${installDir},`,24 "# or ~/.local/bin. Nothing is installed unless the checksum matches.",25 "set -eu",26 "",27 `base=${quoted(input.baseUrl)}`,28 `version=${quoted(input.version)}`,29 `slug=${quoted(brand.slug)}`,30 `name=${quoted(brand.cli)}`,31 `helper=${quoted(brand.gitCredentialHelper)}`,32 `dir="\${${installDir}:-$HOME/.local/bin}"`,33 "",34 "fail() {",35 ' echo "$name install: $*" >&2',36 " exit 1",37 "}",38 "",39 'case "$(uname -s)" in',40 " Linux) os=linux ;;",41 " Darwin) os=darwin ;;",42 ' *) os="$(uname -s)" ;;',43 "esac",44 "",45 'case "$(uname -m)" in',46 " x86_64 | amd64) arch=x64 ;;",47 " arm64 | aarch64) arch=arm64 ;;",48 ' *) arch="$(uname -m)" ;;',49 "esac",50 "",51 'case "$os-$arch" in',52 ` ${machines.join(" | ")}) asset="$slug-$os-$arch" ;;`,53 ` *) fail "no build for $os-$arch; $version is built for ${machines.join(" and ")}" ;;`,54 "esac",55 "",56 "if command -v curl >/dev/null 2>&1; then",57 ' fetch() { curl -fsSL "$1" -o "$2"; }',58 "elif command -v wget >/dev/null 2>&1; then",59 ' fetch() { wget -q -O "$2" "$1"; }',60 "else",61 ' fail "needs curl or wget to download $version"',62 "fi",63 "",64 "if command -v sha256sum >/dev/null 2>&1; then",65 " digest() { sha256sum \"$1\" | cut -d ' ' -f 1; }",66 "elif command -v shasum >/dev/null 2>&1; then",67 " digest() { shasum -a 256 \"$1\" | cut -d ' ' -f 1; }",68 "else",69 ' fail "needs sha256sum or shasum to check the download"',70 "fi",71 "",72 'tmp="$(mktemp -d)"',73 "trap 'rm -rf \"$tmp\"' EXIT",74 "trap 'exit 1' HUP INT TERM",75 "",76 'fetch "$base/$asset" "$tmp/$asset" || fail "could not download $base/$asset"',77 'fetch "$base/SHA256SUMS" "$tmp/SHA256SUMS" || fail "could not download $base/SHA256SUMS"',78 "",79 'expected="$(awk -v asset="$asset" \'$2 == asset { print $1 }\' "$tmp/SHA256SUMS")"',80 '[ -n "$expected" ] || fail "SHA256SUMS lists no $asset; nothing was installed"',81 'actual="$(digest "$tmp/$asset")"',82 '[ "$actual" = "$expected" ] || fail "$asset does not match SHA256SUMS (expected $expected, got $actual); nothing was installed"',83 "",84 'mkdir -p "$dir"',85 'chmod 755 "$tmp/$asset"',86 'mv -f "$tmp/$asset" "$dir/$name"',87 'ln -sf "$name" "$dir/$helper"',88 "",89 'echo "installed $name $version as $dir/$name, with $helper beside it"',Merge cli/default-platform into mainoscabrielbefore adoptionb9fc54b
line 90why, one step back90 'echo "next: $name login"',Add bun infra/teardown.ts: it prints which of the ledger's throwaways still exist, and deletes exactly those only with --applyoscabrielbefore adoptionf2215bd
lines 91–97why, one step back91 'case ":$PATH:" in',92 ' *":$dir:"*) ;;',93 ' *) echo "add $dir to your PATH to run $name" ;;',94 "esac",95 "",96 ].join("\n");97};