diff --git a/Makefile.am b/Makefile.am index 4fd3f9b3d..8e4fffc5d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -135,31 +135,6 @@ checkabi: lib storeabi: lib $(MAKE) -C lib storeabi -PHONY += checkbashisms -checkbashisms: - @if type checkbashisms > /dev/null 2>&1; then \ - checkbashisms -n -p -x \ - $$(find ${top_srcdir} \ - -name '.git' -prune \ - -o -name 'build' -prune \ - -o -name 'tests' -prune \ - -o -name 'config' -prune \ - -o -name 'zed-functions.sh*' -prune \ - -o -name 'zfs-import*' -prune \ - -o -name 'zfs-mount*' -prune \ - -o -name 'zfs-zed*' -prune \ - -o -name 'smart' -prune \ - -o -name 'paxcheck.sh' -prune \ - -o -name 'make_gitrev.sh' -prune \ - -o -name '90zfs' -prune \ - -o -path '*initramfs/hooks' -prune \ - -o -type f ! -name 'config*' \ - ! -name 'libtool' \ - -exec awk 'FNR==1 && /^#!.*bin\/sh/ {print FILENAME}' {} \+); \ - else \ - echo "skipping checkbashisms because checkbashisms is not installed"; \ - fi - PHONY += mancheck mancheck: @if type mandoc > /dev/null 2>&1; then \ diff --git a/cmd/zpool/zpool.d/smart b/cmd/zpool/zpool.d/smart index b71591abb..b95256d75 100755 --- a/cmd/zpool/zpool.d/smart +++ b/cmd/zpool/zpool.d/smart @@ -62,17 +62,14 @@ get_filename_from_dir() done } -script=$(basename "$0") +script="${0##*/}" if [ "$1" = "-h" ] ; then echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2- exit fi -smartctl_path=$(command -v smartctl) - -# shellcheck disable=SC2015 -if [ -b "$VDEV_UPATH" ] && [ -x "$smartctl_path" ] || [ -n "$samples" ] ; then +if [ -b "$VDEV_UPATH" ] && PATH="/usr/sbin:$PATH" command -v smartctl > /dev/null || [ -n "$samples" ] ; then if [ -n "$samples" ] ; then # cat a smartctl output text file instead of running smartctl # on a vdev (only used for developer testing). @@ -80,7 +77,7 @@ if [ -b "$VDEV_UPATH" ] && [ -x "$smartctl_path" ] || [ -n "$samples" ] ; then echo "file=$file" raw_out=$(cat "$samples/$file") else - raw_out=$(eval "sudo $smartctl_path -a $VDEV_UPATH") + raw_out=$(sudo smartctl -a "$VDEV_UPATH") fi # What kind of drive are we? Look for the right line in smartctl: diff --git a/config/Shellcheck.am b/config/Shellcheck.am index a22333ac4..6b805b797 100644 --- a/config/Shellcheck.am +++ b/config/Shellcheck.am @@ -6,3 +6,17 @@ else @[ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; echo "skipping shellcheck of" $(SCRIPTS) $(SHELLCHECKSCRIPTS) "because shellcheck is not installed" endif @set -e; for dir in $(SHELLCHECKDIRS); do $(MAKE) -C $$dir shellcheck; done + + +# command -v *is* specified by POSIX and every shell in existence supports it +.PHONY: checkbashisms +checkbashisms: $(SCRIPTS) $(SHELLCHECKSCRIPTS) +if HAVE_CHECKBASHISMS + [ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; ! if [ -z "$(SHELLCHECK_SHELL)" ]; then \ + checkbashisms -npx $(SCRIPTS) $(SHELLCHECKSCRIPTS); else \ + for f in $(SCRIPTS) $(SHELLCHECKSCRIPTS); do echo $$f >&3; { echo '#!/bin/$(SHELLCHECK_SHELL)'; cat $$f; } | checkbashisms -npx; done; \ + fi 3>&2 2>&1 | grep -vFe "'command' with option other than -p" -e 'command -v' $(CHECKBASHISMS_IGNORE) >&2 +else + @[ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; echo "skipping checkbashisms of" $(SCRIPTS) $(SHELLCHECKSCRIPTS) "because checkbashisms is not installed" +endif + @set -e; for dir in $(SHELLCHECKDIRS); do $(MAKE) -C $$dir checkbashisms; done diff --git a/config/always-shellcheck.m4 b/config/always-shellcheck.m4 index 1e154e1c5..2a9a09974 100644 --- a/config/always-shellcheck.m4 +++ b/config/always-shellcheck.m4 @@ -1,7 +1,10 @@ dnl # -dnl # Check if shellcheck is available. +dnl # Check if shellcheck and/or checkbashisms are available. dnl # AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_SHELLCHECK], [ AC_CHECK_PROG([SHELLCHECK], [shellcheck], [yes]) + AC_CHECK_PROG([CHECKBASHISMS], [checkbashisms], [yes]) + AM_CONDITIONAL([HAVE_SHELLCHECK], [test "x$SHELLCHECK" = "xyes"]) + AM_CONDITIONAL([HAVE_CHECKBASHISMS], [test "x$CHECKBASHISMS" = "xyes"]) ]) diff --git a/contrib/dracut/90zfs/Makefile.am b/contrib/dracut/90zfs/Makefile.am index 19b206ddd..ff3a2b27f 100644 --- a/contrib/dracut/90zfs/Makefile.am +++ b/contrib/dracut/90zfs/Makefile.am @@ -18,3 +18,6 @@ pkgdracut_DATA = \ zfs-rollback-bootfs.service SUBSTFILES += $(pkgdracut_SCRIPTS) $(pkgdracut_DATA) + +# Provided by /bin/sleep, and, again, every implementation of that supports this +CHECKBASHISMS_IGNORE = -e 'sleep only takes one integer' -e 'sleep 0.' diff --git a/scripts/make_gitrev.sh b/scripts/make_gitrev.sh index f5c743b13..da2145533 100755 --- a/scripts/make_gitrev.sh +++ b/scripts/make_gitrev.sh @@ -56,9 +56,9 @@ then # already exists (in the source) if [ -f "${top_srcdir}/${GITREV}" ] then - ZFS_GITREV="$(sed -n \ + ZFS_GITREV=$(sed -n \ '1s/^#define[[:blank:]]ZFS_META_GITREV "\([^"]*\)"$/\1/p' \ - "${top_srcdir}/${GITREV}")" + "${top_srcdir}/${GITREV}") fi elif [ ${dist} = yes ] then diff --git a/scripts/paxcheck.sh b/scripts/paxcheck.sh index 87e817500..27acc9536 100755 --- a/scripts/paxcheck.sh +++ b/scripts/paxcheck.sh @@ -1,7 +1,6 @@ #!/bin/sh -# shellcheck disable=SC2039 -if ! type scanelf > /dev/null 2>&1; then +if ! command -v scanelf > /dev/null; then echo "scanelf (from pax-utils) is required for these checks." >&2 exit 3 fi