#!/bin/sh # Grenade on Linux: installs the `grenade` command for this user. No sudo, no package manager. # # curl -fsSL https://www.holdgrenade.com/install.sh | sh # # What it does: # 1. reads the release list Homebrew installs from (the tap's formula: a download address and its sha256) # 2. downloads that tarball from github.com/holdgrenade/grenade-cli and checks it against the sha256 # 3. unpacks it into ~/.local/share/grenade and links ~/.local/bin/grenade to it # Running it again updates. Afterwards grenaded keeps itself up to date the same way. # To remove: grenade service remove; rm -rf ~/.local/share/grenade ~/.local/bin/grenade # On a Mac use Homebrew instead: brew install holdgrenade/tap/grenade # # The steps mirror grenade-cli src/update/tarballInstall.ts (what the daemon updates itself with). set -eu FORMULA_URL=https://raw.githubusercontent.com/holdgrenade/homebrew-tap/main/Formula/grenade.rb say() { printf '%s\n' "$*"; } fail() { printf 'grenade: %s\n' "$*" >&2 exit 1 } # Everything runs from here, so a download that broke off halfway runs nothing. main() { [ "$(uname -s)" = Linux ] || fail "this installer is for Linux. On a Mac: brew install holdgrenade/tap/grenade" [ -n "${HOME:-}" ] || fail "HOME is not set" for tool in curl tar sed; do command -v "$tool" >/dev/null 2>&1 || fail "$tool is needed and is not on your PATH" done if ! command -v node >/dev/null 2>&1; then fail "Node 22 or newer is needed, and node is not on your PATH. Install it (Arch and Omarchy: sudo pacman -S nodejs, or mise use -g node@lts), then run this again." fi major=$(node -p 'process.versions.node.split(".")[0]') [ "$major" -ge 22 ] || fail "Node 22 or newer is needed; this is $(node --version)" root=${XDG_DATA_HOME:-$HOME/.local/share}/grenade bin=$HOME/.local/bin formula=$(curl -fsSL "$FORMULA_URL") || fail "could not read the release list ($FORMULA_URL)" url=$(printf '%s\n' "$formula" | sed -n 's/^ *url "\(https:\/\/github\.com\/holdgrenade\/grenade-cli\/releases\/download\/[^"]*\)"$/\1/p' | head -n 1) sha=$(printf '%s\n' "$formula" | sed -n 's/^ *sha256 "\([0-9a-f]\{64\}\)"$/\1/p' | head -n 1) version=$(printf '%s\n' "$url" | sed -n 's/.*\/download\/v\([0-9][0-9.]*\)\/.*/\1/p') if [ -z "$url" ] || [ -z "$sha" ] || [ -z "$version" ]; then fail "no release is listed"; fi say "Installing Grenade $version into $root" mkdir -p "$root" "$bin" tmp=$(mktemp -d "$root/.new.XXXXXX") trap 'rm -rf "$tmp"' EXIT curl -fsSL -o "$tmp/grenade.tgz" "$url" || fail "could not download $url" if command -v sha256sum >/dev/null 2>&1; then got=$(sha256sum "$tmp/grenade.tgz" | cut -d" " -f1) else got=$(shasum -a 256 "$tmp/grenade.tgz" | cut -d" " -f1) fi [ "$got" = "$sha" ] || fail "the download's checksum does not match the release list; nothing was installed" tar -xzf "$tmp/grenade.tgz" -C "$tmp" [ -f "$tmp/package/dist/cli.js" ] || fail "the download is not a Grenade release; nothing was installed" chmod +x "$tmp/package/dist/cli.js" rm -rf "$root/package.old" if [ -d "$root/package" ]; then mv "$root/package" "$root/package.old"; fi mv "$tmp/package" "$root/package" rm -rf "$root/package.old" ln -sfn "$root/package/dist/cli.js" "$bin/grenade" say "Installed $bin/grenade ($("$bin/grenade" --version))" first=$(command -v grenade 2>/dev/null || true) case ":$PATH:" in *":$bin:"*) ;; *) say "" say "$bin is not on your PATH. Add this line to ~/.bashrc (or your shell's own file), then open a new terminal:" say " export PATH=\"\$HOME/.local/bin:\$PATH\"" ;; esac if [ -n "$first" ] && [ "$first" != "$bin/grenade" ]; then say "" say "Another grenade comes first on your PATH: $first" say "If npm put it there, take it out with: npm uninstall -g @holdgrenade/cli" fi say "" say "Next: grenade setup" } main "$@"