chore: pinned nats-server download script + gitignore tools/

This commit is contained in:
VolcanicCore
2026-08-27 11:28:14 +00:00
parent b35eda8440
commit 8327f567fd
2 changed files with 42 additions and 0 deletions

3
.gitignore vendored
View File

@@ -25,6 +25,9 @@ dist/
.env.*.local
*.log
# Downloaded tooling
/tools/
# OS
.DS_Store
Thumbs.db

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Downloads a pinned nats-server binary to tools/nats-server.
# Idempotent — skips download if the binary already exists at the pinned version.
set -euo pipefail
NATS_VERSION="${NATS_VERSION:-v2.10.22}"
DEST_DIR="$(cd "$(dirname "$0")/.." && pwd)/tools"
DEST="$DEST_DIR/nats-server"
mkdir -p "$DEST_DIR"
if [ -x "$DEST" ]; then
installed=$("$DEST" --version 2>&1 | head -1 | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown")
if [ "$installed" = "$NATS_VERSION" ]; then
echo "nats-server $NATS_VERSION already installed at $DEST"
exit 0
fi
echo "Replacing $DEST (was $installed) with $NATS_VERSION"
fi
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$arch" in
x86_64|amd64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*) echo "unsupported arch: $arch" >&2; exit 1 ;;
esac
pkg="nats-server-${NATS_VERSION}-${os}-${arch}"
url="https://github.com/nats-io/nats-server/releases/download/${NATS_VERSION}/${pkg}.tar.gz"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
echo "Downloading $url ..."
curl -fsSL "$url" -o "$tmp/nats.tgz"
tar -xzf "$tmp/nats.tgz" -C "$tmp"
mv "$tmp/$pkg/nats-server" "$DEST"
chmod +x "$DEST"
echo "Installed $DEST ($("$DEST" --version | head -1))"