diff --git a/CHANGELOG.md b/CHANGELOG.md index eeac92a2..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 @@ -47,6 +49,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..678bf3ba 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 } @@ -39,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 @@ -52,47 +58,51 @@ FILES=$({ \ done < <(find "$BASEDIR" -not -path '*/.*' -type f -print) || die "Search: Shebang" } | sort | uniq) -echo "Testing:" -for FILE in $FILES; do - echo "* $FILE" - testing "Executable" +[ "${#FILES[@]}" -gt 0 ] || die "No script files found in ${BASEDIR}" + +info "Testing:" +for FILE in "${FILES[@]}"; do + info "* $FILE" + info "Executable" if [ ! -x "$FILE" ]; then - fail "Not Executable" + die "Not Executable: ${FILE}" 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: ${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" || 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: ${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" || fail "$SHELL: Invalid Script" + sh -n "$FILE" || die "$SHELL: Invalid Script: ${FILE}" elif [ "$SHEBANG_EXEC" = "/usr/bin/env sh" ]; then SHELL="sh" - sh -n "$FILE" || fail "$SHELL: Invalid Script" + sh -n "$FILE" || die "$SHELL: Invalid Script: ${FILE}" else - fail "Unknown Shell: $SHEBANG_EXEC" + die "Unknown Shell: $SHEBANG_EXEC in ${FILE}" fi else - fail "No Shebang: $FIRST_LINE" + die "No Shebang: $FIRST_LINE in ${FILE}" 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: ${FILE}" fi done + +success "All checks passed"