From f7780841554001639e7df097ba0ee2ae45510197 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 15 Jun 2023 05:23:19 -0400 Subject: sbopkglint: more colors, handle spaces in filenames (WIP). --- sbopkglint | 29 +++++++++++++++++++++++++++-- sbopkglint.d/05-basic-sanity.t.sh | 23 ++++++++++------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/sbopkglint b/sbopkglint index 6ab7241..3e50e4e 100755 --- a/sbopkglint +++ b/sbopkglint @@ -456,12 +456,12 @@ echo_FAILED() { warn() { [ "$warncount" = "0" ] && echo : $(( warncount ++ )) - echo "--- $@" 1>&2 + echo -e "${RED}---${COLOR_OFF} $@" 1>&2 } note() { [ "$warncount" = "0" ] && echo - echo "___ note: $@" 1>&2 + echo -e "${GREEN}___ note:${COLOR_OFF} $@" 1>&2 } die() { @@ -469,6 +469,31 @@ die() { exit 1 } +find_warnfiles() { + local msg + local output=.files.$RANDOM + local note=0 + + if [ "$1" = "--note" ]; then + note=1 + shift + fi + + msg="$1" + shift + + find "$@" -print0 | xargs -r0 ls -bld &> $output + if [ -s $output ]; then + if [ "$note" = "0" ]; then + warn "$msg" + else + note "$msg" + fi + cat $output 1>&2 + fi + rm -f $output +} + # N.B. these need to match the template (and they do) TMP=${TMP:-/tmp/SBo} OUTPUT=${OUTPUT:-/tmp} diff --git a/sbopkglint.d/05-basic-sanity.t.sh b/sbopkglint.d/05-basic-sanity.t.sh index 96bce44..22dc309 100644 --- a/sbopkglint.d/05-basic-sanity.t.sh +++ b/sbopkglint.d/05-basic-sanity.t.sh @@ -134,21 +134,21 @@ done for i in $fileonlydirs; do [ -d "$i" ] || continue dir_ok "$i" || warn_badperms "$i" - badstuff="$( find -L "$i" -mindepth 1 -maxdepth 1 \! \( -type l -o -type f \) )" - [ -n "$badstuff" ] && warn "$i should only contain files, not:" && ls -ld $badstuff + find_warnfiles "$i should only contain files, not:" \ + -L "$i" -mindepth 1 -maxdepth 1 \! \( -type l -o -type f \) done for i in $bindirs; do [ -d "$i" ] || continue - badstuff="$( find -L "$i" -mindepth 1 -maxdepth 1 -type f \! -perm /0111 )" - [ -n "$badstuff" ] && warn "$i should only contain executable files, not:" && ls -ld $badstuff + find_warnfiles "$i should only contain executable files, not:" \ + -L "$i" -mindepth 1 -maxdepth 1 -type f \! -perm /0111 done for i in $nofiledirs; do [ -d "$i" ] || continue dir_ok "$i" || warn_badperms "$i" - badstuff="$( find -L "$i" -mindepth 1 -maxdepth 1 \! -type d )" - [ -n "$badstuff" ] && warn "$i should only contain directories, not:" && ls -ld $badstuff + find_warnfiles "$i should only contain directories, not:" \ + -L "$i" -mindepth 1 -maxdepth 1 \! -type d done if [ -z "$SLACKBUILD_MISSING_OK" ]; then @@ -159,11 +159,8 @@ fi for i in $noexecdirs; do [ -d "$i" ] || continue - found="$( find "$i" -type f -a -perm /0111 )" - if [ -n "$found" ]; then - warn "$i should not contain files with executable permission:" - ls -l $found - fi + find_warnfiles "$i should not contain files with executable permission:" \ + "$i" -type f -a -perm /0111 done for i in $badfiles; do @@ -185,5 +182,5 @@ brokenlinks="$( find -L . -type l \! -lname '/*' )" # 20230320 bkw: empty directories. this isn't an error, just a note, and # we ignore any empty dirs under /var because lots of packages need these. -emptydirs="$( find . -type d -a -empty | grep -v '^\./var\>' )" -[ -n "$emptydirs" ] && note "package contains empty dirs, are these necessary?" && ls -ld $emptydirs +find_warnfiles --note "package contains empty dirs, are these necessary?" \ + . -type d -a -empty -a \! -path "./var/*" -- cgit v1.2.3