#!/usr/bin/env bash
set -euo pipefail

ARCH="$(uname -m)"
case "$ARCH" in
  x86_64|amd64) BINARY="pcrt-diagnostics-linux-amd64" ;;
  aarch64|arm64) BINARY="pcrt-diagnostics-linux-arm64" ;;
  *) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;;
esac

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE="$ROOT/dist/$BINARY"
if [[ ! -f "$SOURCE" ]]; then
  echo "Binary not found: $SOURCE" >&2
  echo "Run ./build.sh first or use the prebuilt binary package." >&2
  exit 1
fi

install -m 0755 "$SOURCE" /usr/local/bin/pcrt-diagnostics
printf 'Installed /usr/local/bin/pcrt-diagnostics\n'
printf 'Usage: sudo pcrt-diagnostics --code ABCDE\n'
