#!/bin/sh
set -eu

ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
# shellcheck disable=SC1091
. "$ROOT/rehearsal-versions.env"

actual_solana=$(solana --version)
actual_anchor=$(anchor --version)
actual_rust=$(rustc --version)
actual_node=$(node --version)

case "$actual_solana" in
  *"$SOLANA_VERSION"*) ;;
  *) echo "Solana version mismatch: expected $SOLANA_VERSION, got $actual_solana" >&2; exit 1 ;;
esac
case "$actual_anchor" in
  *"$ANCHOR_VERSION"*) ;;
  *) echo "Anchor version mismatch: expected $ANCHOR_VERSION, got $actual_anchor" >&2; exit 1 ;;
esac
case "$actual_rust" in
  *"$RUST_VERSION"*) ;;
  *) echo "Rust version mismatch: expected $RUST_VERSION, got $actual_rust" >&2; exit 1 ;;
esac
case "$actual_node" in
  v"$NODE_MAJOR".*) ;;
  *) echo "Node major mismatch: expected $NODE_MAJOR, got $actual_node" >&2; exit 1 ;;
esac

printf '%s\n' "$actual_solana" "$actual_anchor" "$actual_rust" "$actual_node"
