Path: blob/main/sys/contrib/openzfs/scripts/mancheck.sh
48266 views
#!/bin/sh1#2# Permission to use, copy, modify, and/or distribute this software for3# any purpose with or without fee is hereby granted.4#5# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES6# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF7# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR8# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES9# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN10# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT11# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.12#13# shellcheck disable=SC2068,SC20861415trap 'rm -f "$stdout_file" "$stderr_file" "$result_file"' EXIT1617if [ "$#" -eq 0 ]; then18echo "Usage: $0 <manpage-directory|manpage-file>..."19exit 120fi2122if ! command -v mandoc > /dev/null; then23echo "skipping mancheck because mandoc is not installed"24exit 025fi2627IFS="28"29files="$(30for path in $@ ; do31find -L $path -type f -name '*[1-9]*' -not -name '.*'32done | sort | uniq33)"3435if [ "$files" = "" ] ; then36echo no files to process! 1>&237exit 138fi3940add_excl="$(awk '41/^.\\" lint-ok:/ {42print "-e"43$1 = "mandoc:"44$2 = FILENAME ":[[:digit:]]+:[[:digit:]]+:"4546}' $files)"4748# Redirect to file instead of 2>&1ing because mandoc flushes inconsistently(?) which tears lines49# https://github.com/openzfs/zfs/pull/12129/checks?check_run_id=2701608671#step:5:350stdout_file="$(mktemp)"51stderr_file="$(mktemp)"52mandoc -Tlint $files 1>"$stdout_file" 2>"$stderr_file"53result_file="$(mktemp)"54grep -vhE -e 'mandoc: outdated mandoc.db' -e 'STYLE: referenced manual not found' $add_excl "$stdout_file" "$stderr_file" > "$result_file"5556if [ -s "$result_file" ]; then57cat "$result_file"58exit 159fi606162