From b6fa7eb6ccea0ba67c9f614ed1487df470eb79bb Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Thu, 12 Nov 2026 03:35:59 -0400 Subject: [PATCH] os/, tools/, onnx/: the same usage-range defect, seven of eight already leaking code #2258 fixed `scripts/`: usage text built from `sed -n '16,62p' "$0"`, which is a claim about a file's shape and stops being true when the header above it is edited. The same pattern is in eight more files outside `scripts/`, and **seven had already drifted past the end of their header** -- measured statically, by comparing the range's end with the first line of code: os/v2/mkdebs.sh range 22,45 code starts 44 -> prints code os/v2/mkrepo.sh range 21,27 code starts 23 -> prints code os/v2/mkrootfs.sh range 21,32 code starts 32 -> prints code os/v2/proto.sh range 21,32 code starts 27 -> prints code os/v2/vmtest-v2.sh range 21,34 code starts 31 -> prints code os/v3/puppy/demo-seq-probe.sh range 28,48 code starts 44 -> prints code tools/xhci_keepawake_check.sh range 17,40 code starts 37 -> prints code onnx/bench_npu.sh range 2,30 header ends 45 -> prints only PART of its help (the other direction) `tools/xhci_keepawake_check.sh` is the one that matters most: `docs/axb35-usb-ports.md` and the release notes tell a person to run it with `--require-awake`, and `--help` on it printed code instead of the header. All eight now use the anchored extraction from #2258, defined below the first line of code so its own comment cannot leak: usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } Verified **statically, without executing them** -- several of these reach for devices (`bench_npu.sh` opens the NPU, which is off by owner order; `demo-seq-probe.sh` and `vmtest-v2.sh` too), and #2258's lesson was that running a help path can take a resource. So: * every file: `bash -n` clean, exactly one `usage()` definition, no self-recursive body, no other line ranges left; * each `usage()` output simulated with the same awk: 16-37 lines of prose, **zero** code-like lines, and `bench_npu.sh` now prints its whole header instead of the first 29 lines of it. --- onnx/bench_npu.sh | 6 +++++- os/v2/mkdebs.sh | 6 +++++- os/v2/mkrepo.sh | 6 +++++- os/v2/mkrootfs.sh | 6 +++++- os/v2/proto.sh | 6 +++++- os/v2/vmtest-v2.sh | 6 +++++- os/v3/puppy/demo-seq-probe.sh | 6 +++++- tools/xhci_keepawake_check.sh | 6 +++++- 8 files changed, 40 insertions(+), 8 deletions(-) diff --git a/onnx/bench_npu.sh b/onnx/bench_npu.sh index 947b3e249..a8a7cfa91 100755 --- a/onnx/bench_npu.sh +++ b/onnx/bench_npu.sh @@ -45,6 +45,10 @@ # PORT serve port (default 52625) set -uo pipefail +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- several of these ranges +# had drifted past the end of their header and printed code to whoever asked for help (the same defect engine PR #2258 fixed in scripts/). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + BIN="${ONEBIT_BIN:-$HOME/src/engine-laya-npu/build-npu/1bit}" MODEL="${ONEBIT_MODEL:-$HOME/.config/flm/models/Qwen3-0.6B-NPU2}" KERNELS="${ONEBIT_DX_KERNELS:-}" @@ -60,7 +64,7 @@ while [ $# -gt 0 ]; do --kernels) KERNELS="$2"; shift 2 ;; --port) PORT="$2"; shift 2 ;; --lens|--gen|-w|--warmup|-r|--repeat|--mode|--endpoint) BENCH_ARGS+=("$1" "$2"); shift 2 ;; - -h|--help) sed -n '2,30p' "$0"; exit 0 ;; + -h|--help) usage; exit 0 ;; *) echo "bench_npu.sh: unknown option $1" >&2; exit 2 ;; esac done diff --git a/os/v2/mkdebs.sh b/os/v2/mkdebs.sh index 2dd8b0c4e..dba240388 100755 --- a/os/v2/mkdebs.sh +++ b/os/v2/mkdebs.sh @@ -42,7 +42,11 @@ # prefix (bin/lemond, bin/lemonade, bin/resources). is the release tag, with or without the # leading v: v2026.43 becomes 2026.43-1. set -euo pipefail -[ $# -ge 4 ] || { sed -n '22,45p' "$0"; exit 2; } + +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- several of these ranges +# had drifted past the end of their header and printed code to whoever asked for help (the same defect engine PR #2258 fixed in scripts/). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } +[ $# -ge 4 ] || { usage; exit 2; } stage_in=$1 lemon=$2 version=${3#v} out=$4 keyring=${5:-} kstage=${KERNEL_STAGE:-} kver= here=$(cd "$(dirname "$0")" && pwd) src=$(cd "$here/../.." && pwd) diff --git a/os/v2/mkrepo.sh b/os/v2/mkrepo.sh index 4d3331fd6..2c51bd6a8 100755 --- a/os/v2/mkrepo.sh +++ b/os/v2/mkrepo.sh @@ -21,7 +21,11 @@ # Release file is produced unsigned and the script says so - useful for a local run, never for # publishing. The result is a directory of static files: publish it to 1bit.gg/apt as it is. set -euo pipefail -[ $# -ge 2 ] || { sed -n '21,27p' "$0"; exit 2; } + +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- several of these ranges +# had drifted past the end of their header and printed code to whoever asked for help (the same defect engine PR #2258 fixed in scripts/). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } +[ $# -ge 2 ] || { usage; exit 2; } debs=$1 repo=$2 gnupg=${3:-} keyid=${4:-} [ -d "$debs" ] || { echo "mkrepo: no $debs"; exit 2; } dist=$repo/dists/stable diff --git a/os/v2/mkrootfs.sh b/os/v2/mkrootfs.sh index b3ec24e87..a963095f8 100755 --- a/os/v2/mkrootfs.sh +++ b/os/v2/mkrootfs.sh @@ -30,7 +30,11 @@ # The repository goes in at /srv/1bit-apt and apt reads it as file://, so the signed-by chain is the # same one https would use: an unsigned or wrongly signed Release file fails the build here. set -euo pipefail -[ $# -ge 2 ] || { sed -n '21,32p' "$0"; exit 2; } + +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- several of these ranges +# had drifted past the end of their header and printed code to whoever asked for help (the same defect engine PR #2258 fixed in scripts/). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } +[ $# -ge 2 ] || { usage; exit 2; } repo=$(cd "$1" && pwd) rootfs=$2 sshkey=${3:-} here=$(cd "$(dirname "$0")" && pwd) . "$here/pin.txt" diff --git a/os/v2/proto.sh b/os/v2/proto.sh index 637efe572..383f6b842 100755 --- a/os/v2/proto.sh +++ b/os/v2/proto.sh @@ -25,7 +25,11 @@ # directory to seed the data partition with (so the VM needs no network for Lemonade's backends), and # [model.gguf] a small model for the chat row. set -euo pipefail -[ $# -ge 3 ] || { sed -n '21,32p' "$0"; exit 2; } + +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- several of these ranges +# had drifted past the end of their header and printed code to whoever asked for help (the same defect engine PR #2258 fixed in scripts/). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } +[ $# -ge 3 ] || { usage; exit 2; } w=$1 stage=$2 lemon=$3 backends=${4:-} model=${5:-$HOME/models/Qwen3-0.6B-Q4_K_M.gguf} here=$(cd "$(dirname "$0")" && pwd) version=v2026.43 diff --git a/os/v2/vmtest-v2.sh b/os/v2/vmtest-v2.sh index be5c64de9..1826b9557 100755 --- a/os/v2/vmtest-v2.sh +++ b/os/v2/vmtest-v2.sh @@ -29,7 +29,11 @@ # # Prints VMTEST-V2 PASS or FAIL. set -uo pipefail -[ $# -ge 2 ] || { sed -n '21,34p' "$0"; exit 2; } + +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- several of these ranges +# had drifted past the end of their header and printed code to whoever asked for help (the same defect engine PR #2258 fixed in scripts/). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } +[ $# -ge 2 ] || { usage; exit 2; } rootfs=$(cd "$1" && pwd) seed=$(cd "$2" && pwd) key=${3:-} # an mmdebstrap rootfs is root-owned with root-only files: populating a filesystem image from it and # handing it to qemu needs root, so the whole test runs as root rather than half of it diff --git a/os/v3/puppy/demo-seq-probe.sh b/os/v3/puppy/demo-seq-probe.sh index bee7bb3ca..569565d1e 100755 --- a/os/v3/puppy/demo-seq-probe.sh +++ b/os/v3/puppy/demo-seq-probe.sh @@ -43,6 +43,10 @@ # 1 when any did not, 2 on usage/setup error. set -uo pipefail +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- several of these ranges +# had drifted past the end of their header and printed code to whoever asked for help (the same defect engine PR #2258 fixed in scripts/). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + rounds=10 url=${LEMONADE:-http://1bit-os.local:13305/api/v1} npu=${NPU_MODEL:-Qwen3-0.6B-NPU-1bit} @@ -56,7 +60,7 @@ while [ $# -gt 0 ]; do --big) big=${2:?}; shift 2 ;; --dmesg) dmesg_file=${2:?}; shift 2 ;; --state) state=${2:?}; shift 2 ;; - -h | --help) sed -n '28,48p' "$0"; exit 0 ;; + -h | --help) usage; exit 0 ;; *[!0-9]*) echo "demo-seq-probe: unknown argument: $1" >&2; exit 2 ;; *) rounds=$1; shift ;; esac diff --git a/tools/xhci_keepawake_check.sh b/tools/xhci_keepawake_check.sh index 6aea65fe9..e255c083a 100755 --- a/tools/xhci_keepawake_check.sh +++ b/tools/xhci_keepawake_check.sh @@ -36,6 +36,10 @@ # 2 = usage/IO problem. Never 0 by accident: a machine where the rule does not apply says so. set -u +# usage(): the header comment as prose, anchored on the comment block rather than a line range -- several of these ranges +# had drifted past the end of their header and printed code to whoever asked for help (the same defect engine PR #2258 fixed in scripts/). +usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"; } + SYSFS=${SYSFS:-/sys} MODE=report @@ -56,7 +60,7 @@ while [ $# -gt 0 ]; do --apply) MODE=apply; shift;; --revert) MODE=revert; shift;; --sysfs-root) SYSFS=${2:?--sysfs-root needs a directory}; shift 2;; - -h|--help) sed -n '17,40p' "$0"; exit 0;; + -h|--help) usage; exit 0;; *) echo "xhci_keepawake_check: unknown argument '$1'" >&2; exit 2;; esac done