1#!/bin/sh 2# 3# Permission to use, copy, modify, and/or distribute this software for 4# any purpose with or without fee is hereby granted. 5# 6# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 7# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 8# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 9# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 10# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 11# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 12# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 13# 14# shellcheck disable=SC2068,SC2086 15 16trap 'rm -f "$stdout_file" "$stderr_file" "$result_file"' EXIT 17 18if [ "$#" -eq 0 ]; then 19 echo "Usage: $0 <manpage-directory|manpage-file>..." 20 exit 1 21fi 22 23if ! command -v mandoc > /dev/null; then 24 echo "skipping mancheck because mandoc is not installed" 25 exit 0 26fi 27 28IFS=" 29" 30files="$( 31 for path in $@ ; do 32 find -L $path -type f -name '*[1-9]*' -not -name '.*' 33 done | sort | uniq 34)" 35 36if [ "$files" = "" ] ; then 37 echo no files to process! 1>&2 38 exit 1 39fi 40 41add_excl="$(awk ' 42 /^.\\" lint-ok:/ { 43 print "-e" 44 $1 = "mandoc:" 45 $2 = FILENAME ":[[:digit:]]+:[[:digit:]]+:" 46 print 47 }' $files)" 48 49# Redirect to file instead of 2>&1ing because mandoc flushes inconsistently(?) which tears lines 50# https://github.com/openzfs/zfs/pull/12129/checks?check_run_id=2701608671#step:5:3 51stdout_file="$(mktemp)" 52stderr_file="$(mktemp)" 53mandoc -Tlint $files 1>"$stdout_file" 2>"$stderr_file" 54result_file="$(mktemp)" 55grep -vhE -e 'mandoc: outdated mandoc.db' -e 'STYLE: referenced manual not found' $add_excl "$stdout_file" "$stderr_file" > "$result_file" 56 57if [ -s "$result_file" ]; then 58 cat "$result_file" 59 exit 1 60fi 61