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

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "$repo_root/scripts/lib-hypertwist-sentrux.sh"
temp_root_parent="${TMPDIR:-/tmp}"
sentrux_command="$(hypertwist_resolve_sentrux_command "$repo_root")" || {
  echo "Unable to locate sentrux. Provide HYPERTWIST_SENTRUX_BINARY, place a repo-local sentrux binary under $repo_root/tools/sentrux/bin, add sentrux to PATH, or run scripts/bootstrap-hypertwist-sentrux.sh (set HYPERTWIST_ALLOW_SIBLING_SENTRUX_BOOTSTRAP=1 only if you intentionally want legacy sibling-repo seeding on this machine)." >&2
  exit 1
}

temp_root="$(mktemp -d "${temp_root_parent%/}/hypertwist-sentrux-source-only.XXXXXX")"
cleanup() {
  rm -rf "$temp_root"
}
trap cleanup EXIT

hypertwist_populate_sentrux_source_only_root "$repo_root" "$temp_root"

(
  cd "$repo_root"
  "$sentrux_command" check "$temp_root"
)
