AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
set -euo pipefail4
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"5
cd "$repo_dir"7
# POPULATION. `test/sabotage-*.sh` was absent from this list until 2026-08-23,8
# so seven sabotage scripts were swept by NOTHING -- no absolute-path check, no9
# `bash -n` parse. A syntax error in one surfaced only when somebody ran it, and10
# those are exactly the scripts run rarely and under time pressure. Adding the11
# glob costs one entry; every check below already applies to whatever is in it.12
active_scripts=(test/gate-*.sh test/sabotage-*.sh test/build-d3-bytecode-base.sh tools/*.sh)14
# EVERY ENTRY MUST BE A REAL FILE, because an unexpanded glob is not an error.15
#16
# When a glob matches nothing, bash leaves the LITERAL PATTERN in the array. Both17
# consumers below would then quietly examine less than they claim: the mode loop18
# skips it via `test -f`, and a reader seeing "30 scripts" would have no way to19
# know one of four globs contributed zero. A floor on the total cannot catch it20
# either -- dropping `tools/*.sh` takes 30 to 28, comfortably above any floor21
# worth setting. Checking each entry is what makes the denominator honest, and it22
# is the check that catches a DIRECTORY being renamed out from under this file.23
for entry in "${active_scripts[@]}"; do24
test -f "$entry" || {25
echo "PORTABILITY_GATE: '$entry' is not a file." >&226
echo " A glob in active_scripts matched nothing, so bash left the pattern itself" >&227
echo " in the array and everything below is examining fewer scripts than it says." >&228
exit 1; }29
done31
absolute_path_pattern='(^|[^$A-Za-z0-9_])/(bin|sbin|usr|opt|Users|home|tmp|var|etc|run|nix|gnu)/'33
if ! printf 'tool=/%s\n' 'opt/portability-sensitivity/tool' \34
| rg -q "$absolute_path_pattern"; then35
echo 'PORTABILITY_GATE: absolute-path detector did not reject its sensitivity probe' >&236
exit 137
fi38
absolute_path_hits=$(rg -n "$absolute_path_pattern" "${active_scripts[@]}" \39
| rg -v ':1:#!' \40
| rg -v 'test/gate-d6\.sh:.*#read.*etc/passwd' || true)41
if test -n "$absolute_path_hits"; then42
printf '%s\n' "$absolute_path_hits"43
echo 'PORTABILITY_GATE: active scripts contain a host-specific absolute path' >&244
exit 145
fi46
if rg -n -- '-L[[:space:]]+\.\./sigil-sxml/src' "${active_scripts[@]}"; then47
echo 'PORTABILITY_GATE: active scripts contain an unconfigurable sigil-sxml sibling path' >&248
exit 149
fi51
# SD-P8 added `test/gate-sd-p8.sh`, which resolves sigil-sxml and the dev52
# compiler exactly as these do. Adding it here rather than leaving it to the53
# absolute-path sweep alone is the population check this file exists to be: a54
# new gate that took a sibling path unconfigurably would pass the regex above55
# and still be unportable.56
rg -q 'SIGIL_SXML_ROOT' test/gate-sd-p8.sh57
rg -q 'SIGIL_D1_COMPILER' test/gate-sd-p8.sh58
rg -q 'SIGIL_D1_COMPILER' test/sabotage-sd-p8.sh59
rg -q 'SIGIL_SXML_ROOT' test/sabotage-sd-p8.sh61
for gate in test/gate-d4a.sh test/gate-d6.sh test/gate-d6-customization.sh \62
test/gate-semantic-structures.sh test/gate-glossary.sh; do63
rg -q 'SIGIL_SXML_ROOT' "$gate"64
done65
for helper in test/d4a-trusted-presentation.sgl test/build-d6-pressure.sgl; do66
rg -q 'getenv "SIGIL_D1_COMPILER"' "$helper"67
done68
for gate in test/gate-d6.sh test/gate-d6-customization.sh; do69
rg -q 'TYPST_BIN' "$gate"70
rg -q 'PDFINFO_BIN' "$gate"71
rg -q 'PDFTOTEXT_BIN' "$gate"72
rg -q 'PDFTOPPM_BIN' "$gate"73
rg -q 'QPDF_BIN' "$gate"74
rg -q 'CONVERT_BIN' "$gate"75
rg -q 'SHA256SUM_BIN' "$gate"76
done77
rg -q 'SIGIL_COMPILER_REPO' test/build-d3-bytecode-base.sh78
rg -q 'D3_BYTECODE_BASE_DIR' test/build-d3-bytecode-base.sh81
# EVERY SCRIPT WITH A SHEBANG MUST BE EXECUTABLE IN THE INDEX.82
#83
# Nothing in this repository checked file MODE until 2026-08-23, and the gap is84
# structural rather than an oversight: every check here looks at CONTENT. `bash85
# -n` parses, `rg` greps, `sha256sum` hashes, `git diff` shows. **None of them86
# can see a permission bit.** So a rewrite-and-replace -- `awk … > tmp && mv`, a87
# non-inplace `sed`, an editor's atomic save, a `cp` from a scratch copy -- drops88
# the execute bit silently and no instrument in the tree notices. It surfaces89
# only in git's own `create mode 100644` line at merge time, which nobody reads90
# adversarially. Two independent instances in this estate on one day.91
#92
# THE INDEX, NOT THE FILESYSTEM. `git ls-files -s` is what ships and what a93
# fresh clone gets; a local `chmod +x` that was never staged would make a94
# filesystem check pass and still hand the next person a non-executable file.95
#96
# IT ITERATES `active_scripts` -- THE SAME ARRAY THE SWEEP USES -- so the two97
# cannot drift. An earlier version re-listed two of the four globs and its98
# comment claimed the population was "derived"; it was not, and extending99
# `active_scripts` would have silently left the mode check behind. Sharing the100
# array makes that structural rather than a promise. The shebang test does the101
# filtering, which is why widening it to `tools/*.sh` and the d3 base script102
# cost nothing: measured, all three are already 100755 with shebangs.103
mode_checked=0104
mode_bad=0105
for script in "${active_scripts[@]}"; do106
test -f "$script" || continue107
head -1 "$script" | rg -q '^#!' || continue108
mode_checked=$((mode_checked + 1))109
mode=$(git ls-files -s -- "$script" | awk '{print $1}')110
test -n "$mode" || { echo "PORTABILITY_GATE: $script is not tracked, so its mode cannot ship" >&2; mode_bad=$((mode_bad + 1)); continue; }111
if [ "$mode" != "100755" ]; then112
echo "PORTABILITY_GATE: $script has a shebang but is $mode in the index, not 100755" >&2113
echo " A rewrite-and-replace drops the execute bit and no content check can see it." >&2114
echo " Fix with: chmod +x $script && git update-index --chmod=+x $script" >&2115
mode_bad=$((mode_bad + 1))116
fi117
done118
test "$mode_checked" -ge 20 \119
|| { echo "PORTABILITY_GATE: the mode check examined only $mode_checked scripts; its globs are not matching the tree" >&2; exit 1; }120
test "$mode_bad" -eq 0 || { echo "PORTABILITY_GATE: $mode_bad script(s) with a shebang are not executable in the index" >&2; exit 1; }121
echo "PORTABILITY_GATE_MODES $mode_checked scripts with a shebang, all 100755 in the index"123
bash -n "${active_scripts[@]}"124
echo PORTABILITY_GATE_GREEN