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/infra/test/ops-scratch.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 / infra / test / ops-scratch.sh` 371 lines ยท 26408 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # infra/test/ops-scratch.sh: exercise infra/ops/* and the ops changes in infra/spark/ on the Spark, 3 # writing only into a scratch dir. Each check has a negative control. 4 # Live contact, all read-only: IPL_TEST_ROUNDS probe rounds of GETs to https://interplane.io and one 5 # openssl read of its certificate; reads of ~/.radicle/storage/*/refs and readable /etc/nginx 6 # (archived into the scratch spool, encrypted to a THROWAWAY age key made here); `systemctl show` 7 # of the Forgejo units and ssh.service; the Forgejo setup files under /home/atlas (staged into 8 # scratch). A throwaway non-root nginx listens on 127.0.0.1:$IPL_TEST_PORT and is stopped on exit. 9 # Nothing live is written, enabled, started or stopped. 10 # Usage: bash infra/test/ops-scratch.sh 11 # Env: IPL_TEST_ROUNDS (3) IPL_TEST_SLEEP (20 s between rounds) IPL_TEST_PORT (14548) 12 # KEEP=1 keeps the scratch dir (the Mac pull test reads its spool) 13 # Host tools: bash, curl, openssl, age, GNU tar, nginx 1.24, inotify-tools, flock, systemd-analyze, patch. 14 set -u 15 PATH=$PATH:/usr/sbin # nginx is /usr/sbin/nginx; some agent shells leave sbin out 16 R=$(cd "$(dirname "$0")/../.." && pwd) 17 O=$R/infra/ops; SP=$R/infra/spark 18 ROUNDS=${IPL_TEST_ROUNDS:-3}; NAP=${IPL_TEST_SLEEP:-20}; PORT=${IPL_TEST_PORT:-14548} 19 S=$(mktemp -d /tmp/ipl-ops-test.XXXXXX) 20 NGXPID=$S/ngx/nginx.pid 21 # stopsup PIDFILE: stop a supervisor started by minrun (section 6). Its first line records its own 22 # pid; under setsid that bash leads its own session and process group, so the pid is the group id 23 # (the pid of `setsid bash ... &` is not: setsid forks when it already leads a group). TERM the 24 # group, wait up to 5 s, KILL what is left. 25 stopsup() { 26 local g; g=$(cat "$1" 2>/dev/null) || return 0 27 case $g in ''|*[!0-9]*) return 0;; esac 28 kill -TERM -- "-$g" 2>/dev/null 29 for _ in $(seq 1 25); do kill -0 -- "-$g" 2>/dev/null || break; sleep 0.2; done 30 kill -KILL -- "-$g" 2>/dev/null 31 rm -f -- "$1" 32 } 33 cleanup() { 34 local f 35 for f in "$S"/*.sup.pid; do [ -e "$f" ] && stopsup "$f"; done 36 [ -f "$NGXPID" ] && kill -QUIT "$(cat "$NGXPID")" 2>/dev/null 37 if [ "${KEEP:-0}" = 1 ]; then echo "scratch kept: $S"; else rm -rf -- "$S"; fi 38 } 39 trap cleanup EXIT 40 # a signal ends the run through exit, so cleanup (supervisors first, then the directory) runs on 41 # every exit path 42 trap 'exit 129' HUP; trap 'exit 130' INT; trap 'exit 143' TERM 43 pass=0; fail=0 44 ok() { pass=$((pass + 1)); echo "PASS $*"; } 45 bad() { fail=$((fail + 1)); echo "FAIL $*"; } 46 chk() { local n=$1; shift; if "$@"; then ok "$n"; else bad "$n"; fi; } 47 # rc NAME WANT CMD...: run CMD, output to $S/last.out, compare the exit code. 48 rc() { 49 local n=$1 want=$2 got; shift 2 50 "$@" >"$S/last.out" 2>&1; got=$? 51 if [ "$got" = "$want" ]; then ok "$n (exit $got)"; else bad "$n (exit $got, want $want)"; show 30; fi 52 } 53 show() { sed 's/^/ | /' "$S/last.out" | head -n "${1:-20}"; } 54 has() { grep -q -- "$1" "${2:-$S/last.out}"; } 55 hasnt() { ! grep -q -- "$1" "${2:-$S/last.out}"; } 56 echo "ops-scratch: repo $R head $(git -C "$R" rev-parse --short HEAD) scratch $S $(date -u +%FT%TZ)" 57 58 echo "== 1. syntax" 59 for f in "$O"/*.sh "$O"/mac/forge-backup-pull.sh "$SP"/edge-mirror.sh "$SP"/forgejo/forgejo-backup \ 60 "$SP"/forgejo/forgejo-runtime-restore.sh "$R"/infra/test/ops-scratch.sh; do 61 case $(head -1 "$f") in *bash*) sh=bash;; *) sh=sh;; esac 62 rc "$sh -n ${f#"$R"/}" 0 "$sh" -n "$f" 63 done 64 printf 'if then fi\n' >"$S/broken.sh" 65 rc "negative: bash -n on a broken file" 2 bash -n "$S/broken.sh" 66 67 echo "== 2. probe" 68 rc "probe --dry-run" 0 env IPL_UPTIME_STATE="$S/u-dry" "$O/ipl-uptime-probe.sh" --dry-run; show 69 chk "probe --dry-run wrote nothing" test ! -e "$S/u-dry" 70 rc "negative: probe refuses a non-https base" 2 env IPL_UPTIME_BASE=http://interplane.io IPL_UPTIME_STATE="$S/u-x" "$O/ipl-uptime-probe.sh" 71 for i in $(seq 1 "$ROUNDS"); do 72 rc "probe live round $i" 0 env IPL_UPTIME_STATE="$S/u" "$O/ipl-uptime-probe.sh"; show 73 [ "$i" -lt "$ROUNDS" ] && sleep "$NAP" 74 done 75 n=$(wc -l <"$S/u/probes.tsv"); n200=$(awk -F'\t' '$3 ~ /^[23]/' "$S/u/probes.tsv" | wc -l) 76 chk "probes.tsv has $n lines from $ROUNDS rounds, $n200 with 2xx/3xx" test "$n" = $((ROUNDS * 5)) 77 echo " cert.txt: $(cat "$S/u/cert.txt")" 78 chk "cert expiry read with openssl" grep -qP '^\S+\t20\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ\t' "$S/u/cert.txt" 79 rc "negative: probe against a closed port" 0 env IPL_UPTIME_BASE=https://127.0.0.1:1 IPL_UPTIME_PATHS=/ IPL_UPTIME_STATE="$S/u-neg" "$O/ipl-uptime-probe.sh"; show 80 chk "negative: closed port recorded as status 000" grep -qP '\t/\t000\t' "$S/u-neg/probes.tsv" 81 chk "negative: closed port gives no certificate" grep -q 'no certificate read' "$S/u-neg/cert.txt" 82 83 echo "== 3. page" 84 rc "render --dry-run" 0 env IPL_UPTIME_STATE="$S/u" "$O/ipl-uptime-render.sh" --dry-run 85 cp "$S/last.out" "$S/page.html" 86 chk "page says inside view, not an outside check" has 'Inside view from the Spark; not an outside check' "$S/page.html" 87 chk "page shows the cert expiry" grep -q 'certificate served for interplane.io expires 20' "$S/page.html" 88 chk "page has one row per path (5)" test "$(grep -c '^