Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ brew install rigomart/tap/wt-dash

This installs [Worktrunk](https://worktrunk.dev/) too. wt-dash needs Git and Worktrunk 0.80.0 or newer, and runs on macOS 13 or newer (Apple Silicon and Intel) and on Linux with glibc (arm64 and x64). Alpine and other musl-based distributions are not supported. On a glibc system, `ldd --version` prints "GNU libc". On Intel Macs and Linux, and anywhere else Homebrew has no prebuilt Worktrunk, Homebrew compiles Worktrunk from source, which takes a few minutes.

To install without Homebrew, download the archive for your system from the [latest release](https://github.com/rigomart/wt-dash/releases/latest) and put the `wt-dash` executable in a folder on your PATH. The macOS binary is not signed or notarized, so macOS blocks a copy downloaded with a browser until you allow it under System Settings → Privacy & Security.
Without Homebrew, run the install script:

```sh
curl -fsSL https://wt-dash.rigos.dev/install.sh | sh
```

It downloads the latest release for your system, checks it against the release's SHA-256 checksum, and puts `wt-dash` in `~/.local/bin`. It doesn't install Worktrunk or edit your shell startup files. When it finishes, it says so if `~/.local/bin` isn't on your PATH, or if Worktrunk's `wt` command is missing. In that case, install Worktrunk with `brew install worktrunk`, `cargo install worktrunk`, or from a [Worktrunk release](https://github.com/max-sixty/worktrunk/releases). To read the [script](site/install.sh) before running it, download it with `curl -fsSLO https://wt-dash.rigos.dev/install.sh`, then run `sh install.sh`.

To install a specific release, set `WT_DASH_VERSION`, such as `0.1.1`. To install into another folder, set `WT_DASH_INSTALL_DIR`. Set them for `sh`, after the pipe:

```sh
curl -fsSL https://wt-dash.rigos.dev/install.sh | WT_DASH_VERSION=0.1.1 WT_DASH_INSTALL_DIR="$HOME/bin" sh
```

To install by hand, download the archive for your system from the [latest release](https://github.com/rigomart/wt-dash/releases/latest) and put the `wt-dash` executable in a folder on your PATH. The macOS binary is not signed or notarized, so macOS blocks a copy downloaded with a browser until you allow it under System Settings → Privacy & Security. The install script downloads with curl, which doesn't mark the file for that check, so its copy isn't blocked.

<details>
<summary>Linux without Homebrew, step by step</summary>
<summary>Installing by hand on Linux, step by step</summary>

1. Install Worktrunk with `cargo install worktrunk`, with `sudo pacman -S worktrunk` on Arch Linux, or from a [Worktrunk release](https://github.com/max-sixty/worktrunk/releases).
2. Download the archive for your processor from the [latest release](https://github.com/rigomart/wt-dash/releases/latest): `linux-x64` if `uname -m` prints `x86_64`, `linux-arm64` if it prints `aarch64`.
Expand Down
13 changes: 12 additions & 1 deletion site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
color: var(--accent);
animation: blink 1.1s steps(1) infinite;
}
.cmd.alt code::after {
content: none;
}
@keyframes blink {
50% {
opacity: 0;
Expand Down Expand Up @@ -277,7 +280,15 @@ <h1>Clean up the worktrees your agents left behind.</h1>
<code>brew install rigomart/tap/wt-dash</code>
<button data-copy="brew install rigomart/tap/wt-dash">copy</button>
</div>
<p class="small">macOS 13+ and Linux (glibc). Free and MIT licensed.</p>
<p class="small">
No Homebrew? Use the <a href="install.sh">install script</a>, and install Worktrunk on its
own.
</p>
<div class="cmd alt">
<code>curl -fsSL https://wt-dash.rigos.dev/install.sh | sh</code>
<button data-copy="curl -fsSL https://wt-dash.rigos.dev/install.sh | sh">copy</button>
</div>
<p class="small">macOS 13+ and Linux (glibc).</p>

<figure>
<img
Expand Down
117 changes: 117 additions & 0 deletions site/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/sh
# Installs wt-dash from its GitHub releases. https://wt-dash.rigos.dev
#
# curl -fsSL https://wt-dash.rigos.dev/install.sh | sh
#
# WT_DASH_VERSION the release to install, such as 0.1.1 (default: the latest)
# WT_DASH_INSTALL_DIR the folder to install into (default: ~/.local/bin)
# WT_DASH_RELEASES_URL where releases are downloaded from, for a mirror or a test
# (default: https://github.com/rigomart/wt-dash/releases)
#
# Everything runs from main on the last line, so a download cut off partway runs nothing.

set -eu

say() { printf '%s\n' "$*"; }
warn() { printf 'warning: %s\n' "$*" >&2; }
fail() {
printf 'error: %s\n' "$*" >&2
exit 1
}
need() { command -v "$1" >/dev/null 2>&1 || fail "the installer needs $1."; }

main() {
releases=${WT_DASH_RELEASES_URL:-https://github.com/rigomart/wt-dash/releases}
dest=${WT_DASH_INSTALL_DIR:-"$HOME/.local/bin"}

need curl
need tar
if command -v sha256sum >/dev/null 2>&1; then
sha256="sha256sum"
elif command -v shasum >/dev/null 2>&1; then
sha256="shasum -a 256"
else
fail "the installer needs sha256sum or shasum to check the download."
fi

case $(uname -s) in
Darwin) os=darwin ;;
Linux)
os=linux
if ldd --version 2>&1 | grep -qi musl; then
fail "wt-dash needs glibc, and this system uses musl (Alpine, for example)."
fi
;;
*) fail "wt-dash runs on macOS and Linux only." ;;
esac
case $(uname -m) in
x86_64 | amd64) arch=x64 ;;
arm64 | aarch64) arch=arm64 ;;
*) fail "wt-dash has no build for $(uname -m) processors." ;;
esac
# A shell running under Rosetta reports x86_64 on an Apple Silicon Mac.
if [ "$os" = darwin ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || true)" = 1 ]; then
arch=arm64
fi

if [ -n "${WT_DASH_VERSION:-}" ]; then
tag=v${WT_DASH_VERSION#v}
else
latest=$(curl -fsSLI -o /dev/null -w '%{url_effective}' "$releases/latest") ||
fail "could not reach $releases/latest."
tag=${latest##*/}
case $tag in
v[0-9]*) ;;
*) fail "could not find the latest release at $releases/latest." ;;
esac
fi

archive="wt-dash-$tag-$os-$arch.tar.gz"
url="$releases/download/$tag/$archive"
tmp=$(mktemp -d)
staged=""
trap 'rm -rf "$tmp" "$staged"' EXIT

say "Downloading wt-dash ${tag#v} for $os-$arch"
curl -fsSL -o "$tmp/$archive" "$url" || fail "could not download $url"
curl -fsSL -o "$tmp/$archive.sha256" "$url.sha256" || fail "could not download $url.sha256"
(cd "$tmp" && $sha256 -c "$archive.sha256" >/dev/null 2>&1) ||
fail "$archive does not match its published checksum, so nothing was installed."
tar -xzf "$tmp/$archive" -C "$tmp" wt-dash || fail "could not extract wt-dash from $archive."

mkdir -p "$dest"
staged="$dest/.wt-dash.$$"
install -m 755 "$tmp/wt-dash" "$staged"
version=$("$staged" --version 2>&1) ||
fail "wt-dash ${tag#v} does not run on this system, so nothing was installed: $version"
mv -f "$staged" "$dest/wt-dash"
say "Installed wt-dash $version to $dest/wt-dash"

case ":$PATH:" in
*":$dest:"*)
found=$(command -v wt-dash || true)
if [ "$found" != "$dest/wt-dash" ]; then
warn "$found comes first on your PATH, so the wt-dash command runs that copy instead."
fi
;;
*)
say ""
say "$dest is not on your PATH. Add this line to your shell's startup file, such as ~/.zshrc or ~/.bashrc:"
say " export PATH=\"$dest:\$PATH\""
;;
esac

if ! command -v wt >/dev/null 2>&1; then
say ""
{
warn "wt-dash needs Worktrunk 0.80.0 or newer, and its wt command is not on your PATH."
say "Install it with: brew install worktrunk, or cargo install worktrunk,"
say "or from https://github.com/max-sixty/worktrunk/releases"
} >&2
fi

say ""
say "Check the setup with: wt-dash --doctor"
}

main "$@"
204 changes: 204 additions & 0 deletions tests/install.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import { afterAll, afterEach, beforeAll, expect, test } from "bun:test";
import { createHash } from "node:crypto";
import { chmod, mkdir, mkdtemp, readdir, readFile, rm, symlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";

// Fake GitHub releases: /releases/latest redirects to the newest tag; archives and checksums sit under /releases/download/<tag>/.

const INSTALLER = resolve(import.meta.dir, "../site/install.sh");
const PLATFORM = `${process.platform}-${process.arch}`;
/** The commands the installer and this test's `curl | sh` call. Run with only these on PATH, so a `wt` or `wt-dash` installed on this machine, even in /usr/bin, isn't found. */
const TOOLS = [
"sh",
"curl",
"tar",
"gzip",
"sha256sum",
"shasum",
"uname",
"ldd",
"grep",
"sysctl",
"mktemp",
"rm",
"mkdir",
"install",
"mv",
];
let SYSTEM_PATH: string;

const files = new Map<string, Blob | string>();
const requests: string[] = [];
let server: ReturnType<typeof Bun.serve>;
let fixtures: string;

async function publish(version: string, options: { checksum?: string; executable?: string } = {}) {
const folder = join(fixtures, version);
await mkdir(folder, { recursive: true });
await writeFile(join(folder, "wt-dash"), options.executable ?? `#!/bin/sh\necho ${version}\n`);
await chmod(join(folder, "wt-dash"), 0o755);
await writeFile(join(folder, "LICENSE"), "MIT\n");
const archive = `wt-dash-v${version}-${PLATFORM}.tar.gz`;
const tar = Bun.spawnSync([
"tar",
"-czf",
join(folder, archive),
"-C",
folder,
"wt-dash",
"LICENSE",
]);
expect(tar.exitCode).toBe(0);
const bytes = await readFile(join(folder, archive));
const hash = options.checksum ?? createHash("sha256").update(bytes).digest("hex");
files.set(`/releases/download/v${version}/${archive}`, Bun.file(join(folder, archive)));
files.set(`/releases/download/v${version}/${archive}.sha256`, `${hash} ${archive}\n`);
}

beforeAll(async () => {
fixtures = await mkdtemp(join(tmpdir(), "wt-dash-releases-"));
SYSTEM_PATH = join(fixtures, "system-bin");
await mkdir(SYSTEM_PATH);
for (const tool of TOOLS) {
const found = Bun.which(tool, { PATH: "/usr/bin:/bin:/usr/sbin:/sbin" });
if (found) await symlink(found, join(SYSTEM_PATH, tool));
}
await publish("0.1.0");
await publish("0.2.0");
await publish("0.0.9", { checksum: "0".repeat(64) });
await publish("0.0.8", {
executable: "#!/bin/sh\necho 'version GLIBC_2.99 not found' >&2\nexit 1\n",
});
files.set("/install.sh", await readFile(INSTALLER, "utf8"));
server = Bun.serve({
port: 0,
fetch(request) {
const path = new URL(request.url).pathname;
requests.push(path);
if (path === "/releases/latest")
return Response.redirect(new URL("/releases/tag/v0.2.0", request.url).href, 302);
if (path.startsWith("/releases/tag/")) return new Response("release page");
const body = files.get(path);
return body === undefined ? new Response("Not Found", { status: 404 }) : new Response(body);
},
});
});

afterAll(async () => {
server.stop(true);
await rm(fixtures, { recursive: true, force: true });
});

const homes: string[] = [];
afterEach(async () => {
requests.length = 0;
await Promise.all(homes.splice(0).map((path) => rm(path, { recursive: true, force: true })));
});

async function newHome() {
const home = await mkdtemp(join(tmpdir(), "wt-dash-install-"));
homes.push(home);
return home;
}

/** Runs `curl -fsSL <server>/install.sh | sh`, or pipes `script` into sh when given. */
async function install(env: Record<string, string>, script?: string) {
const base = server.url.href.replace(/\/$/, "");
const child = Bun.spawn(
script === undefined ? ["sh", "-c", `curl -fsSL ${base}/install.sh | sh`] : ["sh"],
{
env: { PATH: SYSTEM_PATH, WT_DASH_RELEASES_URL: `${base}/releases`, ...env },
stdin: script === undefined ? "ignore" : new TextEncoder().encode(script),
stdout: "pipe",
stderr: "pipe",
},
);
const [output, error, code] = await Promise.all([
new Response(child.stdout).text(),
new Response(child.stderr).text(),
child.exited,
]);
return { code, output, error };
}

async function run(executable: string) {
const child = Bun.spawn([executable], { stdout: "pipe", stderr: "pipe" });
return (await new Response(child.stdout).text()).trim();
}

test("the one-liner installs the latest release for this machine and says what is left to set up", async () => {
const home = await newHome();
const result = await install({ HOME: home });
expect(result.code).toBe(0);
expect(requests).toContain(`/releases/download/v0.2.0/wt-dash-v0.2.0-${PLATFORM}.tar.gz`);
expect(await run(join(home, ".local/bin/wt-dash"))).toBe("0.2.0");
expect(result.output).toContain(`Installed wt-dash 0.2.0 to ${home}/.local/bin/wt-dash`);
expect(result.output).toContain(`${home}/.local/bin is not on your PATH.`);
expect(result.output).toContain(`export PATH="${home}/.local/bin:$PATH"`);
expect(result.error).toContain("wt-dash needs Worktrunk 0.80.0 or newer");
expect(result.error).toContain("brew install worktrunk, or cargo install worktrunk");
});

test("a pinned version installs into WT_DASH_INSTALL_DIR, and nothing is flagged once PATH and Worktrunk are set up", async () => {
const home = await newHome();
const bin = join(home, "my bin");
const tools = join(home, "tools");
await mkdir(tools);
await writeFile(join(tools, "wt"), "#!/bin/sh\necho wt v0.80.0\n");
await chmod(join(tools, "wt"), 0o755);
const result = await install({
HOME: home,
PATH: `${bin}:${tools}:${SYSTEM_PATH}`,
WT_DASH_VERSION: "0.1.0",
WT_DASH_INSTALL_DIR: bin,
});
expect(result).toMatchObject({ code: 0, error: "" });
expect(requests).not.toContain("/releases/latest");
expect(await run(join(bin, "wt-dash"))).toBe("0.1.0");
expect(result.output).not.toContain("PATH");
expect(result.output).toContain("Check the setup with: wt-dash --doctor");
});

test("an archive that does not match its published checksum is not installed", async () => {
const home = await newHome();
const result = await install({ HOME: home, WT_DASH_VERSION: "v0.0.9" });
expect(result.code).toBe(1);
expect(result.error).toContain(
`wt-dash-v0.0.9-${PLATFORM}.tar.gz does not match its published checksum, so nothing was installed.`,
);
expect(await Bun.file(join(home, ".local/bin/wt-dash")).exists()).toBe(false);
});

test("a release that can't run on this system leaves the installed copy in place", async () => {
const home = await newHome();
const bin = join(home, ".local/bin");
expect((await install({ HOME: home, WT_DASH_VERSION: "0.1.0" })).code).toBe(0);
const result = await install({ HOME: home, WT_DASH_VERSION: "0.0.8" });
expect(result.code).toBe(1);
expect(result.error).toContain(
"wt-dash 0.0.8 does not run on this system, so nothing was installed: version GLIBC_2.99 not found",
);
expect(await run(join(bin, "wt-dash"))).toBe("0.1.0");
expect(await readdir(bin)).toEqual(["wt-dash"]);
});

test("a release that does not exist fails with the URL it tried", async () => {
const home = await newHome();
const result = await install({ HOME: home, WT_DASH_VERSION: "9.9.9" });
expect(result.code).toBe(1);
expect(result.error).toContain(
`could not download ${server.url.href}releases/download/v9.9.9/wt-dash-v9.9.9-${PLATFORM}.tar.gz`,
);
});

test("a download cut off partway runs nothing", async () => {
const home = await newHome();
const script = await readFile(INSTALLER, "utf8");
const cut = script.slice(0, script.indexOf(" mkdir -p"));
const result = await install({ HOME: home }, cut);
expect(result.code).not.toBe(0);
expect(requests).toEqual([]);
expect(result.output).toBe("");
expect(await Bun.file(join(home, ".local")).exists()).toBe(false);
});
4 changes: 4 additions & 0 deletions tests/site.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ test("the assembled landing page finds every file it links to", async () => {

const html = await readFile(join(out, "index.html"), "utf8");
expect(html).toContain("brew install rigomart/tap/wt-dash");
expect(html).toContain("curl -fsSL https://wt-dash.rigos.dev/install.sh | sh");
expect(await readFile(join(out, "install.sh"), "utf8")).toBe(
await readFile(resolve(import.meta.dir, "../site/install.sh"), "utf8"),
);

const local = [...html.matchAll(/(?:src|href)="([^"#:]+)"/g)].map((match) => match[1]!);
expect(local).toContain("images/projects.png");
Expand Down
Loading