aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / om / hive-page / check.sh
| 1 | #!/bin/sh |
| 2 | # Regenerate the Hive skeleton and browser scripts using the pinned arm64 omc. |
| 3 | # CI on x86_64 checks the committed artifacts against their recorded hashes; |
| 4 | # Pages also runs the skeleton digest test before deployment. |
| 5 | # OMEGA_OMC overrides the compiler path, never its pin. |
| 6 | # OMEGA_ACCEPT_CHANGE=1 accepts rewritten artifacts; otherwise stale output exits 4. |
| 7 | # Exit 2: missing compiler; 3: wrong pin; 4: stale artifact rewritten; |
| 8 | # 5: nondeterministic output; 6: empty output. Compile/run failures propagate. |
| 9 | set -eu |
| 10 | cd "$(dirname "$0")" |
| 11 | omc=${OMEGA_OMC:-$PWD/omc} |
| 12 | pin=$(tr -d ' \n' < omc.sha256) |
| 13 | if [ ! -f "$omc" ]; then |
| 14 | printf 'No compiler at %s; set OMEGA_OMC to the pinned omc (%s)\n' "$omc" "$pin" >&2 |
| 15 | exit 2 |
| 16 | fi |
| 17 | have=$(sha256sum "$omc" | cut -d' ' -f1) |
| 18 | if [ "$have" != "$pin" ]; then |
| 19 | printf 'Compiler sha256 mismatch: recorded %s, found %s\n' "$pin" "$have" >&2 |
| 20 | exit 3 |
| 21 | fi |
| 22 | irwasm=${OMEGA_IRWASM:-$PWD/irwasm} |
| 23 | irpin=$(tr -d ' \n' < irwasm.sha256) |
| 24 | if [ ! -f "$irwasm" ]; then |
| 25 | printf 'No IR wasm backend at %s; expected %s\n' "$irwasm" "$irpin" >&2 |
| 26 | exit 2 |
| 27 | fi |
| 28 | irhave=$(sha256sum "$irwasm" | cut -d' ' -f1) |
| 29 | if [ "$irhave" != "$irpin" ]; then |
| 30 | printf 'IR wasm backend sha256 mismatch: recorded %s, found %s\n' "$irpin" "$irhave" >&2 |
| 31 | exit 3 |
| 32 | fi |
| 33 | work=$(mktemp -d "${TMPDIR:-/tmp}/hive-page.XXXXXX") |
| 34 | trap 'rm -rf "$work"' EXIT HUP INT TERM |
| 35 | # One executable shares the contract between markup (fd 1) and hydrator (fd 3). |
| 36 | # Concatenation composes Omega units; it does not implement generation in shell. |
| 37 | cat contract.om freshness-js.om hive.om hive-js.om > "$work/hive.om" |
| 38 | "$omc" < "$work/hive.om" > "$work/hive" |
| 39 | "$omc" < turing-look.om > "$work/turing" |
| 40 | chmod +x "$work/hive" "$work/turing" |
| 41 | "$work/hive" > "$work/first.html" 3> "$work/first.hive.js" |
| 42 | "$work/hive" > "$work/second.html" 3> "$work/second.hive.js" |
| 43 | "$work/turing" > "$work/first.turing.js" |
| 44 | "$work/turing" > "$work/second.turing.js" |
| 45 | { printf 'ir\n'; cat fresh.om; } > "$work/fresh.ir.om" |
| 46 | "$omc" < "$work/fresh.ir.om" > "$work/fresh.ir" |
| 47 | "$irwasm" < "$work/fresh.ir" > "$work/first.fresh.wasm" |
| 48 | "$irwasm" < "$work/fresh.ir" > "$work/second.fresh.wasm" |
| 49 | stale=0 |
| 50 | publish() { |
| 51 | first=$1 |
| 52 | second=$2 |
| 53 | artifact=$3 |
| 54 | sidecar=$4 |
| 55 | if ! cmp -s "$first" "$second"; then |
| 56 | printf '%s: generator output differs between runs\n' "$artifact" >&2 |
| 57 | exit 5 |
| 58 | fi |
| 59 | if [ ! -s "$first" ]; then |
| 60 | printf '%s: generator wrote nothing\n' "$artifact" >&2 |
| 61 | exit 6 |
| 62 | fi |
| 63 | if [ ! -f "$artifact" ] || ! cmp -s "$artifact" "$first"; then |
| 64 | stale=1 |
| 65 | fi |
| 66 | cp "$first" "$artifact" |
| 67 | hash=$(sha256sum "$artifact" | cut -d' ' -f1) |
| 68 | printf '%s %s\n' "$hash" "$artifact" > "$sidecar" |
| 69 | printf '%s %s bytes sha256 %s\n' "$artifact" "$(wc -c < "$artifact" | tr -d ' ')" "$hash" |
| 70 | } |
| 71 | publish "$work/first.html" "$work/second.html" main.html main.html.sha256 |
| 72 | publish "$work/first.hive.js" "$work/second.hive.js" ../../public/js/hive.js hive.js.sha256 |
| 73 | publish "$work/first.turing.js" "$work/second.turing.js" ../../public/js/turing-look.js turing-look.js.sha256 |
| 74 | mkdir -p ../../public/wasm |
| 75 | publish "$work/first.fresh.wasm" "$work/second.fresh.wasm" ../../public/wasm/hive-fresh.wasm ../../public/wasm/hive-fresh.wasm.sha256 |
| 76 | printf 'irwasm sha256 %s\n' "$irhave" |
| 77 | printf 'omc sha256 %s\n' "$have" |
| 78 | if [ "$stale" = 1 ]; then |
| 79 | printf 'Generated artifacts were rewritten; commit them with their Omega sources\n' >&2 |
| 80 | if [ "${OMEGA_ACCEPT_CHANGE:-0}" != 1 ]; then |
| 81 | exit 4 |
| 82 | fi |
| 83 | fi |