From c107189e6c503c55ee24be6d2b9b645bcbc7a928 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell <273118822+dnyw4l3n13@users.noreply.github.com> Date: Wed, 24 Jun 2026 18:32:25 +0000 Subject: [PATCH 1/7] fix: replace raw echo with output helpers in check Replaced the script-local die/testing/hint/fail functions with the canonical die, info, and success helpers from shell-scripts.instructions.md. All call sites updated; excluded() echo "1"/"0" return values preserved. Prompt: Replace raw echo with output helpers in `check` (issue #619) Closes #619 --- CHANGELOG.md | 1 + check | 58 +++++++++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeac92a2..05efc3b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Please ADD ALL Changes to the UNRELEASED SECTION and not a specific release - git/make-preview: replaced raw echo with die/info/success output helpers - Replaced raw echo with output helpers (die/info/success) in git/clean-all - GEOIP - Updated GEOIP DB from MaxMind (2026-06-24) +- check: replaced raw echo-based output with standard die, info, and success helpers ### Deprecated ### Removed - db/sqlcompare script deleted — no longer in use diff --git a/check b/check index 056c4d08..6ede2a67 100755 --- a/check +++ b/check @@ -1,22 +1,28 @@ #! /bin/bash die() { - echo "$@" + if [ -t 2 ]; then + printf '\n\033[31m✗\033[0m %s\n' "$*" >&2 + else + printf '\n✗ %s\n' "$*" >&2 + fi exit 1 } -testing() { - echo " + $*" -} - -hint() { - echo " ? CHECK: $*" +success() { + if [ -t 1 ]; then + printf '\n\033[32m✓\033[0m %s\n' "$*" + else + printf '\n✓ %s\n' "$*" + fi } -fail() { - echo " - ERROR: $*" - exit 1 - +info() { + if [ -t 1 ]; then + printf '\n\033[32m→\033[0m %s\n' "$*" + else + printf '\n→ %s\n' "$*" + fi } @@ -52,47 +58,47 @@ FILES=$({ \ done < <(find "$BASEDIR" -not -path '*/.*' -type f -print) || die "Search: Shebang" } | sort | uniq) -echo "Testing:" +info "Testing:" for FILE in $FILES; do - echo "* $FILE" - testing "Executable" + info "* $FILE" + info "Executable" if [ ! -x "$FILE" ]; then - fail "Not Executable" + die "Not Executable" fi - testing "Shebang" + info "Shebang" FIRST_LINE=$(head -1 "$FILE") if [[ $FIRST_LINE =~ $REGEX_SHEBANG ]]; then SHEBANG_EXEC="${BASH_REMATCH[1]}" SHELL= if [ "$SHEBANG_EXEC" = "/bin/bash" ]; then SHELL="bash" - bash -n -u "$FILE" || fail "$SHELL: Invalid Script" - sh -n "$FILE" > /dev/null 2>&1 && hint "Could be run in bash?" + bash -n -u "$FILE" || die "$SHELL: Invalid Script" + sh -n "$FILE" > /dev/null 2>&1 && info "Could be run in sh?" elif [ "$SHEBANG_EXEC" = "/usr/bin/env bash" ]; then SHELL="bash" - bash -n -u "$FILE" || fail "$SHELL: Invalid Script" - sh -n "$FILE" > /dev/null 2>&1 && hint "Could be run in bash?" + bash -n -u "$FILE" || die "$SHELL: Invalid Script" + sh -n "$FILE" > /dev/null 2>&1 && info "Could be run in sh?" elif [ "$SHEBANG_EXEC" = "/bin/sh" ]; then SHELL="sh" - sh -n "$FILE" || fail "$SHELL: Invalid Script" + sh -n "$FILE" || die "$SHELL: Invalid Script" elif [ "$SHEBANG_EXEC" = "/usr/bin/env sh" ]; then SHELL="sh" - sh -n "$FILE" || fail "$SHELL: Invalid Script" + sh -n "$FILE" || die "$SHELL: Invalid Script" else - fail "Unknown Shell: $SHEBANG_EXEC" + die "Unknown Shell: $SHEBANG_EXEC" fi else - fail "No Shebang: $FIRST_LINE" + die "No Shebang: $FIRST_LINE" fi ## Run Shellcheck on the file if [ "$(excluded "$FILE")" = "1" ]; then - hint "Excluded from shellcheck" + info "Excluded from shellcheck" else - shellcheck "$FILE" || fail "Shellcheck" + shellcheck "$FILE" || die "Shellcheck" fi done From 111228ac2d9e187fef8ed2c451e55243568a8792 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell <273118822+dnyw4l3n13@users.noreply.github.com> Date: Wed, 24 Jun 2026 19:29:55 +0000 Subject: [PATCH 2/7] fix: call success() after all checks pass in check script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit success() was defined but never called, leaving the script silent on successful completion — indistinguishable from mid-run termination. Prompt: fix each code-review finding in its own commit --- check | 2 ++ 1 file changed, 2 insertions(+) diff --git a/check b/check index 6ede2a67..36de8ac6 100755 --- a/check +++ b/check @@ -102,3 +102,5 @@ for FILE in $FILES; do fi done + +success "All checks passed" From 4673a79c088eb2754970ad10b8f2d282c355f797 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell <273118822+dnyw4l3n13@users.noreply.github.com> Date: Wed, 24 Jun 2026 19:30:16 +0000 Subject: [PATCH 3/7] fix: prefix sh-portability advisory with Hint: to distinguish from progress steps The old hint() function emitted ' ? CHECK: ...' making advisories visually distinct from progress steps. Replacing with info() collapses them to the same format. Prefixing with 'Hint:' restores distinction. Prompt: fix each code-review finding in its own commit --- check | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check b/check index 36de8ac6..4d1ffc53 100755 --- a/check +++ b/check @@ -74,11 +74,11 @@ for FILE in $FILES; do if [ "$SHEBANG_EXEC" = "/bin/bash" ]; then SHELL="bash" bash -n -u "$FILE" || die "$SHELL: Invalid Script" - sh -n "$FILE" > /dev/null 2>&1 && info "Could be run in sh?" + sh -n "$FILE" > /dev/null 2>&1 && info "Hint: Could be run in sh?" elif [ "$SHEBANG_EXEC" = "/usr/bin/env bash" ]; then SHELL="bash" bash -n -u "$FILE" || die "$SHELL: Invalid Script" - sh -n "$FILE" > /dev/null 2>&1 && info "Could be run in sh?" + sh -n "$FILE" > /dev/null 2>&1 && info "Hint: Could be run in sh?" elif [ "$SHEBANG_EXEC" = "/bin/sh" ]; then SHELL="sh" sh -n "$FILE" || die "$SHELL: Invalid Script" From cd3db9ae993fd94fef10398592856326972f1256 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell <273118822+dnyw4l3n13@users.noreply.github.com> Date: Wed, 24 Jun 2026 19:30:41 +0000 Subject: [PATCH 4/7] fix: use mapfile array to avoid word-splitting on filenames with spaces for FILE in \$FILES word-splits on \$IFS, breaking paths containing spaces. mapfile -t + \"${FILES[@]}\" handles any filename safely. Prompt: fix each code-review finding in its own commit --- check | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check b/check index 4d1ffc53..ca39de29 100755 --- a/check +++ b/check @@ -45,7 +45,7 @@ excluded() { } # Find all the script files both executable and ones with shebang -FILES=$({ \ +mapfile -t FILES < <({ \ find "$BASEDIR" -not -path '*/.*' -type f -executable -print || die "Search: find" while IFS= read -r SHEBANG_FILE; do IFS= read -r FIRST_LINE < "$SHEBANG_FILE" || continue @@ -59,7 +59,7 @@ FILES=$({ \ } | sort | uniq) info "Testing:" -for FILE in $FILES; do +for FILE in "${FILES[@]}"; do info "* $FILE" info "Executable" if [ ! -x "$FILE" ]; then From 1b089c17d174a250e7eb4b86547d3bbbdfd75627 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell <273118822+dnyw4l3n13@users.noreply.github.com> Date: Wed, 24 Jun 2026 19:35:45 +0000 Subject: [PATCH 5/7] fix: guard against empty FILES array before loop and success message success "All checks passed" fired even with no files found, giving a false-positive result when BASEDIR was wrong or no scripts existed. Prompt: fix each code-review finding in its own commit --- check | 2 ++ 1 file changed, 2 insertions(+) diff --git a/check b/check index ca39de29..03c0ce41 100755 --- a/check +++ b/check @@ -58,6 +58,8 @@ mapfile -t FILES < <({ \ done < <(find "$BASEDIR" -not -path '*/.*' -type f -print) || die "Search: Shebang" } | sort | uniq) +[ "${#FILES[@]}" -gt 0 ] || die "No script files found in ${BASEDIR}" + info "Testing:" for FILE in "${FILES[@]}"; do info "* $FILE" From 29e568b0e2fb759a90f8ee647c2abf517ea1e194 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell <273118822+dnyw4l3n13@users.noreply.github.com> Date: Wed, 24 Jun 2026 19:42:02 +0000 Subject: [PATCH 6/7] fix: include filename in all die messages inside the per-file loop die() now writes to stderr while info "* \$FILE" writes to stdout. CI systems capturing them separately lose filename context. Adding \${FILE} to every die message in the loop restores that context. Prompt: fix each code-review finding in its own commit --- check | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/check b/check index 03c0ce41..678bf3ba 100755 --- a/check +++ b/check @@ -65,7 +65,7 @@ for FILE in "${FILES[@]}"; do info "* $FILE" info "Executable" if [ ! -x "$FILE" ]; then - die "Not Executable" + die "Not Executable: ${FILE}" fi info "Shebang" @@ -75,32 +75,32 @@ for FILE in "${FILES[@]}"; do SHELL= if [ "$SHEBANG_EXEC" = "/bin/bash" ]; then SHELL="bash" - bash -n -u "$FILE" || die "$SHELL: Invalid Script" + bash -n -u "$FILE" || die "$SHELL: Invalid Script: ${FILE}" sh -n "$FILE" > /dev/null 2>&1 && info "Hint: Could be run in sh?" elif [ "$SHEBANG_EXEC" = "/usr/bin/env bash" ]; then SHELL="bash" - bash -n -u "$FILE" || die "$SHELL: Invalid Script" + bash -n -u "$FILE" || die "$SHELL: Invalid Script: ${FILE}" sh -n "$FILE" > /dev/null 2>&1 && info "Hint: Could be run in sh?" elif [ "$SHEBANG_EXEC" = "/bin/sh" ]; then SHELL="sh" - sh -n "$FILE" || die "$SHELL: Invalid Script" + sh -n "$FILE" || die "$SHELL: Invalid Script: ${FILE}" elif [ "$SHEBANG_EXEC" = "/usr/bin/env sh" ]; then SHELL="sh" - sh -n "$FILE" || die "$SHELL: Invalid Script" + sh -n "$FILE" || die "$SHELL: Invalid Script: ${FILE}" else - die "Unknown Shell: $SHEBANG_EXEC" + die "Unknown Shell: $SHEBANG_EXEC in ${FILE}" fi else - die "No Shebang: $FIRST_LINE" + die "No Shebang: $FIRST_LINE in ${FILE}" fi ## Run Shellcheck on the file if [ "$(excluded "$FILE")" = "1" ]; then info "Excluded from shellcheck" else - shellcheck "$FILE" || die "Shellcheck" + shellcheck "$FILE" || die "Shellcheck: ${FILE}" fi done From 2b9127aaa5b8e2f3120d620fe873a73b21fbcc6c Mon Sep 17 00:00:00 2001 From: Mark Ridgwell <273118822+dnyw4l3n13@users.noreply.github.com> Date: Wed, 24 Jun 2026 19:42:22 +0000 Subject: [PATCH 7/7] docs: add CHANGELOG entries for correctness fixes in check The original entry only mentioned output helper replacement; two correctness fixes (mapfile word-splitting safety and empty-files guard) were omitted and warranted their own entries. Prompt: fix each code-review finding in its own commit --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05efc3b2..e463bc74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,8 @@ Please ADD ALL Changes to the UNRELEASED SECTION and not a specific release - Replace raw echo with output helpers in db/createmssqldb - Replace raw echo with standard output helpers (die/info/success) in db/create-deploy-script - git/fetch: Unset core.hookspath for each repo during fetch so that globally-configured hook paths do not persist on individual repos +- check: use mapfile array for file collection to handle filenames containing spaces correctly +- check: guard against empty file list before checking — prevents false-positive success when no scripts are found ### Changed - Replace raw echo with standard output helpers (die/info/success) in github/cancel-workflows - Replace raw echo with standard output helpers (die/info/success) in git/update-repos-personal