#!/usr/bin/env bash
# One-time build-host setup (Ubuntu 22.04/24.04 or Debian 12). Idempotent.
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq || true  # a broken third-party source must not stop us
apt-get install -y -qq git git-lfs gnupg flex bison build-essential zip unzip curl \
  zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev \
  libxml2-utils xsltproc fontconfig python3 python-is-python3 ccache rsync bc lz4 \
  libssl-dev libncurses-dev libelf-dev dwarves cpio xz-utils python3-pil >/dev/null
git lfs install --system >/dev/null
if ! command -v repo >/dev/null; then
  curl -fsSL https://storage.googleapis.com/git-repo-downloads/repo -o /usr/local/bin/repo
  chmod a+rx /usr/local/bin/repo
fi
git config --global user.name  >/dev/null || git config --global user.name  "failure"
git config --global user.email >/dev/null || git config --global user.email "zandy@failure.fail"
git config --global color.ui false
# ccache on a big box: 100 GB turns a rebuild after a sync into ~20 minutes.
ccache -M 100G >/dev/null
echo "host-bootstrap: ok ($(repo --version 2>/dev/null | head -1))"
