interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / run.sh
| 1 | #!/bin/sh |
| 2 | # run.sh: build and run forged (INTERPLANE Forge web) on spark. |
| 3 | # ./run.sh build compose the units and compile with the pinned omc -> server/forged |
| 4 | # (refused when `git status --porcelain` is non-empty: the live binary is built |
| 5 | # only from a commit; trial builds set FORGED_OUT to another path) |
| 6 | # ./run.sh deploy [commit] build <commit> (default HEAD) in a fresh git worktree, install it as |
| 7 | # server/forged (and nodes/snap.om, its own program, as server/nodes-snap) and |
| 8 | # append "<UTC> <commit> <sha256> nodes-snap <sha256>" to infra/DEPLOY.md; then |
| 9 | # `pkill -x forged` (the supervisor restarts it), `systemctl --user restart |
| 10 | # aien-nodes` (infra/spark/aien-nodes.service) and commit the DEPLOY.md line |
| 11 | # ./run.sh start|stop|status|reload the tmux service "forged" via infra/spark/forged-service.sh |
| 12 | # (ForgeInfra's supervisor: restart loop, cores 4-5 nice 10; reload = flag file |
| 13 | # ~/forge-data/reload, which forged polls between connections) |
| 14 | # ./run.sh restart build, then restart the service |
| 15 | # ./run.sh check-salvage run targeted native storage, sandbox, journey and collector checks |
| 16 | # ./run.sh check-patch run the git patch intake tests (patch/tests/run.sh: every refusal of |
| 17 | # docs/API.md with its accepted twin, guard mutants, the interplane patch tool) |
| 18 | # ./run.sh collector compile salvage/collector.om (its own program: the verifier that runs |
| 19 | # outside the server's namespace) -> server/salvage-collector (COLLECTOR_OUT) |
| 20 | # ./run.sh units print the unit list that build composes (makes .build/chrome.om when it is |
| 21 | # missing or FORGE_SITE_REF / FORGE_SITE_SRC is set, below) |
| 22 | # ./run.sh seams tests only: the same list in the same order with every slice as its seam |
| 23 | # server/no<slice>.om, whatever READY or FORGE_TRY say (social/tests/units.sh |
| 24 | # puts the slice under test in place of its seam); build never reads it. |
| 25 | # door/ is server/nodoor.om there. With FORGE_STORE the list keeps the store |
| 26 | # source (.build/store.om, store/repos.om, store/head.om, server/nostat.om) |
| 27 | # and names server/no<slice>.om, not store/mv<slice>.om or store/moving.om |
| 28 | # ./run.sh chrome make .build/chrome.om afresh and print its path |
| 29 | # ./run.sh agents make .build/agents.om (and .build/agents.tsv, the table it holds) from |
| 30 | # server/agents.tsv for the units of this build, and print the .om path |
| 31 | # Site chrome: the interplane.io header, footer and their stylesheet lines are generated by |
| 32 | # server/chromegen.om (seeded Omega) from content/_layout.html and public/style.css of the site's |
| 33 | # canonical main in local Radicle storage (rad:z399yKvnXcBQNkKoq86iBDgTvQ5QV refs/heads/main), afresh |
| 34 | # at every build, deploy and `./run.sh chrome`, so a site change reaches the forge at its next build |
| 35 | # with no hand copy. Between builds `units` reuses .build/chrome.om, so every test of one run composes |
| 36 | # the same chrome even while the site main moves. |
| 37 | # FORGE_SITE_REF=<commit> builds against one site commit (a rollback rebuild); FORGE_SITE_SRC=<dir> |
| 38 | # reads the two files from a checkout (tests). A build is the pair (forge commit, site commit): deploy |
| 39 | # writes both into infra/DEPLOY.md. A site layout the generator cannot read stops the build with its |
| 40 | # reason on stderr (server/chromegen.om lists them). |
| 41 | # A slice directory (browse dl collab social quiet) is composed only when it holds a READY file; |
| 42 | # otherwise its seam server/no<slice>.om is used. ForgeServer touches READY after integration. |
| 43 | # patch (the git patch intake) reads the store's repositories and social's sessions: it is composed |
| 44 | # only in a store-reading build (FORGE_STORE) with patch/READY and social composed, else |
| 45 | # server/nopatch.om. |
| 46 | # Trial build of unready slices: FORGE_TRY="dl collab" FORGED_OUT=/tmp/forged.try ./run.sh build |
| 47 | # Cores: FORGED_CPUS (taskset list, default 4,5) pins the build and the service; never 3, 7 or 15. |
| 48 | # Store-reading build (interplane-native DESIGN.md step 2): FORGE_STORE=<absolute store root>, with |
| 49 | # FORGED_OUT set (never server/forged), and optionally FORGE_CLONE_BASE=https://<host>/<path>/: |
| 50 | # FORGE_STORE=/path/to/store FORGED_OUT=/tmp/x/forged ./run.sh build |
| 51 | # composes .build/store.om, store/repos.om, store/head.om and store/clone.om in place of |
| 52 | # server/radsrc.om, nodes/head.om and dl/dlclone.om (the project list is the store's catalog.tsv; Git |
| 53 | # is read from projects/NAME/repo.git) and the seams of the slices that read Radicle-only data or need one that |
| 54 | # does: collab and quiet (server/no<slice>.om), growth, salvage, community and open (store/mv<slice>.om, |
| 55 | # which answer their addresses with the 503 "moving" page of store/moving.om in place of the 404 of |
| 56 | # server/no<slice>.om) and the research intake (research/noadd.om). Without FORGE_STORE every unit is |
| 57 | # the default and the old path stays. |
| 58 | # A store-reading build serves every public line of the catalog (less the deny list, server/repos.om |
| 59 | # fdeny), takes the site chrome from the store's interplane.io project (FORGE_SITE_STORE overrides), |
| 60 | # composes door/ with store/evcol.om, the collector that reads the store, in place of door/ev3col.om, |
| 61 | # and answers the addresses of salvage, community, open and trending with the store seams |
| 62 | # store/mv*.om: 503, "This part is moving to the new Interplane store and is not available yet." |
| 63 | # deploy and restart refuse FORGE_STORE: nothing here switches the live service. |
| 64 | set -eu |
| 65 | # unit order: `ls <slice>/*.om` must sort by byte (dl/dl.om before dl/dljson.om, whose code reads |
| 66 | # dl.om globals); under en_US collation the order flips and omc stops with error 3 |
| 67 | export LC_ALL=C |
| 68 | cd "$(dirname "$0")" |
| 69 | ROOT=$(pwd) |
| 70 | OMV=$HOME/work/flux/omega-mv |
| 71 | OMC=$OMV/seed/out/omc |
| 72 | PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194 |
| 73 | DATA=$HOME/forge-data |
| 74 | CORES=${FORGED_CPUS:-4,5} |
| 75 | for part in $(echo "$CORES" | tr ',' ' '); do |
| 76 | case $part in |
| 77 | *[!0-9-]* | '' | -* | *-) echo "run.sh: bad FORGED_CPUS '$CORES'" >&2; exit 2 ;; |
| 78 | esac |
| 79 | lo=${part%-*} hi=${part#*-} |
| 80 | for c in 3 7 15; do |
| 81 | if [ "$c" -ge "$lo" ] && [ "$c" -le "$hi" ]; then |
| 82 | echo "run.sh: FORGED_CPUS '$CORES' includes forbidden core $c" >&2 |
| 83 | exit 2 |
| 84 | fi |
| 85 | done |
| 86 | done |
| 87 | |
| 88 | SITE_RID=z399yKvnXcBQNkKoq86iBDgTvQ5QV |
| 89 | # seams: 1 only under the `seams` command (a command word, never an environment value) |
| 90 | seams=0 |
| 91 | # chromegen: (re)make $ROOT/.build/chrome.om from the site source; only diagnostics on stderr |
| 92 | chromegen() { |
| 93 | b=$ROOT/.build |
| 94 | mkdir -p "$b" |
| 95 | gen=$b/chromegen-$(cat "$OMC" server/chromegen.om | sha256sum | cut -c1-16) |
| 96 | if [ ! -x "$gen" ]; then |
| 97 | pinck |
| 98 | taskset -c "$CORES" nice -n 10 "$OMC" < server/chromegen.om > "$gen.$$" || { rm -f "$gen.$$"; echo "run.sh: server/chromegen.om did not compile" >&2; return 1; } |
| 99 | chmod 755 "$gen.$$" |
| 100 | mv "$gen.$$" "$gen" |
| 101 | fi |
| 102 | if [ -n "${FORGE_SITE_SRC:-}" ]; then |
| 103 | sha=$(git -C "$FORGE_SITE_SRC" rev-parse --verify HEAD^{commit} 2> /dev/null || echo 0000000000000000000000000000000000000000) |
| 104 | { cat "$FORGE_SITE_SRC/content/_layout.html"; printf '\0'; cat "$FORGE_SITE_SRC/public/style.css"; printf '\0'; echo "$sha"; } > "$b/site.$$" |
| 105 | else |
| 106 | if [ -n "${FORGE_STORE:-}" ]; then |
| 107 | s=${FORGE_SITE_STORE:-${FORGE_STORE%/}/projects/interplane.io/repo.git} |
| 108 | else |
| 109 | s=${FORGE_SITE_STORE:-$HOME/.radicle/storage/$SITE_RID} |
| 110 | fi |
| 111 | sha=$(git --git-dir="$s" rev-parse --verify "${FORGE_SITE_REF:-refs/heads/main}^{commit}") || { echo "run.sh: no site commit ${FORGE_SITE_REF:-refs/heads/main} in $s" >&2; return 1; } |
| 112 | { git --git-dir="$s" show "$sha:content/_layout.html"; printf '\0'; git --git-dir="$s" show "$sha:public/style.css"; printf '\0'; echo "$sha"; } > "$b/site.$$" |
| 113 | fi |
| 114 | if ! "$gen" < "$b/site.$$" > "$b/chrome.om.$$"; then |
| 115 | rm -f "$b/site.$$" "$b/chrome.om.$$" |
| 116 | echo "run.sh: the site chrome could not be generated from interplane.io $sha (reason above)" >&2 |
| 117 | return 1 |
| 118 | fi |
| 119 | rm -f "$b/site.$$" |
| 120 | mv "$b/chrome.om.$$" "$b/chrome.om" |
| 121 | } |
| 122 | |
| 123 | # composed SLICE: true when this list composes SLICE's own units, not its seam server/no<slice>.om: |
| 124 | # the slice holds a READY file or FORGE_TRY names it. Never in the seams list (`./run.sh seams`). |
| 125 | composed() { |
| 126 | [ "$seams" = 0 ] || return 1 |
| 127 | [ -f "$1/READY" ] && return 0 |
| 128 | case " ${FORGE_TRY:-} " in *" $1 "*) return 0 ;; esac |
| 129 | return 1 |
| 130 | } |
| 131 | # ready SLICE: SLICE holds a READY file (false in the seams list) |
| 132 | ready() { [ "$seams" = 0 ] && [ -f "$1/READY" ]; } |
| 133 | |
| 134 | # storegen: (re)make $ROOT/.build/store.om from FORGE_STORE and FORGE_CLONE_BASE: the store root |
| 135 | # (tfsroot, with a final "/"), FSCB (1 when a clone base is set) and the clone base (tfcbase, "-" when |
| 136 | # unset). Unfinished migration: shell glue beside chromegen; every decision about the store itself is |
| 137 | # made in Omega by store/repos.om. The byte rules keep the values plain text literals that need no |
| 138 | # escaping in Omega, HTML or JSON. |
| 139 | storegen() { |
| 140 | r=${FORGE_STORE%/}/ |
| 141 | case $r in |
| 142 | /*) ;; |
| 143 | *) echo "run.sh: FORGE_STORE must be an absolute path: '$FORGE_STORE'" >&2; return 1 ;; |
| 144 | esac |
| 145 | case $r in |
| 146 | *[!A-Za-z0-9._/+-]*) echo "run.sh: FORGE_STORE may hold only A-Z a-z 0-9 . _ / + -: '$FORGE_STORE'" >&2; return 1 ;; |
| 147 | esac |
| 148 | cb=${FORGE_CLONE_BASE:-} |
| 149 | f=0 |
| 150 | if [ -n "$cb" ]; then |
| 151 | case $cb in |
| 152 | https://?*/) ;; |
| 153 | *) echo "run.sh: FORGE_CLONE_BASE must start with https:// and end with /: '$cb'" >&2; return 1 ;; |
| 154 | esac |
| 155 | case $cb in |
| 156 | *[!A-Za-z0-9._/:+-]*) echo "run.sh: FORGE_CLONE_BASE may hold only A-Z a-z 0-9 . _ / : + -: '$cb'" >&2; return 1 ;; |
| 157 | esac |
| 158 | f=1 |
| 159 | else |
| 160 | cb=- |
| 161 | fi |
| 162 | mkdir -p "$ROOT/.build" |
| 163 | printf 'note .build/store.om: generated by run.sh storegen (store-reading build)\ntext tfsroot "%s"\nconst FSCB ulong %s\ntext tfcbase "%s"\n' "$r" "$f" "$cb" > "$ROOT/.build/store.om.$$" |
| 164 | mv "$ROOT/.build/store.om.$$" "$ROOT/.build/store.om" |
| 165 | } |
| 166 | |
| 167 | # stout SLICE: true when the store-reading build composes SLICE out through its seam |
| 168 | stout() { |
| 169 | [ -n "${FORGE_STORE:-}" ] || return 1 |
| 170 | case " collab quiet growth salvage community open " in *" $1 "*) return 0 ;; esac |
| 171 | return 1 |
| 172 | } |
| 173 | # mvseam SLICE: true when the store-reading build answers SLICE's addresses with its store seam |
| 174 | # store/mv<SLICE>.om (the 503 "moving" page). Never in the seams list, where every slice is |
| 175 | # server/no<slice>.om and store/moving.om is not listed. |
| 176 | mvseam() { [ "$seams" = 0 ] && stout "$1"; } |
| 177 | |
| 178 | # agentsgen UNITS: (re)make $ROOT/.build/agents.om from server/agents.tsv for the build whose unit list |
| 179 | # is UNITS: one text tfqatsv, tabs and newlines written as \t and \n, comment lines (#) left out; the |
| 180 | # same rows as plain TSV in $ROOT/.build/agents.tsv (what the tests read). The table's first column is |
| 181 | # the part that answers the row: forge (always composed), nodes (the node health snapshot of |
| 182 | # nodes/stat.om, composed when UNITS holds server/radsrc.om, the Radicle source: a store-reading |
| 183 | # build has no node), - (a not_available row as written), or a slice folder |
| 184 | # (composed when a unit of UNITS is in that folder). A row whose part this build does not compose |
| 185 | # becomes a not_available row ("none") naming the part, so agents.json lists only what answers. When |
| 186 | # UNITS holds store/mv<part>.om (the store build: growth, salvage, community, open), that part is |
| 187 | # moving to the new Interplane store: its rows say so, and say whether their address answers 503 |
| 188 | # (store/moving.om) or not; and not_available rows for salvage/ and community/ name those addresses. |
| 189 | # Refused with the reason on stderr, nothing written: a byte that is not printable ASCII or tab, a |
| 190 | # double quote or a backslash (they would end or change the text), or a row without 8 fields. |
| 191 | agentsgen() { |
| 192 | b=$ROOT/.build |
| 193 | mkdir -p "$b" |
| 194 | if grep -q "$(printf '[^ -~\t]')" server/agents.tsv || grep -q '["\\]' server/agents.tsv; then |
| 195 | echo "run.sh: server/agents.tsv holds a byte that is not printable ASCII or tab, a quote or a backslash" >&2 |
| 196 | return 1 |
| 197 | fi |
| 198 | parts=$(printf '%s\n' "$1" | awk -F/ '$0 == "server/radsrc.om" { print "nodes" } $0 == "collab/native/write.om" { print "issue-write" } NF > 1 && $1 !~ /^(server|nodes|store)$/ && $0 !~ /^\// { print $1 }' | sort -u | tr '\n' ' ') |
| 199 | mv=$(printf '%s\n' "$1" | sed -n 's|^store/mv\([a-z]*\)\.om$|\1|p' | sort -u | tr '\n' ' ') |
| 200 | if ! grep -v '^#' server/agents.tsv | awk -F '\t' -v OFS='\t' -v parts=" $parts " -v mv=" $mv " ' |
| 201 | NF != 8 { bad = 1; exit } |
| 202 | NR == 1 { $1 = ""; sub(/^\t/, ""); print; next } |
| 203 | $1 == "collab" && $3 ~ /\/patches(\/|$)/ && index(parts, " patch ") { next } |
| 204 | $1 == "patch" && !index(parts, " patch ") { next } |
| 205 | $1 == "-" || $1 == "forge" || index(parts, " " $1 " ") { $1 = ""; sub(/^\t/, ""); print; next } |
| 206 | index(mv, " " $1 " ") && $3 ~ /^((salvage|community|open)(\/.*)?|open\.json|trending(\.json)?|bring\.sh|get\.sh|withdraw\.sh)$/ { |
| 207 | print "none", $3, "-", "-", "-", $7, "not answered by this build: its " $1 " part is moving to the new Interplane store and is not available yet; the address answers 503 with that text (forge/error/1 with reason moving to a JSON request), no Retry-After"; next } |
| 208 | index(mv, " " $1 " ") { |
| 209 | print "none", $3, "-", "-", "-", $7, "not answered by this build: its " $1 " part is moving to the new Interplane store and is not available yet; this address answers 404, or without this schema"; next } |
| 210 | { print "none", $3, "-", "-", "-", $7, "not answered by this build: its " $1 " part is not composed (the address answers 404 or 501, or without this schema)" } |
| 211 | END { |
| 212 | if (bad) exit 1 |
| 213 | if (index(mv, " salvage ")) print "none", "salvage/", "-", "-", "-", "docs/AGENT-DOOR.md", "the Salvage Yard is moving to the new Interplane store and is not available yet; salvage/, and every address under it, answers 503 with that text (forge/error/1 with reason moving to a JSON request), no Retry-After" |
| 214 | if (index(mv, " community ")) print "none", "community/", "-", "-", "-", "docs/AGENT-DOOR.md", "Community Machines are moving to the new Interplane store and are not available yet; community/, and every address under it, answers 503 with that text (forge/error/1 with reason moving to a JSON request), no Retry-After" |
| 215 | }' > "$b/agents.tsv.$$"; then |
| 216 | rm -f "$b/agents.tsv.$$" |
| 217 | echo "run.sh: server/agents.tsv has a row without 8 tab-separated fields" >&2 |
| 218 | return 1 |
| 219 | fi |
| 220 | { |
| 221 | printf 'note generated by run.sh from server/agents.tsv at every build; edit the table, not this file\ntext tfqatsv "' |
| 222 | sed 's/\t/\\t/g' "$b/agents.tsv.$$" | awk '{printf "%s\\n", $0}' |
| 223 | printf '"\n' |
| 224 | } > "$b/agents.om.$$" |
| 225 | mv "$b/agents.tsv.$$" "$b/agents.tsv" |
| 226 | mv "$b/agents.om.$$" "$b/agents.om" |
| 227 | } |
| 228 | |
| 229 | # units: the unit list; agentsgen reads it (the parts it composes) and fills the AGENTS slot |
| 230 | units() { |
| 231 | u=$(units_core) |
| 232 | if agentsgen "$u"; then |
| 233 | a=$ROOT/.build/agents.om |
| 234 | else |
| 235 | a=$ROOT/.build/AGENTS-NOT-GENERATED-see-stderr |
| 236 | fi |
| 237 | printf '%s\n' "$u" | awk -v a="$a" '$0 == "@AGENTS@" { print a; next } { print }' |
| 238 | } |
| 239 | |
| 240 | # units: a failed generation lists a path that does not exist, so a caller's cat and omc fail loudly |
| 241 | units_core() { |
| 242 | if [ ! -s "$ROOT/.build/chrome.om" ] || [ -n "${FORGE_SITE_REF:-}${FORGE_SITE_SRC:-}" ]; then |
| 243 | if ! chromegen; then |
| 244 | echo "$ROOT/.build/CHROME-NOT-GENERATED-see-stderr" |
| 245 | fi |
| 246 | fi |
| 247 | echo "$OMV/seed/net/http.om" |
| 248 | echo "$OMV/seed/net/notls.om" |
| 249 | echo "$OMV/om/tls/sha2.om" |
| 250 | echo "server/util.om" |
| 251 | echo "$ROOT/.build/chrome.om" |
| 252 | echo "server/repos.om" |
| 253 | if [ -n "${FORGE_STORE:-}" ]; then |
| 254 | if storegen; then |
| 255 | echo "$ROOT/.build/store.om" |
| 256 | else |
| 257 | echo "$ROOT/.build/STORE-NOT-GENERATED-see-stderr" |
| 258 | fi |
| 259 | echo "store/repos.om" |
| 260 | echo "store/head.om" |
| 261 | else |
| 262 | echo "server/radsrc.om" |
| 263 | echo "nodes/head.om" |
| 264 | fi |
| 265 | for s in browse dl collab social quiet; do |
| 266 | if [ "$s" = collab ] && [ -n "${FORGE_STORE:-}" ] && composed collab && composed browse; then |
| 267 | echo collab/co0form.om |
| 268 | ls collab/native/*.om | grep -v "^collab/native/write.om$" |
| 269 | elif ! stout "$s" && composed "$s"; then |
| 270 | if [ "$s" = dl ] && [ -n "${FORGE_STORE:-}" ]; then |
| 271 | ls dl/*.om | grep -v '^dl/dlclone\.om$' |
| 272 | echo "store/clone.om" |
| 273 | else |
| 274 | ls "$s"/*.om |
| 275 | fi |
| 276 | else |
| 277 | echo "server/no$s.om" |
| 278 | fi |
| 279 | done |
| 280 | if [ -n "${FORGE_STORE:-}" ] && composed collab && composed browse; then |
| 281 | if composed social; then echo collab/native/write.om; else echo server/noissuewrite.om; fi |
| 282 | fi |
| 283 | # the git patch intake (patch/, docs/API.md "Git patches") reads the store's repositories |
| 284 | # (projects/NAME/repo.git) and social's sessions: composed only in a store-reading build, when |
| 285 | # patch and social are composed; every other build keeps the seam server/nopatch.om |
| 286 | if [ -n "${FORGE_STORE:-}" ] && composed patch && composed social && composed browse; then |
| 287 | ls patch/*.om |
| 288 | else |
| 289 | echo "server/nopatch.om" |
| 290 | fi |
| 291 | # the node health pages read the Radicle node's snapshot; the store-reading build has no node |
| 292 | if [ -n "${FORGE_STORE:-}" ]; then |
| 293 | echo "server/nostat.om" |
| 294 | else |
| 295 | echo "nodes/stat.om" |
| 296 | fi |
| 297 | echo "server/json.om" |
| 298 | echo "server/counts.om" |
| 299 | echo "server/count-snapshot.om" |
| 300 | # the store build answers the addresses of the parts it composes out with one 503 (store/moving.om) |
| 301 | if [ -n "${FORGE_STORE:-}" ] && [ "$seams" = 0 ]; then |
| 302 | echo "store/moving.om" |
| 303 | fi |
| 304 | if ! stout growth && composed growth; then |
| 305 | ls growth/*.om |
| 306 | elif mvseam growth; then |
| 307 | echo "store/mvgrowth.om" |
| 308 | else |
| 309 | echo "server/nogrowth.om" |
| 310 | fi |
| 311 | if ! stout salvage && composed salvage; then |
| 312 | ls salvage/[0-9][0-9]*.om |
| 313 | elif mvseam salvage; then |
| 314 | echo "store/mvsalvage.om" |
| 315 | else |
| 316 | echo "server/nosalvage.om" |
| 317 | fi |
| 318 | case " ${FORGE_TRY:-} " in *" community "*) try=1 ;; *) try=0 ;; esac |
| 319 | if ! stout community && { { ready community && ready salvage; } || { [ "$seams" = 0 ] && [ "$try" = 1 ]; }; }; then |
| 320 | echo "$OMV/om/tls/ec.om" |
| 321 | ls community/[0-9][0-9]*.om |
| 322 | elif mvseam community; then |
| 323 | echo "store/mvcommunity.om" |
| 324 | else |
| 325 | echo "server/nocommunity.om" |
| 326 | fi |
| 327 | case " ${FORGE_TRY:-} " in *" open "*) try=1 ;; *) try=0 ;; esac |
| 328 | if ! stout open && { { ready open && ready salvage; } || { [ "$seams" = 0 ] && [ "$try" = 1 ]; }; }; then |
| 329 | echo "open/route.om" |
| 330 | elif mvseam open; then |
| 331 | echo "store/mvopen.om" |
| 332 | else |
| 333 | echo "server/noopen.om" |
| 334 | fi |
| 335 | if composed research; then |
| 336 | echo "research/route.om" |
| 337 | if ! stout open && ready open && ready salvage; then |
| 338 | echo "research/intake-route.om" |
| 339 | else |
| 340 | echo "research/noadd.om" |
| 341 | fi |
| 342 | else |
| 343 | echo "server/noresearch.om" |
| 344 | fi |
| 345 | # door/ (the event stream and the feed, docs/AGENT-DOOR.md): with Radicle storage it reads collab's |
| 346 | # COB model and social's log (door/ev3col.om), so it needs both composed, else the seam |
| 347 | # server/nodoor.om answers 501; a store-reading build reads the store and social's log |
| 348 | # (store/evcol.om in place of door/ev3col.om) and needs social only |
| 349 | case " ${FORGE_TRY:-} " in *" door "*) try=1 ;; *) try=0 ;; esac |
| 350 | if [ -n "${FORGE_STORE:-}" ] && { { ready door && ready social; } || { [ "$seams" = 0 ] && [ "$try" = 1 ]; }; }; then |
| 351 | ls door/*.om | sed 's|^door/ev3col\.om$|store/evcol.om|' |
| 352 | elif { ready door && ready collab && ready social; } || { [ "$seams" = 0 ] && [ "$try" = 1 ]; }; then |
| 353 | ls door/*.om |
| 354 | else |
| 355 | echo "server/nodoor.om" |
| 356 | fi |
| 357 | echo "@AGENTS@" |
| 358 | echo "server/agents.om" |
| 359 | echo "server/state.om" |
| 360 | echo "server/pages.om" |
| 361 | echo "nodes/srch.om" |
| 362 | echo "server/jsonp.om" |
| 363 | echo "server/route.om" |
| 364 | echo "server/main.om" |
| 365 | echo "server/tr.om" |
| 366 | } |
| 367 | |
| 368 | pinck() { |
| 369 | got=$(sha256sum "$OMC" | cut -d' ' -f1) |
| 370 | if [ "$got" != "$PIN" ]; then |
| 371 | echo "run.sh: omc sha256 $got is not the pin $PIN" >&2 |
| 372 | exit 1 |
| 373 | fi |
| 374 | } |
| 375 | |
| 376 | compile() { # compile OUT: compose the units of the current directory, compile, install OUT atomically |
| 377 | pinck |
| 378 | chromegen || exit 1 |
| 379 | tmp=$1.new |
| 380 | # build-commit stamp (collab/co4pat.om `text tcbldc`): only when every repo unit is clean, so a |
| 381 | # dirty trial build stays "unrecorded" and never names a wrong commit |
| 382 | st='s/^x$/x/' |
| 383 | # shellcheck disable=SC2046 |
| 384 | if c=$(git rev-parse HEAD 2> /dev/null) && [ -z "$(git status --porcelain -- $(units | grep -v '^/') server/agents.tsv)" ]; then |
| 385 | st="s/^text tcbldc \"unrecorded\"\$/text tcbldc \"$c\"/" |
| 386 | fi |
| 387 | # shellcheck disable=SC2046 |
| 388 | { printf 'om2\n'; cat $(units); } | sed -e "$st" | taskset -c "$CORES" nice -n 10 "$OMC" > "$tmp" |
| 389 | chmod 755 "$tmp" |
| 390 | mv "$tmp" "$1" |
| 391 | } |
| 392 | |
| 393 | snapc() { # snapc OUT: compile nodes/snap.om (the node snapshot writer; its own program), install OUT atomically |
| 394 | pinck |
| 395 | if ! taskset -c "$CORES" nice -n 10 "$OMC" < nodes/snap.om > "$1.new"; then |
| 396 | rm -f "$1.new" |
| 397 | echo "run.sh: nodes/snap.om did not compile" >&2 |
| 398 | exit 1 |
| 399 | fi |
| 400 | chmod 755 "$1.new" |
| 401 | mv "$1.new" "$1" |
| 402 | } |
| 403 | |
| 404 | publicc() { # Trusted supervisor reader, built with the same pinned compiler. |
| 405 | helperc infra/spark/public-read.om "$1" |
| 406 | } |
| 407 | |
| 408 | listenc() { # Trusted supervisor listener helper (the sandboxed forged has no network of its own). |
| 409 | helperc infra/spark/forged-listen.om "$1" |
| 410 | } |
| 411 | |
| 412 | seccompc() { # seccompc OUT: build the sandbox socket filter generator and write its program to OUT |
| 413 | helperc infra/spark/forged-seccomp.om "$1.gen" |
| 414 | if ! "$1.gen" > "$1.new"; then |
| 415 | rm -f "$1.gen" "$1.new" |
| 416 | echo "run.sh: forged-seccomp did not write the filter" >&2 |
| 417 | exit 1 |
| 418 | fi |
| 419 | rm -f "$1.gen" |
| 420 | chmod 644 "$1.new" |
| 421 | mv "$1.new" "$1" |
| 422 | } |
| 423 | |
| 424 | helperc() { # helperc SRC OUT: compile a supervisor helper, install OUT atomically |
| 425 | pinck |
| 426 | if ! taskset -c "$CORES" nice -n 10 "$OMC" < "$1" > "$2.new"; then |
| 427 | rm -f "$2.new" |
| 428 | echo "run.sh: $1 did not compile" >&2 |
| 429 | exit 1 |
| 430 | fi |
| 431 | chmod 755 "$2.new" |
| 432 | mv "$2.new" "$2" |
| 433 | } |
| 434 | |
| 435 | build() { |
| 436 | out=${FORGED_OUT:-server/forged} |
| 437 | if [ -n "${FORGE_STORE:-}" ] && [ -z "${FORGED_OUT:-}" ]; then |
| 438 | echo "run.sh: a store-reading build needs FORGED_OUT (it never writes server/forged)" >&2 |
| 439 | exit 1 |
| 440 | fi |
| 441 | if [ "$(realpath -m "$out")" = "$ROOT/server/forged" ] && [ -n "$(git status --porcelain)" ]; then |
| 442 | echo "run.sh: working tree is not clean; the live binary is built only from a commit (./run.sh deploy)" >&2 |
| 443 | exit 1 |
| 444 | fi |
| 445 | if [ "$(realpath -m "$out")" = "$ROOT/server/forged" ] && [ -n "${FORGE_STORE:-}" ]; then |
| 446 | echo "run.sh: a store-reading build never writes server/forged" >&2 |
| 447 | exit 1 |
| 448 | fi |
| 449 | compile "$out" |
| 450 | publicc "$(dirname "$out")/public-read" |
| 451 | listenc "$(dirname "$out")/forged-listen" |
| 452 | seccompc "$(dirname "$out")/forged-seccomp.bpf" |
| 453 | echo "built $out $(sha256sum "$out" | cut -d' ' -f1)" |
| 454 | } |
| 455 | |
| 456 | checks() { |
| 457 | got=$(sha256sum "$OMC" | cut -d' ' -f1) |
| 458 | [ "$got" = "$PIN" ] || { echo "compiler pin mismatch" >&2; exit 1; } |
| 459 | testdir=$(mktemp -d /tmp/forge-salvage-check.XXXXXX) |
| 460 | trap 'rm -rf "$testdir"' EXIT HUP INT TERM |
| 461 | for test in store limits verify journey; do |
| 462 | if [ "$test" = journey ]; then |
| 463 | { printf 'om2\n'; cat $(units); } | sed 's/^fn main to int$/fn fmainx to int/' > "$testdir/test.om" |
| 464 | else |
| 465 | { printf 'om2\n'; cat "$OMV/om/tls/sha2.om" salvage/00core.om; } > "$testdir/test.om" |
| 466 | [ "$test" != verify ] || cat salvage/10verify.om >> "$testdir/test.om" |
| 467 | fi |
| 468 | cat "salvage/tests/$test.om" >> "$testdir/test.om" |
| 469 | taskset -c "$CORES" nice -n 10 "$OMC" < "$testdir/test.om" > "$testdir/test" |
| 470 | chmod 700 "$testdir/test" |
| 471 | mkdir -m 700 "$testdir/$test" |
| 472 | OMEGA_COMPILER="$OMC" taskset -c "$CORES" "$testdir/test" "$testdir/$test/" |
| 473 | done |
| 474 | # the collector program itself (salvage/collector.om), run against the store the journey left |
| 475 | collc "$testdir/collector" |
| 476 | s="$testdir/journey/" |
| 477 | cfail() { echo "SALVAGE_COLLECTOR FAIL: $*" >&2; exit 1; } |
| 478 | crun() { rc=0; taskset -c "$CORES" env -i "$@" "$testdir/collector" once || rc=$?; } |
| 479 | rbyte() { od -An -tu1 -j64 -N1 "$1" | tr -d ' '; } |
| 480 | w="$testdir/cwork/" |
| 481 | crun; [ "$rc" = 1 ] || cfail "no store configured: want exit 1, got $rc" |
| 482 | crun INTERPLANE_SALVAGE_DIR="$s" OMEGA_COMPILER="$OMC" |
| 483 | [ "$rc" = 1 ] || cfail "no scratch folder configured: want exit 1, got $rc" |
| 484 | crun INTERPLANE_SALVAGE_DIR="$s" INTERPLANE_SALVAGE_WORK="${s}work/" OMEGA_COMPILER="$OMC" |
| 485 | [ "$rc" = 1 ] || cfail "scratch folder inside the store: want exit 1, got $rc" |
| 486 | mkdir -m 700 "$testdir/empty" |
| 487 | crun INTERPLANE_SALVAGE_DIR="$testdir/empty/" INTERPLANE_SALVAGE_WORK="$w" OMEGA_COMPILER="$OMC" |
| 488 | [ "$rc" = 3 ] || cfail "store without a key: want exit 3, got $rc" |
| 489 | [ ! -e "$testdir/empty/collector.key" ] || cfail "the collector created a key" |
| 490 | crun INTERPLANE_SALVAGE_DIR="$s" INTERPLANE_SALVAGE_WORK="$w" OMEGA_COMPILER="$OMC" |
| 491 | [ "$rc" = 0 ] || cfail "nothing queued: want exit 0, got $rc" |
| 492 | printf 'not-a-record-id' > "${s}job" |
| 493 | crun INTERPLANE_SALVAGE_DIR="$s" INTERPLANE_SALVAGE_WORK="$w" OMEGA_COMPILER="$OMC" |
| 494 | [ "$rc" = 2 ] && [ ! -e "${s}job" ] || cfail "damaged job: want exit 2 and the file removed, got $rc" |
| 495 | part= |
| 496 | for f in "${s}receipts/"*; do |
| 497 | [ "$(rbyte "$f")" = 1 ] && part=$(basename "$f") && break |
| 498 | done |
| 499 | [ -n "$part" ] || cfail "the journey left no passing receipt to replay" |
| 500 | # negative control: a compiler that is not the pin must give a refusal receipt, never a pass |
| 501 | rm -f "${s}receipts/$part" |
| 502 | (umask 077 && printf '%s' "$part" > "${s}job") |
| 503 | crun INTERPLANE_SALVAGE_DIR="$s" INTERPLANE_SALVAGE_WORK="$w" OMEGA_COMPILER=/usr/bin/true |
| 504 | [ "$rc" = 1 ] && [ ! -e "${s}job" ] || cfail "wrong compiler: want exit 1 and the job removed, got $rc" |
| 505 | [ "$(rbyte "${s}receipts/$part")" = 2 ] || cfail "wrong compiler: the receipt is not a refusal" |
| 506 | rm -f "${s}receipts/$part" |
| 507 | (umask 077 && printf '%s' "$part" > "${s}job") |
| 508 | crun INTERPLANE_SALVAGE_DIR="$s" INTERPLANE_SALVAGE_WORK="$w" OMEGA_COMPILER="$OMC" |
| 509 | [ "$rc" = 1 ] && [ ! -e "${s}job" ] || cfail "queued job: want exit 1 and the job removed, got $rc" |
| 510 | [ "$(rbyte "${s}receipts/$part")" = 1 ] || cfail "queued job: the receipt is not a pass" |
| 511 | [ "$(wc -c < "${s}receipts/$part")" = 353 ] || cfail "queued job: the receipt is not 353 bytes" |
| 512 | [ -z "$(ls -A "$w")" ] || cfail "scratch files were left behind in $w" |
| 513 | [ ! -e "${s}work/omc" ] || cfail "the collector used the scratch folder inside the store" |
| 514 | echo "SALVAGE_COLLECTOR PASS 10 (no store, no scratch folder, scratch inside the store refused, no key and none created, idle, damaged job removed, wrong compiler refused, queued job receipted, job removed, scratch outside the store and left empty)" |
| 515 | } |
| 516 | |
| 517 | collc() { # collc OUT: compile the salvage collector (salvage/collector.om; its own program), install OUT atomically |
| 518 | pinck |
| 519 | if ! { printf 'om2\n'; cat "$OMV/om/tls/sha2.om" salvage/00core.om salvage/10verify.om salvage/collector.om; } \ |
| 520 | | taskset -c "$CORES" nice -n 10 "$OMC" > "$1.new"; then |
| 521 | rm -f "$1.new" |
| 522 | echo "run.sh: salvage/collector.om did not compile" >&2 |
| 523 | exit 1 |
| 524 | fi |
| 525 | chmod 755 "$1.new" |
| 526 | mv "$1.new" "$1" |
| 527 | } |
| 528 | |
| 529 | intakec() { # intakec OUT: compile the open-builds intake (open/intake.om; its own program), install OUT atomically |
| 530 | pinck |
| 531 | if ! { printf 'om2\n'; cat "$OMV/om/tls/sha2.om" open/intake.om; } | taskset -c "$CORES" nice -n 10 "$OMC" > "$1.new"; then |
| 532 | rm -f "$1.new" |
| 533 | echo "run.sh: open/intake.om did not compile" >&2 |
| 534 | exit 1 |
| 535 | fi |
| 536 | chmod 755 "$1.new" |
| 537 | mv "$1.new" "$1" |
| 538 | } |
| 539 | |
| 540 | deploy() { |
| 541 | commit=$(git rev-parse --verify "${1:-HEAD}^{commit}") |
| 542 | wt=$(mktemp -d /tmp/forged-deploy.XXXXXX) |
| 543 | git worktree add --detach "$wt" "$commit" > /dev/null |
| 544 | # a failed compile exits through set -e: remove the scratch worktree on that path too |
| 545 | trap 'git -C "$ROOT" worktree remove --force "$wt" 2> /dev/null || true' EXIT |
| 546 | if [ -n "$(git -C "$wt" status --porcelain)" ]; then |
| 547 | git worktree remove --force "$wt" |
| 548 | echo "run.sh: worktree of $commit is not clean" >&2 |
| 549 | exit 1 |
| 550 | fi |
| 551 | # one subshell per program: each function ends its && list, so set -e stops on a failed compile |
| 552 | (cd "$wt" && compile "$wt/forged") |
| 553 | (cd "$wt" && snapc "$wt/nodes-snap") |
| 554 | (cd "$wt" && publicc "$wt/public-read") |
| 555 | (cd "$wt" && listenc "$wt/forged-listen") |
| 556 | (cd "$wt" && seccompc "$wt/forged-seccomp.bpf") |
| 557 | site=$(sed -n 's/^text tchrsite "\([0-9a-f]*\)"$/\1/p' "$wt/.build/chrome.om") |
| 558 | mv "$wt/forged" "$ROOT/server/forged.new" |
| 559 | mv "$wt/nodes-snap" "$ROOT/server/nodes-snap.new" |
| 560 | mv "$wt/public-read" "$ROOT/server/public-read.new" |
| 561 | mv "$wt/forged-listen" "$ROOT/server/forged-listen.new" |
| 562 | mv "$wt/forged-seccomp.bpf" "$ROOT/server/forged-seccomp.bpf.new" |
| 563 | git worktree remove --force "$wt" |
| 564 | mv "$ROOT/server/forged.new" "$ROOT/server/forged" |
| 565 | mv "$ROOT/server/nodes-snap.new" "$ROOT/server/nodes-snap" |
| 566 | mv "$ROOT/server/public-read.new" "$ROOT/server/public-read" |
| 567 | mv "$ROOT/server/forged-listen.new" "$ROOT/server/forged-listen" |
| 568 | mv "$ROOT/server/forged-seccomp.bpf.new" "$ROOT/server/forged-seccomp.bpf" |
| 569 | sha=$(sha256sum "$ROOT/server/forged" | cut -d' ' -f1) |
| 570 | ssha=$(sha256sum "$ROOT/server/nodes-snap" | cut -d' ' -f1) |
| 571 | psha=$(sha256sum "$ROOT/server/public-read" | cut -d' ' -f1) |
| 572 | lsha=$(sha256sum "$ROOT/server/forged-listen" | cut -d' ' -f1) |
| 573 | fsha=$(sha256sum "$ROOT/server/forged-seccomp.bpf" | cut -d' ' -f1) |
| 574 | line="$(date -u +%Y-%m-%dT%H:%MZ) $commit $sha nodes-snap $ssha public-read $psha forged-listen $lsha forged-seccomp.bpf $fsha site $site" |
| 575 | printf -- '- %s\n' "$line" >> "$ROOT/infra/DEPLOY.md" |
| 576 | echo "deployed $line (restart: pkill -x forged; systemctl --user restart aien-nodes; then commit infra/DEPLOY.md)" |
| 577 | } |
| 578 | |
| 579 | svc() { |
| 580 | FORGE_DATA=$DATA FORGED_CPUS=$CORES bash "$ROOT/infra/spark/forged-service.sh" "$@" |
| 581 | } |
| 582 | |
| 583 | case "${1:-}" in |
| 584 | units) units ;; |
| 585 | seams) |
| 586 | seams=1 |
| 587 | units |
| 588 | ;; |
| 589 | chrome) |
| 590 | chromegen |
| 591 | echo "$ROOT/.build/chrome.om" |
| 592 | ;; |
| 593 | agents) |
| 594 | units > /dev/null |
| 595 | echo "$ROOT/.build/agents.om" |
| 596 | ;; |
| 597 | build) build ;; |
| 598 | check-salvage) checks ;; |
| 599 | collector) |
| 600 | out=${COLLECTOR_OUT:-server/salvage-collector} |
| 601 | collc "$out" |
| 602 | echo "built $out $(sha256sum "$out" | cut -d' ' -f1)" |
| 603 | ;; |
| 604 | intake) |
| 605 | out=${INTAKE_OUT:-server/open-intake} |
| 606 | intakec "$out" |
| 607 | echo "built $out $(sha256sum "$out" | cut -d' ' -f1)" |
| 608 | ;; |
| 609 | check-open) sh open/tests/run.sh ;; |
| 610 | check-open-up) bash open/tests/up.sh ;; |
| 611 | check-patch) bash patch/tests/run.sh && bash patch/tests/resilience.sh ;; |
| 612 | check-issues) bash collab/tests/native-issues-store.sh ;; |
| 613 | deploy) |
| 614 | if [ -n "${FORGE_STORE:-}" ]; then |
| 615 | echo "run.sh: deploy refuses FORGE_STORE: the store-reading build is not deployed by this script" >&2 |
| 616 | exit 1 |
| 617 | fi |
| 618 | deploy "${2:-}" |
| 619 | ;; |
| 620 | start) svc start ;; |
| 621 | stop) svc stop ;; |
| 622 | reload) svc reload ;; |
| 623 | status) svc status ;; |
| 624 | restart) |
| 625 | if [ -n "${FORGE_STORE:-}" ]; then |
| 626 | echo "run.sh: restart refuses FORGE_STORE: nothing here switches the live service" >&2 |
| 627 | exit 1 |
| 628 | fi |
| 629 | "$0" build |
| 630 | svc restart |
| 631 | ;; |
| 632 | *) |
| 633 | sed -n '2,10p' "$0" |
| 634 | exit 2 |
| 635 | ;; |
| 636 | esac |