From 61e3be423b623023507b7063632d03352e555ade Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Thu, 12 Nov 2026 02:41:41 -0400 Subject: [PATCH] scripts: usage texts stop leaking code, and hw-gate's no-argument path stops taking a GPU ticket Every one of these scripts answered "how do I use this" with a line range into its own header: sed -n '16,62p' "$0" A line range is a claim about a file's shape, and it stops being true the moment someone edits the header above it. Two of them had already drifted: mk-kernel-packages.sh `... | sed -n '16,62p'` header ends at 54 -> printed `repo=$(cd ...)` and `kdebs=''` pack-distro.sh `... | sed -n '16,52p'` header ends at 50 -> printed `set -euo pipefail` So asking those two for help printed shell code. The other ten were still inside their headers, which is the same defect one edit from happening. They now extract the header itself -- comment lines after the shebang, stopping at the first line of code -- so an edit to the header cannot make the usage print code: usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } The definition sits BELOW the first line of code on purpose: the awk stops at that line, so the function's own comment cannot end up in its output. (My first attempt put it above, and the usage printed the function's comment as help text.) ## hw-gate.sh: no arguments took the fleet's GPU token The bigger find, and an accident: auditing usage paths, `hw-gate.sh` with no arguments **queued on ~/GPU-TOKEN and started a hardware run**: gpu-hold[3939264] queued 'hw-gate pid 3939264' as 0179446563 The script already documents this hazard for `-h` -- "printing the usage takes no hardware and must not claim the fleet's GPU token" -- but the guard is `case " $* " in *" -h "*|*" --help "*)`, and with **zero** arguments `$*` is empty, so the case does not match and the gate walks straight into the queue. It now answers no-arguments the way its siblings do: [ $# -gt 0 ] || { usage; exit 2; } Verified: `scripts/hw-gate.sh` -> rc 2, 63 lines of usage, and the queue is untouched -- `ls -A ~/GPU-QUEUE` 1652 entries and 81 `hw-gate` markers before and after. (My first check of that used `ls`, which hides the dotfiles the queue is made of, so it reported "no entries" for a directory with 1652 of them.) ## Verified all 12 scripts: bash -n clean; usage paths run under a 10s timeout, no code leaked, no hang install-ci-runner.sh: its own `usage()` body was replaced before the function existed -> `usage() { usage; }`, infinite recursion; removed, and the audit's timeout is why it was caught rather than shipped hw-gate.sh: rc 2, no queue entry, before/after counts identical tools/copyright.py --check: clean One shellcheck note, pre-existing and untouched: weekly.sh has SC2043/SC2010/SC2046 at lines 104, 292 and 611, none of them in the code this touches. --- scripts/bump-hrx-report.sh | 6 +++++- scripts/check-ci-runners.sh | 6 +++++- scripts/check-ubuntu-2604-lemond.sh | 6 +++++- scripts/fetch-rocm-sdk.sh | 6 +++++- scripts/hw-gate.sh | 12 +++++++++++- scripts/install-ci-runner.sh | 5 ++++- scripts/mk-kernel-packages.sh | 6 +++++- scripts/mk-plugin-package.sh | 6 +++++- scripts/pack-distro.sh | 6 +++++- scripts/pack-proof.sh | 6 +++++- scripts/package-linux.sh | 6 +++++- scripts/weekly.sh | 6 +++++- 12 files changed, 65 insertions(+), 12 deletions(-) diff --git a/scripts/bump-hrx-report.sh b/scripts/bump-hrx-report.sh index a75443953..a2de0108f 100755 --- a/scripts/bump-hrx-report.sh +++ b/scripts/bump-hrx-report.sh @@ -26,6 +26,10 @@ # there were no conflicts, which is the difference between "nothing conflicted" and "nobody looked". set -uo pipefail +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + run="" step="" log="" attempt="" while [ $# -gt 0 ]; do case "$1" in @@ -33,7 +37,7 @@ while [ $# -gt 0 ]; do --step) step=${2:?--step needs a name}; shift 2 ;; --log) log=${2:?--log needs a path or -}; shift 2 ;; --attempt) attempt=${2:?--attempt needs a number}; shift 2 ;; - -h|--help) sed -n '3,17p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; + -h|--help) usage; exit 0 ;; *) echo "bump-hrx-report: unknown argument: $1" >&2; exit 2 ;; esac done diff --git a/scripts/check-ci-runners.sh b/scripts/check-ci-runners.sh index 344989704..a95f7466f 100755 --- a/scripts/check-ci-runners.sh +++ b/scripts/check-ci-runners.sh @@ -33,6 +33,10 @@ # says where else it belongs and why a scheduled red needs a workflow change (an RFC under CONTRIBUTING). set -uo pipefail +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + repo=1bit-MONSTER/engine require=() list=0 @@ -41,7 +45,7 @@ while [ $# -gt 0 ]; do --repo) repo=$2; shift 2 ;; --require) shift; while [ $# -gt 0 ] && [ "${1#-}" = "$1" ]; do require+=("$1"); shift; done ;; --list) list=1; shift ;; - -h|--help) sed -n '16,33p' "$0"; exit 0 ;; + -h|--help) usage; exit 0 ;; *) echo "check-ci-runners.sh: unknown option $1" >&2; exit 2 ;; esac done diff --git a/scripts/check-ubuntu-2604-lemond.sh b/scripts/check-ubuntu-2604-lemond.sh index 2106a2af7..4a77f1f37 100755 --- a/scripts/check-ubuntu-2604-lemond.sh +++ b/scripts/check-ubuntu-2604-lemond.sh @@ -27,7 +27,11 @@ # /opt/rocm-therock come in from the host and the engine's HRX llama-server runs on HRX0. set -euo pipefail -[ $# -ge 2 ] || { sed -n '16,27p' "$0"; exit 2; } +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + +[ $# -ge 2 ] || { usage; exit 2; } pkg=$(readlink -f "$1") model=$(readlink -f "$2") gpu=${3:-} name=1bit-u2604-check-$$ runtime=${CONTAINER_RUNTIME:-docker} diff --git a/scripts/fetch-rocm-sdk.sh b/scripts/fetch-rocm-sdk.sh index a37541811..d6eb502ab 100755 --- a/scripts/fetch-rocm-sdk.sh +++ b/scripts/fetch-rocm-sdk.sh @@ -27,13 +27,17 @@ # stdout, diagnostics on stderr, so callers can use it as a command substitution. set -euo pipefail +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + root=$(cd "$(dirname "$0")/.." && pwd) me=fetch-rocm-sdk check=0 while [ $# -gt 0 ]; do case "$1" in --check) check=1; shift ;; - -h|--help) sed -n '16,26p' "$0"; exit 0 ;; + -h|--help) usage; exit 0 ;; --) shift; break ;; -*) echo "$me: unknown option $1" >&2; exit 2 ;; *) break ;; diff --git a/scripts/hw-gate.sh b/scripts/hw-gate.sh index 3ba2145f0..2e4f35a28 100755 --- a/scripts/hw-gate.sh +++ b/scripts/hw-gate.sh @@ -74,13 +74,23 @@ # the gate. set -uo pipefail +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + # -h/--help is answered before anything else, in particular before the GPU queue below: printing the # usage takes no hardware and must not claim the fleet's GPU token (measured: `hw-gate --help` queued on # ~/GPU-TOKEN and held it for a moment while another pass was running). case " $* " in - *" -h "*|*" --help "*) sed -n '16,66p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; + *" -h "*|*" --help "*) usage; exit 0 ;; esac +# No arguments at all is a usage error, not a hardware run. With an empty "$*" the case above does not match, so the gate used +# to walk straight into the GPU queue below: measured 2026-11-12, when an audit that ran every script's usage path took two +# tickets (`gpu-hold[...] queued 'hw-gate pid ...'`) instead of printing help. It claimed and released within seconds, but a +# usage path must take no hardware, and this one is now answered before the queue like -h/--help. +[ $# -gt 0 ] || { usage; exit 2; } + # Fair GPU queue (the protocol is written down in ~/amd-oss/GPU-TOKEN.md on the box): when the gpu-hold helper # is installed, the whole gate runs inside one claim on ~/GPU-TOKEN instead of racing for it with a noclobber # open. Claims are served in arrival order, a killed run cannot leave the token behind, the die temperature diff --git a/scripts/install-ci-runner.sh b/scripts/install-ci-runner.sh index d50770ef9..522946bb8 100755 --- a/scripts/install-ci-runner.sh +++ b/scripts/install-ci-runner.sh @@ -62,9 +62,12 @@ # --verify only report the installed unit's state set -euo pipefail +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + name=strixhalo-engine labels=pr-agent user=ghrunner groups=docker memory_max=48G token_file='' runner_dir='' runner_version='' env_file='' hold_state=/var/lib/1bit-fleet hold_group=fleethold owner_user=bcloud no_hold=0 migrate=0 dry=0 verify=0 -usage() { sed -n '16,48p' "$0"; } while [ $# -gt 0 ]; do case $1 in diff --git a/scripts/mk-kernel-packages.sh b/scripts/mk-kernel-packages.sh index 0c27ce24d..b47673f09 100755 --- a/scripts/mk-kernel-packages.sh +++ b/scripts/mk-kernel-packages.sh @@ -53,9 +53,13 @@ # the family it is building, so each family is proven in that family's container: # docs/install-any-distro.md. set -euo pipefail + +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } umask 022 -[ $# -ge 2 ] || { sed -n '16,62p' "$0"; exit 2; } +[ $# -ge 2 ] || { usage; exit 2; } out=$1 ver=$2; shift 2 repo=$(cd "$(dirname "$0")/.." && pwd) diff --git a/scripts/mk-plugin-package.sh b/scripts/mk-plugin-package.sh index 5f2594a3b..6f9577fda 100755 --- a/scripts/mk-plugin-package.sh +++ b/scripts/mk-plugin-package.sh @@ -38,7 +38,11 @@ # LIBHSA overrides the HSA runtime source; the default is the system's libhsa-runtime64.so.1. set -euo pipefail -[ $# -ge 3 ] || { sed -n '18,34p' "$0"; exit 2; } +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + +[ $# -ge 3 ] || { usage; exit 2; } bundle=$(cd "$1" && pwd) out=$2 ver=$3 [ -x "$bundle/1bit" ] || { echo "not a 1bit bundle: $bundle (no 1bit binary)" >&2; exit 1; } [ -d "$bundle/hrx/llama/bin" ] || { echo "not a 1bit bundle: $bundle (no hrx/llama/bin)" >&2; exit 1; } diff --git a/scripts/pack-distro.sh b/scripts/pack-distro.sh index 9ca41fb16..03795f7a7 100755 --- a/scripts/pack-distro.sh +++ b/scripts/pack-distro.sh @@ -50,7 +50,11 @@ # The produced file's path is the only thing on stdout. set -euo pipefail -[ $# -eq 3 ] || { sed -n '16,52p' "$0"; exit 2; } +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + +[ $# -eq 3 ] || { usage; exit 2; } fmt=$1 root=$2 out=$3 repo=$(cd "$(dirname "$0")/.." && pwd) # shellcheck source=scripts/pack-version.sh diff --git a/scripts/pack-proof.sh b/scripts/pack-proof.sh index 5af8d0ab4..ed4059ea0 100755 --- a/scripts/pack-proof.sh +++ b/scripts/pack-proof.sh @@ -44,7 +44,11 @@ # it supports, named once here so a release cannot quietly prove itself on something else. set -uo pipefail -[ $# -eq 2 ] || { sed -n '16,43p' "$0"; exit 2; } +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + +[ $# -eq 2 ] || { usage; exit 2; } dir=$(cd "$1" && pwd) || exit 2 # shellcheck source=scripts/pack-version.sh . "$(dirname "$0")/pack-version.sh" diff --git a/scripts/package-linux.sh b/scripts/package-linux.sh index 7a9d962f8..5f9f16fdc 100755 --- a/scripts/package-linux.sh +++ b/scripts/package-linux.sh @@ -29,7 +29,11 @@ # unpacks it into the Lemonade + onebit package as 1bit/ (docs/releases.md). set -euo pipefail -[ $# -ge 3 ] || { sed -n '16,27p' "$0"; exit 2; } +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + +[ $# -ge 3 ] || { usage; exit 2; } build=$(cd "$1" && pwd) out=$2 ver=$3 src=$(cd "$(dirname "$0")/.." && pwd) name=1bit-$ver-linux-x86_64 diff --git a/scripts/weekly.sh b/scripts/weekly.sh index 2a0045f70..15a48bcfe 100755 --- a/scripts/weekly.sh +++ b/scripts/weekly.sh @@ -36,7 +36,11 @@ # what the build scripts each list; preflight (at the end) checks the toolchain, hipcc, patchelf and the kernel image. set -euo pipefail -[ $# -ge 1 ] || { sed -n '16,33p' "$0"; exit 2; } +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- two of these ranges had +# drifted past the end of their header and printed code to whoever asked for help (engine#2129). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + +[ $# -ge 1 ] || { usage; exit 2; } W=$(mkdir -p "$1" && cd "$1" && pwd); shift STAGES=${*:-bumps build test package release} REPO=1bit-MONSTER/engine