#!/bin/sh # Festoon installer. # # curl -fsSL https://get.festoon.dev | sh # # Downloads the standalone build for this platform and puts it on PATH. # No Python, no package manager, no repository clone. # # The build is a directory, not one file: a PyInstaller onefile binary # unpacks itself into a fresh temp dir on every run, and macOS assesses each # freshly written extension module on first load — ~7s for every command and # every Claude Code hook. Unpacked once, the same build starts in ~0.2s. # # $FESTOON_LIB_DIR/versions//festoon (+ _internal/) # $FESTOON_LIB_DIR/current -> versions/ # $FESTOON_INSTALL_DIR/festoon -> $FESTOON_LIB_DIR/current/festoon # # Keep in step with src/festoon/cli/upgrade.py, which maintains the same # layout. set -eu # The PUBLIC release repository, not the private source one — a private # repo's assets 404 for unauthenticated curl. Keep in step with REPO in # src/festoon/cli/upgrade.py and RELEASE_REPO in the release workflow. REPO="${FESTOON_REPO:-standley-brent/festoon-cli}" VERSION="${FESTOON_VERSION:-latest}" # Prefer a user-writable location so the common case needs no sudo. INSTALL_DIR="${FESTOON_INSTALL_DIR:-$HOME/.local/bin}" LIB_DIR="${FESTOON_LIB_DIR:-$HOME/.local/share/festoon}" # A local release tarball instead of downloading one. CI installs the # artifact it just built through this, so the installer is tested against # the real thing before anyone runs it. ARCHIVE="${FESTOON_ARCHIVE:-}" err() { printf 'festoon: %s\n' "$1" >&2; exit 1; } detect_target() { os=$(uname -s) arch=$(uname -m) case "$os" in Darwin) os=macos ;; Linux) os=linux ;; *) err "unsupported operating system: $os (Windows: see the MSI installer)" ;; esac case "$arch" in arm64|aarch64) arch=arm64 ;; x86_64|amd64) arch=x64 ;; *) err "unsupported architecture: $arch" ;; esac printf '%s-%s' "$os" "$arch" } # Replace a symlink atomically, even one pointing at a directory, which plain # `mv` would move the new link INTO. GNU spells "treat the destination as a # file" -T, BSD/macOS -h. swap_link() { ln -s "$1" "$2.new.$$" mv -Tf "$2.new.$$" "$2" 2>/dev/null || mv -hf "$2.new.$$" "$2" \ || { rm -f "$2.new.$$"; err "could not update $2"; } } main() { command -v tar >/dev/null 2>&1 || err "tar is required" target=$(detect_target) asset="festoon-$target.tar.gz" if [ "$VERSION" = "latest" ]; then url="https://github.com/$REPO/releases/latest/download/$asset" else url="https://github.com/$REPO/releases/download/$VERSION/$asset" fi # Staged inside versions/, never /tmp: the move into place must be a # rename on one filesystem. A copy would be all-new files, and new files # pay the macOS first-run assessment again. mkdir -p "$LIB_DIR/versions" stage=$(mktemp -d "$LIB_DIR/versions/.install.XXXXXX") # Always clean up, including on failure — a half-unpacked build left # behind is worse than none. trap 'rm -rf "$stage"' EXIT INT TERM if [ -n "$ARCHIVE" ]; then cp "$ARCHIVE" "$stage/$asset" || err "cannot read $ARCHIVE" else command -v curl >/dev/null 2>&1 || err "curl is required" printf 'Downloading festoon (%s)...\n' "$target" if ! curl -fsSL "$url" -o "$stage/$asset"; then err "download failed: $url If this version has no build for $target yet, check: https://github.com/$REPO/releases" fi fi tar -xzf "$stage/$asset" -C "$stage" || err "the download could not be unpacked" [ -x "$stage/festoon/festoon" ] || err "the download has no festoon/festoon inside" # Verify before installing, so a corrupt download cannot replace a # working install. This is also the slow first start, so the first # Claude Code hook after installing does not pay it. printf 'Verifying (the first start takes a few seconds)...\n' reported=$("$stage/festoon/festoon" --version 2>/dev/null) \ || err "the downloaded binary did not run — installation aborted" version=${reported##* } case "$version" in ""|.*|*/*) err "the downloaded binary reported an unusable version: $reported" ;; esac previous="" if [ -L "$LIB_DIR/current" ]; then previous=$(basename "$(readlink "$LIB_DIR/current")") fi # Reinstalling the version that is current goes in beside it, so # `current` never points at a directory being removed. name=$version [ "$previous" != "$name" ] || name="$version.1" rm -rf "$LIB_DIR/versions/$name" mv "$stage/festoon" "$LIB_DIR/versions/$name" swap_link "versions/$name" "$LIB_DIR/current" # Older versions go; the one that was current stays, because a hook # started before the swap may still be loading modules from it. for dir in "$LIB_DIR"/versions/*; do old=$(basename "$dir") [ "$old" = "$name" ] || [ "$old" = "$previous" ] || rm -rf "$dir" done # Replaces a legacy single-file install in place, so hooks and PATH # entries naming $INSTALL_DIR/festoon keep working. mkdir -p "$INSTALL_DIR" rm -f "$INSTALL_DIR/festoon.new.$$" ln -s "$LIB_DIR/current/festoon" "$INSTALL_DIR/festoon.new.$$" mv -f "$INSTALL_DIR/festoon.new.$$" "$INSTALL_DIR/festoon" printf '\n%s installed to %s\n' "$reported" "$INSTALL_DIR/festoon" # `join` takes no org: signing in decides it. The hint used to say # `festoon join `, which argparse rejects — so the first command # a new user copied from here failed. case ":$PATH:" in *":$INSTALL_DIR:"*) printf '\nNext: festoon join\n' ;; *) # Name the file the user's own shell reads; the Linux build serves # bash users, for whom ~/.zshrc does nothing. case "${SHELL:-}" in */zsh) rc="$HOME/.zshrc" ;; */bash) rc="$HOME/.bashrc" ;; *) rc="$HOME/.profile" ;; esac printf '\n%s is not on your PATH. Add it:\n' "$INSTALL_DIR" printf ' echo '"'"'export PATH="%s:$PATH"'"'"' >> %s\n' "$INSTALL_DIR" "$rc" printf '\nthen open a new terminal and run: festoon join\n' ;; esac } main "$@"