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
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ checksum:

changelog:
use: git
sort: asc
filters:
exclude:
- "^docs:"
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ Recommended archive set:
- linux-arm64
- linux-amd64

Install from a prebuilt archive (example: `v0.1.0`, `darwin-arm64`):

```bash
curl -fsSL "https://raw.githubusercontent.com/keyskey/gobce/main/scripts/install.sh" | sh
```

Install a specific version:

```bash
VERSION=v0.1.0 curl -fsSL "https://raw.githubusercontent.com/keyskey/gobce/main/scripts/install.sh" | sh

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Environment variables not propagated to piped sh process

High Severity

The VERSION and INSTALL_DIR variables in the install commands are not passed to the sh process. Shell prefix assignments (VAR=value cmd) only apply to the immediate command, not commands in a pipe. This causes the install script to silently ignore the user's specified version or install directory, falling back to defaults.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5dd8f39. Configure here.

```

Install to a custom directory:

```bash
INSTALL_DIR="$HOME/.local/bin" curl -fsSL "https://raw.githubusercontent.com/keyskey/gobce/main/scripts/install.sh" | sh
```

## CLI Usage

```bash
Expand Down
90 changes: 90 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env sh

set -eu

REPO="keyskey/gobce"
BINARY_NAME="${BINARY_NAME:-gobce}"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"

need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "required command not found: $1" >&2
exit 1
fi
}

detect_os() {
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$os" in
darwin|linux) echo "$os" ;;
*)
echo "unsupported OS: $os (supported: darwin, linux)" >&2
exit 1
;;
esac
}

detect_arch() {
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) echo "amd64" ;;
arm64|aarch64) echo "arm64" ;;
*)
echo "unsupported architecture: $arch (supported: amd64, arm64)" >&2
exit 1
;;
esac
}

resolve_version() {
if [ -n "${VERSION:-}" ]; then
echo "$VERSION"
return
fi

need_cmd curl
version="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p' | sed -n '1p')"
if [ -z "$version" ]; then
echo "could not resolve latest release version; set VERSION=vX.Y.Z and retry" >&2
exit 1
fi
echo "$version"
}

install_binary() {
need_cmd curl
need_cmd tar
need_cmd mktemp

os="$(detect_os)"
arch="$(detect_arch)"
version="$(resolve_version)"
version_no_v="${version#v}"
archive="${BINARY_NAME}_${version_no_v}_${os}_${arch}.tar.gz"
download_url="https://github.com/${REPO}/releases/download/${version}/${archive}"

tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT INT TERM

echo "downloading ${download_url}"
curl -fL -o "${tmp_dir}/${archive}" "$download_url"
tar -xzf "${tmp_dir}/${archive}" -C "$tmp_dir"

if [ ! -f "${tmp_dir}/${BINARY_NAME}" ]; then
echo "binary not found in archive: ${BINARY_NAME}" >&2
exit 1
fi

mkdir -p "$INSTALL_DIR"
if command -v install >/dev/null 2>&1; then
install -m 0755 "${tmp_dir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
else
cp "${tmp_dir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
chmod 0755 "${INSTALL_DIR}/${BINARY_NAME}"
fi

echo "installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}"
echo "run: ${BINARY_NAME} --help"
}

install_binary
Loading