|
| 1 | +#!/usr/bin/env bash |
| 2 | +# plugins/dso/scripts/acli-version-resolver.sh |
| 3 | +# |
| 4 | +# Spike PoC: resolves the current ACLI (Atlassian CLI) version and computes |
| 5 | +# its SHA-256 checksum for use in reproducible installs (e.g. Homebrew formulae). |
| 6 | +# |
| 7 | +# ── Version string format ───────────────────────────────────────────────────── |
| 8 | +# ACLI reports its version via: acli --version |
| 9 | +# Output format: acli version <semver>[-tag] |
| 10 | +# Example: acli version 1.3.5-stable |
| 11 | +# The version token is everything after "acli version " (space-trimmed). |
| 12 | +# The -stable suffix (or similar channel suffix) is preserved verbatim. |
| 13 | +# |
| 14 | +# ── Download URL patterns ───────────────────────────────────────────────────── |
| 15 | +# Latest binary (platform-detect bootstrap): |
| 16 | +# https://acli.atlassian.com/{platform}/latest/acli_{platform}_{arch} |
| 17 | +# Example: https://acli.atlassian.com/darwin/latest/acli_darwin_arm64 |
| 18 | +# |
| 19 | +# Versioned tarball (used for SHA-256 pinning): |
| 20 | +# https://acli.atlassian.com/{platform}/{version}/acli_{version}_{platform}_{arch}.tar.gz |
| 21 | +# Example: https://acli.atlassian.com/darwin/1.3.5-stable/acli_1.3.5-stable_darwin_arm64.tar.gz |
| 22 | +# |
| 23 | +# ── Supported platform / arch values ───────────────────────────────────────── |
| 24 | +# Platform: darwin, linux (auto-detected from `uname -s`) |
| 25 | +# Arch: amd64, arm64 (auto-detected from `uname -m`; x86_64 → amd64, arm64/aarch64 → arm64) |
| 26 | +# |
| 27 | +# ── Output format ───────────────────────────────────────────────────────────── |
| 28 | +# On success two lines are printed to stdout: |
| 29 | +# ACLI_VERSION=<version> |
| 30 | +# ACLI_SHA256=<hex-hash> |
| 31 | +# |
| 32 | +# ── Manually validated versions ─────────────────────────────────────────────── |
| 33 | +# Validated: v1.3.4-stable SHA256=<run manually to obtain> |
| 34 | +# Validated: v1.3.5-stable SHA256=<run manually to obtain> |
| 35 | +# |
| 36 | +# ── Usage ───────────────────────────────────────────────────────────────────── |
| 37 | +# acli-version-resolver.sh [--platform darwin|linux] [--arch amd64|arm64] |
| 38 | +# |
| 39 | +# Exit 0 on success; non-zero with a descriptive error message on stderr on failure. |
| 40 | + |
| 41 | +set -uo pipefail |
| 42 | + |
| 43 | +# ── Argument parsing ────────────────────────────────────────────────────────── |
| 44 | +PLATFORM="" |
| 45 | +ARCH="" |
| 46 | + |
| 47 | +while [[ $# -gt 0 ]]; do |
| 48 | + case "$1" in |
| 49 | + --platform) |
| 50 | + PLATFORM="$2" |
| 51 | + shift 2 |
| 52 | + ;; |
| 53 | + --arch) |
| 54 | + ARCH="$2" |
| 55 | + shift 2 |
| 56 | + ;; |
| 57 | + *) |
| 58 | + echo "ERROR: unknown argument: $1" >&2 |
| 59 | + exit 1 |
| 60 | + ;; |
| 61 | + esac |
| 62 | +done |
| 63 | + |
| 64 | +# ── Platform / arch detection ───────────────────────────────────────────────── |
| 65 | +if [[ -z "$PLATFORM" ]]; then |
| 66 | + raw_os="$(uname -s 2>/dev/null || true)" |
| 67 | + case "${raw_os,,}" in |
| 68 | + darwin) PLATFORM="darwin" ;; |
| 69 | + linux) PLATFORM="linux" ;; |
| 70 | + *) |
| 71 | + echo "ERROR: unsupported OS '${raw_os}'; pass --platform darwin|linux" >&2 |
| 72 | + exit 1 |
| 73 | + ;; |
| 74 | + esac |
| 75 | +fi |
| 76 | + |
| 77 | +if [[ -z "$ARCH" ]]; then |
| 78 | + raw_arch="$(uname -m 2>/dev/null || true)" |
| 79 | + case "$raw_arch" in |
| 80 | + x86_64) ARCH="amd64" ;; |
| 81 | + arm64|aarch64) ARCH="arm64" ;; |
| 82 | + *) |
| 83 | + echo "ERROR: unsupported arch '${raw_arch}'; pass --arch amd64|arm64" >&2 |
| 84 | + exit 1 |
| 85 | + ;; |
| 86 | + esac |
| 87 | +fi |
| 88 | + |
| 89 | +# ── Locate acli (use PATH if available, otherwise download latest bootstrap) ── |
| 90 | +TMPDIR_WORK="$(mktemp -d)" |
| 91 | +trap 'rm -rf "$TMPDIR_WORK"' EXIT |
| 92 | + |
| 93 | +if command -v acli &>/dev/null; then |
| 94 | + ACLI_BIN="$(command -v acli)" |
| 95 | +else |
| 96 | + # Download the latest acli binary for bootstrap |
| 97 | + LATEST_URL="https://acli.atlassian.com/${PLATFORM}/latest/acli_${PLATFORM}_${ARCH}" |
| 98 | + ACLI_BIN="$TMPDIR_WORK/acli" |
| 99 | + if ! curl -fsSL -o "$ACLI_BIN" "$LATEST_URL"; then |
| 100 | + echo "ERROR: failed to download acli from ${LATEST_URL}" >&2 |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + chmod +x "$ACLI_BIN" |
| 104 | +fi |
| 105 | + |
| 106 | +# ── Run acli --version and parse the version string ────────────────────────── |
| 107 | +version_output="$("$ACLI_BIN" --version 2>&1 || true)" |
| 108 | + |
| 109 | +# Expected format: "acli version <version>" |
| 110 | +# Extract the version token (third word) |
| 111 | +version_token="" |
| 112 | +if [[ "$version_output" =~ ^acli[[:space:]]+version[[:space:]]+([^[:space:]]+) ]]; then |
| 113 | + version_token="${BASH_REMATCH[1]}" |
| 114 | +fi |
| 115 | + |
| 116 | +if [[ -z "$version_token" ]]; then |
| 117 | + echo "ERROR: could not parse version from acli output: ${version_output}" >&2 |
| 118 | + exit 1 |
| 119 | +fi |
| 120 | + |
| 121 | +# ── Construct the versioned tarball URL ─────────────────────────────────────── |
| 122 | +TARBALL_URL="https://acli.atlassian.com/${PLATFORM}/${version_token}/acli_${version_token}_${PLATFORM}_${ARCH}.tar.gz" |
| 123 | + |
| 124 | +# ── Download the versioned tarball ─────────────────────────────────────────── |
| 125 | +TARBALL_PATH="$TMPDIR_WORK/acli_${version_token}_${PLATFORM}_${ARCH}.tar.gz" |
| 126 | +if ! curl -fsSL -o "$TARBALL_PATH" "$TARBALL_URL"; then |
| 127 | + echo "ERROR: failed to download versioned tarball from ${TARBALL_URL}" >&2 |
| 128 | + exit 1 |
| 129 | +fi |
| 130 | + |
| 131 | +# ── Compute SHA-256 ─────────────────────────────────────────────────────────── |
| 132 | +sha256="" |
| 133 | +if command -v sha256sum &>/dev/null; then |
| 134 | + sha256="$(sha256sum "$TARBALL_PATH" | awk '{print $1}')" |
| 135 | +elif command -v shasum &>/dev/null; then |
| 136 | + sha256="$(shasum -a 256 "$TARBALL_PATH" | awk '{print $1}')" |
| 137 | +else |
| 138 | + echo "ERROR: no sha256sum or shasum found in PATH" >&2 |
| 139 | + exit 1 |
| 140 | +fi |
| 141 | + |
| 142 | +# ── Output ──────────────────────────────────────────────────────────────────── |
| 143 | +echo "ACLI_VERSION=${version_token}" |
| 144 | +echo "ACLI_URL=${TARBALL_URL}" |
| 145 | +echo "ACLI_SHA256=${sha256}" |
0 commit comments