aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsbopkglint6
-rw-r--r--sbopkglint.d/30-manpages.t.sh6
-rw-r--r--sbopkglint.d/60-usr_info.t.sh11
3 files changed, 10 insertions, 13 deletions
diff --git a/sbopkglint b/sbopkglint
index fd458c4..2e86174 100755
--- a/sbopkglint
+++ b/sbopkglint
@@ -584,6 +584,12 @@ find_warnfiles() {
rm -f $output
}
+# return true if the file is gzipped, otherwise false.
+# faster than using file(1).
+is_gzipped() {
+ [ "$( hexdump -n 2 -e '"%2x"' "$1" )" = '8b1f' ]
+}
+
# N.B. these need to match the template (and they do)
TMP=${TMP:-/tmp/SBo}
OUTPUT=${OUTPUT:-/tmp}
diff --git a/sbopkglint.d/30-manpages.t.sh b/sbopkglint.d/30-manpages.t.sh
index 4264d86..0bc4a96 100644
--- a/sbopkglint.d/30-manpages.t.sh
+++ b/sbopkglint.d/30-manpages.t.sh
@@ -35,9 +35,7 @@ check_gzipped_page() {
BADPERMS+="$f "
fi
- if [ "$( file -L -b --mime-type "$f" )" != "application/gzip" ]; then
- NOTGZIPPED+="$f "
- fi
+ is_gzipped "$f" || NOTGZIPPED+="$f "
# I have ~42,000 man pages on my dev box, file(1) fails to identify
# 12 of them as troff, but adding the check for .T catches them all.
@@ -134,7 +132,7 @@ if [ -d usr/man ]; then
[ -n "$BADDIRPERMS" ] && warn "bad man directory owner/permissions (should be 0755, root:root)" && ls -ld $BADDIRPERMS
[ -n "$BADDIRS" ] && warn "bad directory names in /usr/man:" && ls -ld $BADDIRS
[ -n "$BADNAMES" ] && warn "bad man page names (not *.gz):" && ls -ld $BADNAMES
- [ -n "$NOTGZIPPED" ] && warn "non-gzip (but named *.gz) man pages:" && ls -ld $NOTGZIPPED
+ [ -n "$NOTGZIPPED" ] && warn "non-gzipiped (but named *.gz) man pages:" && ls -ld $NOTGZIPPED
[ -n "$NONTROFF" ] && warn "invalid man pages (not troff):" && ls -ld $NONTROFF
[ -n "$WRONGSECT" ] && warn "man pages in wrong section:" && ls -ld $WRONGSECT
fi
diff --git a/sbopkglint.d/60-usr_info.t.sh b/sbopkglint.d/60-usr_info.t.sh
index b839180..3f3ffd5 100644
--- a/sbopkglint.d/60-usr_info.t.sh
+++ b/sbopkglint.d/60-usr_info.t.sh
@@ -36,18 +36,11 @@ NONINFO=""
NONGZIP=""
# 2 args: $1 is the file to check, $2 is 1 for .gz name, 0 otherwise.
-# The LANG=C is because we're grepping for raw bytes, not characters
-# in e.g. UTF-8 encoding. Believe it or not, using head and grep is
-# quite a bit faster than using the file command... though we could
-# make file faster with "file -m /etc/file/magic/compress".
check_info() {
- local is_gzip=0
- head -c2 "$1" | LANG=C grep -Pq '\x1f\x8b' && is_gzip=1
-
if [ "$2" = 0 ]; then
- [ "$is_gzip" = "1" ] && warn "$i is gzipped but lacks .gz extension"
+ is_gzipped "$1" && warn "$i is gzipped but lacks .gz extension"
else
- [ "$is_gzip" = "0" ] && warn "$i has .gz extension but is not gzipped"
+ is_gzipped "$1" || warn "$i has .gz extension but is not gzipped"
fi
LANG=C zgrep -Pq '\x1f' "$1" || NONINFO+="$1 "