|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Install the SMP CLI binary from S3. |
| 5 | +# Resolves the latest stable version via gh, detects the platform, |
| 6 | +# and downloads the binary to ~/.cargo/bin. |
| 7 | + |
| 8 | +SMP_INSTALL_DIR="${HOME}/.cargo/bin" |
| 9 | + |
| 10 | +if command -v smp >/dev/null 2>&1; then |
| 11 | + echo "smp is already installed: $(smp --version 2>/dev/null)" |
| 12 | + exit 0 |
| 13 | +fi |
| 14 | + |
| 15 | +# Resolve latest stable version via gh |
| 16 | +if ! command -v gh >/dev/null 2>&1; then |
| 17 | + echo "ERROR: gh CLI not found (needed to resolve version). Install with: brew install gh" |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +SMP_CLI_VERSION=$(gh release list --repo DataDog/single-machine-performance --limit 1 --exclude-pre-releases 2>/dev/null | awk '{print $1}') |
| 22 | +if [ -z "$SMP_CLI_VERSION" ]; then |
| 23 | + echo "ERROR: could not resolve latest SMP version from GitHub" |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +echo "Resolved SMP CLI version: ${SMP_CLI_VERSION}" |
| 28 | + |
| 29 | +# Determine target triple |
| 30 | +OS="$(uname -s)" |
| 31 | +ARCH="$(uname -m)" |
| 32 | +case "${OS}-${ARCH}" in |
| 33 | + Darwin-arm64) TARGET="aarch64-apple-darwin" ;; |
| 34 | + Darwin-x86_64) TARGET="x86_64-apple-darwin" ;; |
| 35 | + Linux-aarch64) TARGET="aarch64-unknown-linux-musl" ;; |
| 36 | + Linux-x86_64) TARGET="x86_64-unknown-linux-musl" ;; |
| 37 | + *) |
| 38 | + echo "ERROR: unsupported platform ${OS}-${ARCH}" |
| 39 | + exit 1 |
| 40 | + ;; |
| 41 | +esac |
| 42 | + |
| 43 | +# Download from S3 |
| 44 | +if ! command -v aws >/dev/null 2>&1; then |
| 45 | + echo "ERROR: aws CLI not found (needed to download from S3). Install with: brew install awscli" |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +mkdir -p "$SMP_INSTALL_DIR" |
| 50 | +S3_PATH="s3://smp-cli-releases/${SMP_CLI_VERSION}/${TARGET}/smp" |
| 51 | +echo "Downloading ${S3_PATH} -> ${SMP_INSTALL_DIR}/smp" |
| 52 | + |
| 53 | +if ! aws s3 cp "$S3_PATH" "${SMP_INSTALL_DIR}/smp"; then |
| 54 | + echo "ERROR: download from S3 failed (check AWS credentials: aws sts get-caller-identity)" |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | + |
| 58 | +chmod +x "${SMP_INSTALL_DIR}/smp" |
| 59 | + |
| 60 | +# smp --version emits ANSI escape codes and INFO log lines; extract just the version tag |
| 61 | +if SMP_RAW=$("${SMP_INSTALL_DIR}/smp" --version 2>/dev/null); then |
| 62 | + SMP_VER=$(echo "$SMP_RAW" | sed 's/\x1b\[[0-9;]*m//g' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1) |
| 63 | + echo "Installed smp ${SMP_VER:-unknown} to ${SMP_INSTALL_DIR}" |
| 64 | +else |
| 65 | + echo "ERROR: downloaded binary failed version check" |
| 66 | + exit 1 |
| 67 | +fi |
0 commit comments