Repository navigation
feat: add install script for macOS and Linux #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
whynowy
wants to merge
2
commits into
a2aproject:main
Choose a base branch
from
whynowy:install
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+194
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # a2a installer | ||
| # | ||
| # Usage: | ||
| # curl -fsSL https://raw.githubusercontent.com/a2aproject/a2a-cli/main/install.sh | bash | ||
| # | ||
| # Environment variables: | ||
| # A2A_VERSION Specific version to install (e.g. v0.3.1 or 0.3.1). | ||
| # Defaults to the latest published release. | ||
| # A2A_INSTALL_DIR Directory to install the binary into. Defaults to | ||
| # /usr/local/bin (falls back to $HOME/.local/bin if not | ||
| # writable and sudo is unavailable). | ||
| # A2A_BINARY_NAME Name of the installed binary. Defaults to a2a. | ||
| # | ||
| set -euo pipefail | ||
|
|
||
| REPO="a2aproject/a2a-cli" | ||
| A2A_BINARY_NAME="${A2A_BINARY_NAME:-a2a}" | ||
| A2A_INSTALL_DIR="${A2A_INSTALL_DIR:-/usr/local/bin}" | ||
|
|
||
| tmpdir="" | ||
| trap 'rm -rf "${tmpdir:-}"' EXIT | ||
|
|
||
| log() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } | ||
| warn() { printf '\033[1;33m==>\033[0m %s\n' "$*" >&2; } | ||
| err() { printf '\033[1;31m==>\033[0m %s\n' "$*" >&2; exit 1; } | ||
|
|
||
| require() { | ||
| command -v "$1" >/dev/null 2>&1 || err "required command not found: $1" | ||
| } | ||
|
|
||
| require uname | ||
| require tar | ||
| require install | ||
| require mktemp | ||
|
|
||
| if command -v curl >/dev/null 2>&1; then | ||
| DOWNLOADER="curl" | ||
| elif command -v wget >/dev/null 2>&1; then | ||
| DOWNLOADER="wget" | ||
| else | ||
| err "neither curl nor wget is installed" | ||
| fi | ||
|
|
||
| if command -v sha256sum >/dev/null 2>&1; then | ||
| SHA256=(sha256sum) | ||
| elif command -v shasum >/dev/null 2>&1; then | ||
| SHA256=(shasum -a 256) | ||
| else | ||
| err "neither sha256sum nor shasum is installed" | ||
| fi | ||
|
|
||
| fetch() { | ||
| local url="$1" out="$2" | ||
| if [ "$DOWNLOADER" = "curl" ]; then | ||
| curl -fsSL "$url" -o "$out" | ||
| else | ||
| wget -qO "$out" "$url" | ||
| fi | ||
| } | ||
|
|
||
| fetch_stdout() { | ||
| local url="$1" | ||
| if [ "$DOWNLOADER" = "curl" ]; then | ||
| curl -fsSL "$url" | ||
| else | ||
| wget -qO- "$url" | ||
| fi | ||
| } | ||
|
|
||
| detect_os() { | ||
| local os | ||
| os="$(uname -s | tr '[:upper:]' '[:lower:]')" | ||
| case "$os" in | ||
| linux) echo "linux" ;; | ||
| darwin) echo "darwin" ;; | ||
| *) err "unsupported OS: $os (see https://github.com/${REPO}/releases for Windows builds)" ;; | ||
| esac | ||
| } | ||
|
|
||
| detect_arch() { | ||
| local arch | ||
| arch="$(uname -m)" | ||
| case "$arch" in | ||
| x86_64|amd64) echo "amd64" ;; | ||
| aarch64|arm64) echo "arm64" ;; | ||
| *) err "unsupported architecture: $arch" ;; | ||
| esac | ||
| } | ||
|
|
||
| resolve_tag() { | ||
| if [ -n "${A2A_VERSION:-}" ]; then | ||
| echo "v${A2A_VERSION#v}" | ||
| return | ||
| fi | ||
| local api_url="https://api.github.com/repos/${REPO}/releases/latest" | ||
| local tag | ||
| tag="$(fetch_stdout "$api_url" \ | ||
| | grep -E '"tag_name"' \ | ||
| | head -n 1 \ | ||
| | sed -E 's/.*"tag_name"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')" | ||
| [ -n "$tag" ] || err "failed to detect latest version from $api_url" | ||
| echo "$tag" | ||
| } | ||
|
|
||
| verify_checksum() { | ||
| local archive="$1" checksums="$2" name expected actual | ||
| name="$(basename "$archive")" | ||
| expected="$(awk -v n="$name" '$2 == n { print $1 }' "$checksums")" | ||
| [ -n "$expected" ] || err "no checksum found for $name" | ||
| actual="$("${SHA256[@]}" "$archive" | awk '{ print $1 }')" | ||
| [ "$expected" = "$actual" ] || err "checksum mismatch for $name (want $expected, got $actual)" | ||
| } | ||
|
|
||
| choose_install_dir() { | ||
| local dir="$A2A_INSTALL_DIR" | ||
| if [ -d "$dir" ] && [ -w "$dir" ]; then | ||
| echo "$dir" | ||
| return | ||
| fi | ||
| if [ ! -d "$dir" ] && mkdir -p "$dir" 2>/dev/null; then | ||
| echo "$dir" | ||
| return | ||
| fi | ||
| if command -v sudo >/dev/null 2>&1; then | ||
| echo "$dir" | ||
| return | ||
| fi | ||
| warn "$dir is not writable and sudo is unavailable; falling back to \$HOME/.local/bin" | ||
| mkdir -p "$HOME/.local/bin" | ||
| echo "$HOME/.local/bin" | ||
| } | ||
|
|
||
| install_binary() { | ||
| local src="$1" dest_dir="$2" dest="$2/$A2A_BINARY_NAME" | ||
| if [ -w "$dest_dir" ]; then | ||
| install -m 0755 "$src" "$dest" | ||
| return | ||
| fi | ||
| log "Installing to $dest (requires sudo)" | ||
| sudo mkdir -p "$dest_dir" | ||
| sudo install -m 0755 "$src" "$dest" | ||
| } | ||
|
|
||
| main() { | ||
| local os arch tag version base_url archive_name dest_dir | ||
| os="$(detect_os)" | ||
| arch="$(detect_arch)" | ||
| tag="$(resolve_tag)" | ||
| version="${tag#v}" | ||
| archive_name="a2a_${version}_${os}_${arch}.tar.gz" | ||
| base_url="https://github.com/${REPO}/releases/download/${tag}" | ||
|
|
||
| log "Installing a2a ${tag} for ${os}/${arch}" | ||
| log "Asset: ${base_url}/${archive_name}" | ||
|
|
||
| tmpdir="$(mktemp -d)" | ||
|
|
||
| fetch "${base_url}/${archive_name}" "${tmpdir}/${archive_name}" \ | ||
| || err "failed to download ${base_url}/${archive_name}" | ||
| fetch "${base_url}/checksums.txt" "${tmpdir}/checksums.txt" \ | ||
| || err "failed to download ${base_url}/checksums.txt" | ||
| verify_checksum "${tmpdir}/${archive_name}" "${tmpdir}/checksums.txt" | ||
|
|
||
| tar -xzf "${tmpdir}/${archive_name}" -C "$tmpdir" a2a \ | ||
| || err "failed to extract a2a from ${archive_name}" | ||
|
|
||
| dest_dir="$(choose_install_dir)" | ||
| install_binary "${tmpdir}/a2a" "$dest_dir" | ||
|
|
||
| log "Installed ${A2A_BINARY_NAME} to ${dest_dir}/${A2A_BINARY_NAME}" | ||
|
|
||
| case ":$PATH:" in | ||
| *":${dest_dir}:"*) ;; | ||
| *) warn "${dest_dir} is not in your PATH; add it to use ${A2A_BINARY_NAME} directly" ;; | ||
| esac | ||
|
|
||
| "${dest_dir}/${A2A_BINARY_NAME}" version || warn "installed binary failed to report its version" | ||
| } | ||
|
|
||
| main "$@" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unauthenticated api calls are limited to 60 per hour per IP. we can use
releases/latest/download/checksums.txtinstead