#!/usr/bin/env bash
# Is this machine able to build Android 17? Exit 0 = yes, 1 = no.
# Thresholds are the build's real appetite, not AOSP's published minimum.
# Override the probes for testing with VANTA_CORES / VANTA_RAM_GB / VANTA_DISK_GB.
set -uo pipefail
SRC=${1:-$HOME/vanta}
mkdir -p "$SRC" 2>/dev/null || true
cores=${VANTA_CORES:-$(nproc --all)}
ram=${VANTA_RAM_GB:-$(awk '/MemTotal/ {printf "%d", $2/1048576}' /proc/meminfo)}
disk=${VANTA_DISK_GB:-$(df -BG --output=avail "$SRC" 2>/dev/null | tail -1 | tr -dc 0-9)}
fail=0
chk() { if [ "$2" -ge "$3" ]; then echo "ok    $1: $2 (need $3)"; else echo "FAIL  $1: $2 (need $3)"; fail=1; fi; }
chk cores "$cores" 16
chk ram_gb "$ram" 64
chk disk_gb "${disk:-0}" 400
case "$(uname -m)" in x86_64) echo "ok    arch: x86_64";; *) echo "FAIL  arch: $(uname -m) (AOSP builds on x86_64 only)"; fail=1;; esac
[ "$fail" = 0 ] && echo "preflight: ready" || echo "preflight: NOT a build host"
exit $fail
