Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/ipl/tools/receipt.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / ipl / tools / receipt.sh` 103 lines ยท 8892 bytes Raw Blame History 1 #!/bin/bash 2 # receipt.sh OMC SHA2_OM CHAIN_OM SNAPSHOT_OM WRONG_OMC TRIAL_ROOT OUT_DIR [EXPECTED_REFUSED ...] 3 # Run from a clean clone of the exact head. Builds, runs the gate and its wrong-compiler control, 4 # makes a trial signing key, imports the old store into TRIAL_ROOT, re-derives the catalog from full 5 # verification (with IPL_OWNER_PINS set to OUT_DIR/owner-pins, outside the trial store), compares 6 # every head with the old store on its own, accounts for every project of 7 # the old store that this node signed, and writes OUT_DIR/READY.json from what it measured. Nothing 8 # in READY.json is typed. The live forge catalog path uses ~/.config/interplane/owner-pins, installed 9 # by hand from the owner key's .pub; this script does not write that file. 10 # TRIAL_ROOT and OUT_DIR must not exist: a receipt is written once and never over another. 11 # EXPECTED_REFUSED names the projects whoever runs this expects the import to refuse. That is the 12 # runner's expectation, written into the receipt as such; it is nobody's decision about a project. 13 # Any other refusal, or an expected one that did not happen, fails the receipt. 14 # Exit 0 only when every step did what READY.json says it should and READY.json was written. 15 set -u 16 cd "$(dirname "$0")/.." || exit 2 17 [ $# -ge 7 ] || { sed -n '2,10s/^# \{0,1\}//p' "$0" >&2; exit 2; } 18 omc=$1 sha2=$2 chainom=$3 snapom=$4 wrong=$5 root=$6 out=$7; shift 7 19 invocation=$(printf ' %q' "$0" "$omc" "$sha2" "$chainom" "$snapom" "$wrong" "$root" "$out" "$@") 20 expected=$(printf '%s\n' "$@" | grep . | sort) 21 # the control needs a real other compiler: a missing file would also be refused, and prove nothing 22 [ -x "$wrong" ] && [ "$(sha256sum "$wrong" | cut -d' ' -f1)" != "$(sed -n 's/^omc-sha256 //p' PIN)" ] || { echo "receipt: WRONG_OMC must be a compiler other than PIN's" >&2; exit 2; } 23 [ -z "$(git status --porcelain)" ] || { echo "receipt: the tree is not clean" >&2; exit 2; } 24 [ ! -e "$root" ] || { echo "receipt: $root exists; a trial store is made fresh" >&2; exit 2; } 25 mkdir "$out" 2>/dev/null || { echo "receipt: $out exists; a receipt is never written over another" >&2; exit 2; } 26 mkdir -p "$root/TRIAL-KEY" || exit 2 27 head=$(git rev-parse HEAD); key=$root/TRIAL-KEY/trial_`ed25519` 28 ssh-keygen -q -t `ed25519` -N "" -C "trial key made by tools/receipt.sh for $head; not an owner's key" -f "$key" || exit 2 29 # Pin outside the trial ROOT (never inside $root). Live forge/mirror hosts use 30 # ~/.config/interplane/owner-pins or IPL_OWNER_PINS; do not install that file from this script. 31 printf '* %s\n' "$(ssh-keygen -lf "$key.pub" | awk '{print $2}')" > "$out/owner-pins" 32 chmod 600 "$out/owner-pins" 33 export IPL_OWNER_PINS="$out/owner-pins" 34 echo "receipt:$invocation" > "$out/commands.txt" 35 run() { # NAME cmd...: the exact command, its log and its exit status 36 local n=$1; shift; printf '%s:' "$n" >> "$out/commands.txt"; printf ' %q' "$@" >> "$out/commands.txt"; echo >> "$out/commands.txt" 37 "$@" > "$out/$n.log" 2>&1; echo $? > "$out/$n.rc" 38 } 39 run build sh build.sh "$omc" "$sha2" "$chainom" "$snapom" 40 run gate bash tests/run.sh "$omc" "$sha2" "$chainom" 41 run gate-wrong-compiler bash tests/run.sh "$wrong" "$sha2" "$chainom" 42 run import tools/import-radicle.sh "$root" "$key" 43 run catalog ./ipl catalog "$root" 44 same=0; diff=0 45 while IFS=$'\t' read -r name id br h vis; do 46 rid=$(sed -n 's/^alias rad://p' "$root/projects/$name/records/1") 47 o=$(env -i PATH=/usr/bin:/bin git --git-dir="${RAD_HOME:-$HOME/.radicle}/storage/$rid" rev-parse -q --verify "refs/heads/$br" 2>/dev/null) 48 s=$(env -i PATH=/usr/bin:/bin git --git-dir="$root/projects/$name/repo.git" rev-parse -q --verify "refs/heads/$br" 2>/dev/null) 49 if [ -n "$h" ] && [ "$o" = "$h" ] && [ "$s" = "$h" ]; then same=$((same + 1)); else diff=$((diff + 1)); echo "$name old=$o store=$s chain=$h"; fi 50 done < "$root/catalog.tsv" > "$out/heads-differ.txt" 51 rc() { cat "$out/$1.rc"; } 52 tsv=$root/import.tsv 53 n_ok=0; n_skip=0; n_ref=0; n_rows=0; refused=""; catalog_lines=0; names_match=0 54 if [ -f "$tsv" ]; then 55 n_ok=$(grep -c -P '\tOK$' "$tsv"); n_skip=$(grep -c -P '\tSKIP ' "$tsv"); n_ref=$(grep -c -P '\tREFUSED ' "$tsv"); n_rows=$(wc -l < "$tsv") 56 refused=$(grep -P '\tREFUSED ' "$tsv" | cut -f1 | sort) 57 fi 58 if [ -f "$root/catalog.tsv" ]; then 59 catalog_lines=$(wc -l < "$root/catalog.tsv") 60 # by name, not only by count: the verified catalog is exactly the projects the import took 61 [ -f "$tsv" ] && [ "$(grep -P '\tOK$' "$tsv" | cut -f1 | sort)" = "$(cut -f1 "$root/catalog.tsv" | sort)" ] && names_match=1 62 else : > "$root/catalog.tsv"; fi 63 [ -f "$tsv" ] || : > "$tsv" 64 # every line of the inventory is one of the three outcomes; every OK project is in the verified 65 # catalog and nothing else is; the refusals are exactly the stated ones 66 accounted=0; [ "$n_rows" = $((n_ok + n_skip + n_ref)) ] && [ "$catalog_lines" = "$n_ok" ] && [ "$n_ok" -gt 0 ] && [ "$names_match" = 1 ] && accounted=1 67 refusals_as_stated=0; [ "$refused" = "$expected" ] && refusals_as_stated=1 68 want_import=0; [ "$n_ref" = 0 ] || want_import=1 69 pass=0 70 [ "$(rc build)" = 0 ] && [ "$(rc gate)" = 0 ] && [ "$(rc gate-wrong-compiler)" = 2 ] && [ "$(rc import)" = "$want_import" ] && [ "$(rc catalog)" = 0 ] && 71 [ "$diff" = 0 ] && [ "$same" = "$n_ok" ] && [ "$accounted" = 1 ] && [ "$refusals_as_stated" = 1 ] && pass=1 72 jq -n --arg head "$head" --arg root "$root" --arg pin "$(cat PIN)" --argjson pass "$pass" \ 73 --arg gate_last "$(tail -n 1 "$out/gate.log")" --arg tools "$(grep '^tools: ' "$out/gate.log")" \ 74 --arg import_last "$(grep '^import: ok' "$out/import.log")" --arg import_tools "$(grep '^import: looked' "$out/import.log")" \ 75 --arg refused "$(grep -P '\tREFUSED ' "$tsv" | cut -f1,2,6 | tr '\t' ' ')" --arg skipped "$(grep -P '\tSKIP ' "$tsv" | cut -f2,6 | tr '\t' ' ')" --arg expected "$expected" \ 76 --argjson build_rc "$(rc build)" --argjson gate_rc "$(rc gate)" --argjson wrong_rc "$(rc gate-wrong-compiler)" --argjson import_rc "$(rc import)" --argjson catalog_rc "$(rc catalog)" \ 77 --argjson want_import "$want_import" --argjson n_ok "$n_ok" --argjson n_skip "$n_skip" --argjson n_ref "$n_ref" --argjson n_rows "$n_rows" \ 78 --argjson catalog_lines "$catalog_lines" --argjson same "$same" --argjson differ "$diff" --argjson accounted "$accounted" --argjson as_stated "$refusals_as_stated" \ 79 --arg commands "$(cat "$out/commands.txt")" --arg keyfp "$(ssh-keygen -lf "$key.pub" | awk '{print $2}')" \ 80 --arg logs "$(cd "$out" && sha256sum commands.txt build.log gate.log gate-wrong-compiler.log import.log catalog.log heads-differ.txt)" \ 81 --arg inventory "$(sha256sum < "$tsv" | cut -c1-64)" --arg catalog "$(sha256sum < "$root/catalog.tsv" | cut -c1-64)" \ 82 --arg binaries "$(cat bin/BUILD.sha256)" --arg when "$(date -u +%FT%TZ)" --arg host "$(uname -n) $(uname -m)" ' 83 {what: "interplane-native step 1, trial store", 84 result: (if $pass == 1 then "every step below did what it should" else "FAILED: at least one step below did not do what it should" end), 85 scope: "a local trial on this host; not installed, not serving, not the publishing route", 86 head: $head, written: $when, host: $host, pin: ($pin | split("\n") | map(select(. != ""))), built: ($binaries | split("\n")), 87 commands: ($commands | split("\n") | map(select(. != ""))), 88 trial_key: {made_by: "this run, for this run", fingerprint: $keyfp, path: ($root + "/TRIAL-KEY")}, 89 steps: [ 90 {step: "build", exit: $build_rc, want: 0}, 91 {step: "gate", exit: $gate_rc, want: 0, last_line: $gate_last, tools: $tools}, 92 {step: "gate with another compiler (control: must be refused)", exit: $wrong_rc, want: 2}, 93 {step: "import", exit: $import_rc, want: $want_import, last_line: $import_last, tools: $import_tools, 94 inventory_lines: $n_rows, ok: $n_ok, left_out_on_purpose: $n_skip, refused: $n_ref, 95 refused_projects: ($refused | split("\n") | map(select(. != ""))), refusals_the_runner_expected: ($expected | split("\n") | map(select(. != ""))), 96 refusals_are_exactly_the_expected_ones: ($as_stated == 1), left_out: ($skipped | split("\n") | map(select(. != ""))), inventory_sha256: $inventory}, 97 {step: "catalog from full verification", exit: $catalog_rc, want: 0, projects: $catalog_lines, catalog_sha256: $catalog, 98 every_imported_project_and_nothing_else: ($accounted == 1)}, 99 {step: "head of every catalogued project compared with the old store and with repo.git", same: $same, different: $differ, want_different: 0}], 100 trial_root: $root, logs_sha256: ($logs | split("\n")), 101 not_done: ["ipl is shell: its decisions are not yet in Omega", "no agent grants, no HTTP actions, no mirrors, nothing served (steps 2 to 6)", "no owner key: the signing key is the trial key above", "private projects are not imported", "interruptions are tested by stopping the program at chosen points, not by cutting power"]}' > "$out/READY.json" || 102 { echo "receipt: READY.json could not be written" >&2; exit 1; } 103 [ -s "$out/READY.json" ] && [ "$pass" = 1 ]