|
| 1 | +#!/usr/bin/env bash |
| 2 | +# /usr/libexec/mios/mios-build-driver |
| 3 | +# |
| 4 | +# Entry point for the inside-MiOS-DEV phase of the MiOS build pipeline. |
| 5 | +# |
| 6 | +# This script is INVOKED FROM WINDOWS (via `wt.exe new-tab wsl.exe -d |
| 7 | +# MiOS-DEV ... bash /usr/libexec/mios/mios-build-driver`) AFTER the |
| 8 | +# Windows-side bootstrap finishes: |
| 9 | +# |
| 10 | +# Day-0 split (per the self-replication architecture): |
| 11 | +# * Windows side irm | iex -> ack -> MiOS-DEV podman machine setup |
| 12 | +# * <handoff> Show-PostBootstrapMenu choice "Continue to build" |
| 13 | +# spawns a fresh Windows Terminal hosting `wsl.exe |
| 14 | +# -d MiOS-DEV` running THIS driver |
| 15 | +# * MiOS-DEV side fetch + overlay + identity + FULL build pipeline |
| 16 | +# for all output formats (OCI, WSL2/g, Hyper-V, |
| 17 | +# QEMU, Live-CD/USB, USB installer, RAW) |
| 18 | +# |
| 19 | +# The Windows side does NOT stream the build dashboard back -- the |
| 20 | +# dashboard renders on MiOS-DEV's tty inside the SSH/wsl session, and |
| 21 | +# the Windows Terminal is the host of that tty. That keeps the |
| 22 | +# multi-GB, multi-image build off the WSL2/Windows boundary. |
| 23 | +# |
| 24 | +# Idempotent: re-running picks up where the previous attempt left off |
| 25 | +# (clone is shallow; build cache is podman-managed; identity is |
| 26 | +# already-saved-to-/etc/mios/install.env on second run). |
| 27 | +set -euo pipefail |
| 28 | + |
| 29 | +# ── MiOS dashboard (banner + fastfetch + motd stats) ───────────────────────── |
| 30 | +# The operator's expectation per the architecture memo is that the |
| 31 | +# Windows-Terminal-hosted SSH window shows the unified MiOS dashboard, |
| 32 | +# not just plain build output. /etc/issue.d/ has the live banner |
| 33 | +# rendered by mios-dashboard-issue.service; printing it once here |
| 34 | +# anchors the operator in the MiOS context before the build noise |
| 35 | +# starts. |
| 36 | +if command -v mios-dashboard >/dev/null 2>&1; then |
| 37 | + mios-dashboard 2>/dev/null || true |
| 38 | +elif [[ -f /etc/motd ]]; then |
| 39 | + cat /etc/motd 2>/dev/null || true |
| 40 | +fi |
| 41 | + |
| 42 | +# ── Logging ────────────────────────────────────────────────────────────────── |
| 43 | +LOG_DIR="/var/log/mios" |
| 44 | +LOG_FILE="${LOG_DIR}/build-driver-$(date +%Y%m%d-%H%M%S).log" |
| 45 | +mkdir -p "$LOG_DIR" |
| 46 | +echo "[mios-build-driver] starting at $(date -Iseconds)" | tee -a "$LOG_FILE" |
| 47 | +echo "[mios-build-driver] logging to $LOG_FILE" |
| 48 | + |
| 49 | +_log() { echo "[mios-build-driver] $*" | tee -a "$LOG_FILE"; } |
| 50 | +_fail() { _log "FATAL: $*"; exit 1; } |
| 51 | + |
| 52 | +# ── Pre-flight ─────────────────────────────────────────────────────────────── |
| 53 | +WORKDIR="${MIOS_BUILD_WORKDIR:-/var/lib/mios/build}" |
| 54 | +mkdir -p "$WORKDIR" |
| 55 | + |
| 56 | +# Resolve the MiOS repo location. Three candidates in priority order: |
| 57 | +# 1. /.git -- live working tree (canonical when running on a real |
| 58 | +# MiOS host where `.git IS /` per the self-replication contract) |
| 59 | +# 2. /var/lib/mios/build/mios -- the dedicated build workspace |
| 60 | +# 3. /ctx -- the build-context bind mount inside `podman build` |
| 61 | +MIOS_REPO="" |
| 62 | +if [[ -d /.git ]]; then |
| 63 | + MIOS_REPO="/" |
| 64 | + _log "MiOS repo: live root (/.git present -- self-replication path)" |
| 65 | +elif [[ -d "$WORKDIR/mios/.git" ]]; then |
| 66 | + MIOS_REPO="$WORKDIR/mios" |
| 67 | + _log "MiOS repo: $MIOS_REPO (build workspace)" |
| 68 | +else |
| 69 | + _log "MiOS repo not found -- cloning to $WORKDIR/mios" |
| 70 | + mkdir -p "$WORKDIR/mios" |
| 71 | + git clone --depth=1 https://github.com/mios-dev/mios.git "$WORKDIR/mios" \ |
| 72 | + 2>&1 | tee -a "$LOG_FILE" \ |
| 73 | + || _fail "git clone of mios.git failed -- check network connectivity" |
| 74 | + MIOS_REPO="$WORKDIR/mios" |
| 75 | +fi |
| 76 | + |
| 77 | +# mios-bootstrap is needed for build helper scripts under automation/lib/. |
| 78 | +BOOT_REPO="" |
| 79 | +if [[ -d "$WORKDIR/mios-bootstrap/.git" ]]; then |
| 80 | + BOOT_REPO="$WORKDIR/mios-bootstrap" |
| 81 | +elif [[ -d /opt/mios-bootstrap/.git ]]; then |
| 82 | + BOOT_REPO="/opt/mios-bootstrap" |
| 83 | +else |
| 84 | + _log "mios-bootstrap repo not found -- cloning to $WORKDIR/mios-bootstrap" |
| 85 | + mkdir -p "$WORKDIR/mios-bootstrap" |
| 86 | + git clone --depth=1 https://github.com/mios-dev/mios-bootstrap.git "$WORKDIR/mios-bootstrap" \ |
| 87 | + 2>&1 | tee -a "$LOG_FILE" \ |
| 88 | + || _fail "git clone of mios-bootstrap.git failed -- check network connectivity" |
| 89 | + BOOT_REPO="$WORKDIR/mios-bootstrap" |
| 90 | +fi |
| 91 | +_log "mios-bootstrap repo: $BOOT_REPO" |
| 92 | + |
| 93 | +# ── Identity ───────────────────────────────────────────────────────────────── |
| 94 | +# /etc/mios/install.env is written by the Windows side BEFORE handoff |
| 95 | +# (Phase 7 in build-mios.ps1) so the prompts already happened on the |
| 96 | +# Windows side this round. Future migration chunks move the prompts |
| 97 | +# in here so the operator answers them in the MiOS-DEV terminal -- |
| 98 | +# NOT in Windows -- per the architecture memo. |
| 99 | +if [[ -f /etc/mios/install.env ]]; then |
| 100 | + _log "identity loaded from /etc/mios/install.env (written by Windows side)" |
| 101 | + # shellcheck disable=SC1091 |
| 102 | + source /etc/mios/install.env |
| 103 | +else |
| 104 | + _log "WARN: /etc/mios/install.env missing -- identity prompts not yet migrated to MiOS-DEV side" |
| 105 | + _log "WARN: build will use vendor defaults from usr/share/mios/env.defaults" |
| 106 | +fi |
| 107 | + |
| 108 | +# ── Build invocation ───────────────────────────────────────────────────────── |
| 109 | +# automation/build.sh expects to run inside a `podman build` against the |
| 110 | +# Containerfile. Outside that context it's a no-op driver entry. The |
| 111 | +# canonical way to drive the build from here is: |
| 112 | +# |
| 113 | +# cd <MIOS_REPO> && podman build -t localhost/mios:latest . |
| 114 | +# |
| 115 | +# The Containerfile then RUNs automation/build.sh with /ctx bind-mounted |
| 116 | +# at the repo root, which in turn exec's every automation/[0-9][0-9]-*.sh |
| 117 | +# step in order, masking secrets, capturing logs, etc. |
| 118 | +# |
| 119 | +# For now this driver is a SCAFFOLD. Subsequent migration chunks will |
| 120 | +# wire in: |
| 121 | +# * Multi-format output via bootc-image-builder (vhdx, qcow2, iso, raw) |
| 122 | +# * Identity-prompt migration from build-mios.ps1 Phase 6 |
| 123 | +# * Dashboard renderer matching the Windows-side ASCII-frame UI |
| 124 | +# * WSLg/Wayland verification for Epiphany SSOT-config editing |
| 125 | +_log "starting podman build at $MIOS_REPO" |
| 126 | +_log " podman build -t localhost/mios:latest -f Containerfile $MIOS_REPO" |
| 127 | + |
| 128 | +if cd "$MIOS_REPO" && podman build \ |
| 129 | + -t localhost/mios:latest \ |
| 130 | + -f Containerfile \ |
| 131 | + . 2>&1 | tee -a "$LOG_FILE"; then |
| 132 | + _log "podman build succeeded" |
| 133 | +else |
| 134 | + _fail "podman build failed -- see $LOG_FILE" |
| 135 | +fi |
| 136 | + |
| 137 | +_log "build-driver complete" |
| 138 | +echo |
| 139 | +echo " +-- MiOS build complete -----------------------------------+" |
| 140 | +echo " | OCI image: localhost/mios:latest |" |
| 141 | +echo " | Build log: $LOG_FILE" |
| 142 | +echo " | |" |
| 143 | +echo " | Next chunks will produce: WSL2/g .tar, Hyper-V .vhdx, |" |
| 144 | +echo " | QEMU qcow2, Live-CD/USB ISO, USB installer, RAW image. |" |
| 145 | +echo " +----------------------------------------------------------+" |
| 146 | +echo |
| 147 | +echo " Press Enter to close this terminal, or run \`bash\` to drop into a shell..." |
| 148 | +read -r _ || true |
0 commit comments