Skip to content

Commit ccfb7c1

Browse files
chore(install): user-local dir, macOS codesign, skip GitHub API (#55)
* chore(install): user-local dir, macOS codesign, skip GitHub API * shellcheck
1 parent 2bcf964 commit ccfb7c1

4 files changed

Lines changed: 67 additions & 18 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@bunny.net/cli": patch
3+
---
4+
5+
Improve the `install.sh` shell installer:
6+
7+
- Default install directory is now `~/.bunny/bin` (no sudo required). Set `BUNNY_INSTALL_DIR=/usr/local/bin` to keep the previous behaviour.
8+
- On macOS, the installer now clears the `com.apple.quarantine` xattr and ad-hoc codesigns the binary so Gatekeeper allows execution on first run (fixes "killed: 9" on Apple Silicon).
9+
- Resolving the latest version no longer calls `api.github.com` (rate-limited to 60 req/hr); it uses GitHub's `releases/latest/download` redirect instead.
10+
- The script now warns if a legacy `bunny` binary is still present at `/usr/local/bin/bunny`, since depending on PATH order it may shadow the new install. Remove it with `sudo rm /usr/local/bin/bunny`.

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ jobs:
2121
run: bun build packages/cli/src/index.ts --compile --minify --sourcemap --outfile bunny
2222
- name: Build database-shell binary
2323
run: bun build packages/database-shell/src/cli.ts --compile --minify --sourcemap --outfile bsql
24+
- name: Lint install.sh (POSIX shellcheck)
25+
run: shellcheck -s sh install.sh
26+
- name: Bash syntax check install.sh
27+
run: bash -n install.sh

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ The CLI is distributed through three channels:
652652
curl -fsSL https://cli.bunny.net/install.sh | sh
653653
```
654654

655-
Downloads the prebuilt binary for the current platform from GitHub Releases and installs to `/usr/local/bin`. Supports `BUNNY_INSTALL_DIR` env var for custom paths. Script is at `install.sh` in the repo root.
655+
Downloads the prebuilt binary for the current platform from GitHub Releases and installs to `~/.bunny/bin`. Supports `BUNNY_INSTALL_DIR` env var for custom paths (e.g. `BUNNY_INSTALL_DIR=/usr/local/bin`). On macOS the script clears the quarantine xattr and ad-hoc codesigns the binary so Gatekeeper allows execution. Uses GitHub's `releases/latest/download` redirect to avoid the api.github.com rate limit. Script is at `install.sh` in the repo root.
656656

657657
**2. npm (platform-specific binary packages)**
658658

install.sh

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
set -e
33

44
REPO="bunnyWay/cli"
5-
INSTALL_DIR="${BUNNY_INSTALL_DIR:-/usr/local/bin}"
5+
INSTALL_DIR="${BUNNY_INSTALL_DIR:-$HOME/.bunny/bin}"
6+
BIN_NAME="bunny"
67

78
get_os() {
89
case "$(uname -s)" in
@@ -29,23 +30,19 @@ if [ "$OS" = "unsupported" ] || [ "$ARCH" = "unsupported" ]; then
2930
exit 1
3031
fi
3132

32-
# Determine version
33-
if [ -n "$1" ]; then
33+
BINARY="bunny-${OS}-${ARCH}"
34+
35+
# Pinned version uses the tagged release URL; otherwise use the `latest`
36+
# redirect so we don't hit api.github.com (rate-limited to 60 req/hr).
37+
if [ -n "${1:-}" ]; then
3438
VERSION="$1"
39+
URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY}"
40+
echo "Installing bunny ${VERSION} (${OS}/${ARCH})..."
3541
else
36-
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | cut -d'"' -f4)
37-
fi
38-
39-
if [ -z "$VERSION" ]; then
40-
echo "Error: Could not determine latest version."
41-
exit 1
42+
URL="https://github.com/${REPO}/releases/latest/download/${BINARY}"
43+
echo "Installing bunny (${OS}/${ARCH})..."
4244
fi
4345

44-
BINARY="bunny-${OS}-${ARCH}"
45-
URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY}"
46-
47-
echo "Installing bunny ${VERSION} (${OS}/${ARCH})..."
48-
4946
TMPFILE=$(mktemp)
5047
trap 'rm -f "$TMPFILE"' EXIT
5148

@@ -61,14 +58,52 @@ fi
6158

6259
chmod +x "$TMPFILE"
6360

61+
# Create install dir, falling back to sudo if needed (only relevant when
62+
# BUNNY_INSTALL_DIR points somewhere unwritable like /usr/local/bin).
63+
if ! mkdir -p "$INSTALL_DIR" 2>/dev/null; then
64+
echo "Creating ${INSTALL_DIR} (requires sudo)..."
65+
sudo mkdir -p "$INSTALL_DIR"
66+
fi
67+
6468
# Install
6569
if [ -w "$INSTALL_DIR" ]; then
66-
mv "$TMPFILE" "${INSTALL_DIR}/bunny"
70+
mv "$TMPFILE" "${INSTALL_DIR}/${BIN_NAME}"
6771
else
6872
echo "Installing to ${INSTALL_DIR} (requires sudo)..."
69-
sudo mv "$TMPFILE" "${INSTALL_DIR}/bunny"
73+
sudo mv "$TMPFILE" "${INSTALL_DIR}/${BIN_NAME}"
74+
fi
75+
76+
# macOS: clear quarantine xattr (set by curl) and ad-hoc sign so Gatekeeper
77+
# and the Apple Silicon kernel allow execution. Without this, first run on
78+
# darwin-arm64 fails with "killed: 9".
79+
if [ "$OS" = "darwin" ]; then
80+
xattr -d com.apple.quarantine "${INSTALL_DIR}/${BIN_NAME}" 2>/dev/null || true
81+
codesign --sign - --force "${INSTALL_DIR}/${BIN_NAME}" 2>/dev/null || true
7082
fi
7183

72-
echo "bunny ${VERSION} installed to ${INSTALL_DIR}/bunny"
84+
echo "bunny installed to ${INSTALL_DIR}/${BIN_NAME}"
85+
86+
# Warn if a previous install left a copy at /usr/local/bin/bunny — depending on
87+
# PATH order, that older binary may shadow the one we just installed.
88+
LEGACY_BIN="/usr/local/bin/bunny"
89+
if [ "${INSTALL_DIR}/${BIN_NAME}" != "$LEGACY_BIN" ] && [ -f "$LEGACY_BIN" ]; then
90+
echo ""
91+
echo "Warning: an existing bunny binary was found at ${LEGACY_BIN}."
92+
echo " Earlier versions of this installer wrote to /usr/local/bin. Depending on"
93+
echo " your PATH order, that older binary may shadow the new install."
94+
echo " Remove it with: sudo rm ${LEGACY_BIN}"
95+
fi
96+
97+
# PATH reminder when installing to a directory not on PATH
98+
case ":$PATH:" in
99+
*":$INSTALL_DIR:"*) ;;
100+
*)
101+
echo ""
102+
echo "${INSTALL_DIR} is not on your PATH. Add it by running:"
103+
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
104+
echo "and adding that line to your shell's rc file (~/.zshrc, ~/.bashrc, etc)."
105+
;;
106+
esac
107+
73108
echo ""
74109
echo "Run 'bunny --help' to get started."

0 commit comments

Comments
 (0)