#!/bin/sh
# Installs borer on macOS or Linux and registers it with every MCP client it
# finds (Claude Code, Claude Desktop, Cursor, Windsurf, VS Code, Gemini CLI,
# Codex CLI, Zed):
#
# curl -fsSL https://borer.lol/install | sh
#
# Served by the borer site at /install (apps/web/install/install.sh).
#
# It downloads the release archive for this machine, checks it against the
# release's SHA256SUMS, puts the binary in BORER_INSTALL (default
# ~/.local/bin) and runs `borer setup --apply`.
#
# BORER_VERSION=v0.1.0 install that release instead of the latest
# BORER_INSTALL=
install there instead of ~/.local/bin
# BORER_NO_SETUP=1 install only; register nothing
# BORER_MIRROR= fetch release files from // (needs BORER_VERSION)
#
# To uninstall, run it with --uninstall (or with BORER_UNINSTALL=1):
#
# curl -fsSL https://borer.lol/install | sh -s -- --uninstall
#
# That runs `borer setup --apply --remove`, deletes the binary and borer's cache
# ($XDG_CACHE_HOME/borer, else ~/.cache/borer), and says what it left.
#
# Everything runs from main, called on the last line: a download cut short
# defines at most part of it and runs nothing.
set -eu
REPO="imjustprism/borer"
dir="${BORER_INSTALL:-$HOME/.local/bin}"
say() { printf 'borer: %s\n' "$*"; }
fail() {
printf 'borer: %s\n' "$*" >&2
exit 1
}
need() { command -v "$1" >/dev/null 2>&1 || fail "needs $1"; }
# Removes the copies of borer left in $dir: a borer.new this script did not
# finish moving, and the borer.old, borer.N.old and .borer.update that
# `borer update` can leave.
clear_leftovers() {
for f in "$dir/borer.new" "$dir/borer.old" "$dir"/borer.[0-9]*.old "$dir/.borer.update"; do
[ -f "$f" ] && rm -f "$f"
done
return 0
}
# borer's cache, where the CLI keeps it (cache_base in its index.rs):
# indexes, fetched PDBs and the update check's answer.
cache_dir() { printf '%s/borer' "${LOCALAPPDATA:-${XDG_CACHE_HOME:-$HOME/.cache}}"; }
uninstall() {
left=""
if [ -x "$dir/borer" ]; then
# Before the binary goes: it is what knows each client's config.
say "removing borer from the MCP clients it registered with"
"$dir/borer" setup --apply --remove ||
left="$left
MCP client registrations: 'borer setup --apply --remove' failed; remove the borer server from each client's MCP settings"
rm -f "$dir/borer"
say "removed $dir/borer"
else
left="$left
MCP client registrations, if any: no $dir/borer to run 'borer setup --apply --remove' with; remove the borer server from each client's MCP settings"
fi
clear_leftovers
cache=$(cache_dir)
if [ -d "$cache" ]; then
rm -rf "$cache"
say "removed the cache, $cache"
fi
[ -n "${BORER_CACHE_DIR:-}" ] && left="$left
$BORER_CACHE_DIR: the index cache BORER_CACHE_DIR points at"
[ -n "${BORER_SYMCACHE:-}" ] && left="$left
$BORER_SYMCACHE: the PDB cache BORER_SYMCACHE points at"
# This script never edits a shell profile, so there is no line of its own
# to take out; one added by hand for borer can go.
case ":$PATH:" in
*":$dir:"*) left="$left
$dir on PATH: this installer never edits shell profiles; if you added that line for borer, remove it" ;;
esac
if [ -n "$left" ]; then
say "left in place:$left"
else
say "uninstalled"
fi
}
main() {
for arg in "$@"; do
case "$arg" in
--uninstall) BORER_UNINSTALL=1 ;;
*) fail "unknown option $arg (the one option is --uninstall)" ;;
esac
done
if [ "${BORER_UNINSTALL:-}" = "1" ]; then
uninstall
return
fi
need curl
need tar
need uname
case "$(uname -s)" in
Linux) os="unknown-linux-gnu" ;;
Darwin) os="apple-darwin" ;;
*) fail "no build for $(uname -s); on Windows use install.ps1" ;;
esac
case "$(uname -m)" in
x86_64 | amd64) arch="x86_64" ;;
arm64 | aarch64) arch="aarch64" ;;
*) fail "no build for $(uname -m)" ;;
esac
[ "$os" = "unknown-linux-gnu" ] && [ "$arch" = "aarch64" ] && fail "no Linux arm64 build yet"
target="$arch-$os"
# The latest release's tag, from where /releases/latest redirects.
tag="${BORER_VERSION:-}"
if [ -z "$tag" ]; then
url=$(curl -fsSLI -o /dev/null -w '%{url_effective}' "https://github.com/$REPO/releases/latest") ||
fail "could not reach GitHub"
tag="${url##*/}"
[ "$tag" = "latest" ] && fail "no release published yet"
fi
name="borer-$tag-$target"
base="${BORER_MIRROR:+$BORER_MIRROR/$tag}"
base="${base:-https://github.com/$REPO/releases/download/$tag}"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT INT TERM
say "downloading $name"
curl -fsSL -o "$tmp/$name.tar.gz" "$base/$name.tar.gz" || fail "no $name.tar.gz in release $tag"
curl -fsSL -o "$tmp/SHA256SUMS" "$base/SHA256SUMS" || fail "no SHA256SUMS in release $tag"
want=$(awk -v f="$name.tar.gz" '$2 == f || $2 == "*" f { print $1 }' "$tmp/SHA256SUMS")
[ -n "$want" ] || fail "SHA256SUMS lists no $name.tar.gz"
if command -v sha256sum >/dev/null 2>&1; then
got=$(sha256sum "$tmp/$name.tar.gz" | awk '{ print $1 }')
else
got=$(shasum -a 256 "$tmp/$name.tar.gz" | awk '{ print $1 }')
fi
[ "$got" = "$want" ] || fail "checksum mismatch for $name.tar.gz"
tar -xzf "$tmp/$name.tar.gz" -C "$tmp"
mkdir -p "$dir"
clear_leftovers
# Copied beside it, then renamed over it: a running borer (an MCP client keeps
# one open) cannot be written to, but it can be replaced.
cp "$tmp/$name/borer" "$dir/borer.new"
chmod 755 "$dir/borer.new"
mv -f "$dir/borer.new" "$dir/borer"
say "installed $tag to $dir/borer"
case ":$PATH:" in
*":$dir:"*) ;;
*) [ "${BORER_NO_PATH:-}" = "1" ] || say "add $dir to PATH to run borer from a shell" ;;
esac
if [ "${BORER_NO_SETUP:-}" = "1" ]; then
say "skipped setup; run: $dir/borer setup --apply"
else
"$dir/borer" setup --apply
fi
}
main "$@"