From 64025fa3a1f0f710f7f8678f2ac459b07ed9f88f Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Thu, 20 Aug 2020 13:45:47 -0700 Subject: [PATCH] Silence 'make checkbashisms' Commit d2bce6d03 added the 'make checkbashisms' target but did not resolve all of the bashisms in the scripts. This commit doesn't resolve them all either but it does fix up a few, and it excludes the others so 'make checkstyle' no longer prints warnings. It's a small step in the right direction. * Dracut is Linux specific and itself depends on bash. Therefore all dracut support scripts can be bash specific, update their shebang accordingly. * zed-functions.sh, zfs-import, zfs-mount, zfs-zed, smart paxcheck.sh, make_gitrev.sh - these scripts were excuded from the check until they can be updated and properly tested. * zfsunlock - only whole values for sleep are allowed. * vdev_id - removed unneeded locals; use && instead of -a. * dkms.mkconf, dkms.postbuil - use || instead of -o. Reviewed-by: InsanePrawn Reviewed-by: Gabriel A. Devenyi Reviewed-by: Ryan Moeller Reviewed-by: George Melikov Signed-off-by: Brian Behlendorf Closes #10755 --- Makefile.am | 7 +++++++ cmd/vdev_id/vdev_id | 17 ++++++++--------- contrib/dracut/90zfs/export-zfs.sh.in | 2 +- contrib/dracut/90zfs/mount-zfs.sh.in | 2 +- contrib/dracut/90zfs/parse-zfs.sh.in | 2 +- contrib/dracut/90zfs/zfs-lib.sh.in | 2 +- contrib/dracut/90zfs/zfs-load-key.sh.in | 2 +- contrib/dracut/90zfs/zfs-needshutdown.sh.in | 2 +- contrib/initramfs/zfsunlock | 4 ++-- scripts/dkms.mkconf | 2 +- scripts/dkms.postbuild | 4 ++-- 11 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Makefile.am b/Makefile.am index 840604c232..b409d2196f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -145,6 +145,13 @@ checkbashisms: -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 -type f ! -name 'config*' \ ! -name 'libtool' \ -exec bash -c 'awk "NR==1 && /\#\!.*bin\/sh.*/ {print FILENAME;}" "{}"' \;); \ diff --git a/cmd/vdev_id/vdev_id b/cmd/vdev_id/vdev_id index a79aed3b5d..8a75e638b6 100755 --- a/cmd/vdev_id/vdev_id +++ b/cmd/vdev_id/vdev_id @@ -114,9 +114,8 @@ EOF } map_slot() { - local LINUX_SLOT=$1 - local CHANNEL=$2 - local MAPPED_SLOT= + LINUX_SLOT=$1 + CHANNEL=$2 MAPPED_SLOT=`awk "\\$1 == \"slot\" && \\$2 == ${LINUX_SLOT} && \ \\$4 ~ /^${CHANNEL}$|^$/ { print \\$3; exit }" $CONFIG` @@ -127,9 +126,9 @@ map_slot() { } map_channel() { - local MAPPED_CHAN= - local PCI_ID=$1 - local PORT=$2 + MAPPED_CHAN= + PCI_ID=$1 + PORT=$2 case $TOPOLOGY in "sas_switch") @@ -487,7 +486,7 @@ alias_handler () { # digits as partitions, causing alias creation to fail. This # ambiguity seems unavoidable, so devices using this facility # must not use such names. - local DM_PART= + DM_PART= if echo $DM_NAME | grep -q -E 'p[0-9][0-9]*$' ; then if [ "$DEVTYPE" != "partition" ] ; then DM_PART=`echo $DM_NAME | awk -Fp '/p/{print "-part"$2}'` @@ -549,7 +548,7 @@ if [ ! -r $CONFIG ] ; then exit 0 fi -if [ -z "$DEV" -a -z "$ENCLOSURE_MODE" ] ; then +if [ -z "$DEV" ] && [ -z "$ENCLOSURE_MODE" ] ; then echo "Error: missing required option -d" exit 1 fi @@ -565,7 +564,7 @@ fi TOPOLOGY=${TOPOLOGY:-sas_direct} # Should we create /dev/by-enclosure symlinks? -if [ "$ENCLOSURE_MODE" = "yes" -a "$TOPOLOGY" = "sas_direct" ] ; then +if [ "$ENCLOSURE_MODE" = "yes" ] && [ "$TOPOLOGY" = "sas_direct" ] ; then ID_ENCLOSURE=$(enclosure_handler) if [ -z "$ID_ENCLOSURE" ] ; then exit 0 diff --git a/contrib/dracut/90zfs/export-zfs.sh.in b/contrib/dracut/90zfs/export-zfs.sh.in index 8926503834..09e4a3cc0e 100755 --- a/contrib/dracut/90zfs/export-zfs.sh.in +++ b/contrib/dracut/90zfs/export-zfs.sh.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash . /lib/dracut-zfs-lib.sh diff --git a/contrib/dracut/90zfs/mount-zfs.sh.in b/contrib/dracut/90zfs/mount-zfs.sh.in index 73300a9b66..f5b3d9056c 100755 --- a/contrib/dracut/90zfs/mount-zfs.sh.in +++ b/contrib/dracut/90zfs/mount-zfs.sh.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash . /lib/dracut-zfs-lib.sh diff --git a/contrib/dracut/90zfs/parse-zfs.sh.in b/contrib/dracut/90zfs/parse-zfs.sh.in index eccfdc6bcb..6a805ae24a 100755 --- a/contrib/dracut/90zfs/parse-zfs.sh.in +++ b/contrib/dracut/90zfs/parse-zfs.sh.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash . /lib/dracut-lib.sh diff --git a/contrib/dracut/90zfs/zfs-lib.sh.in b/contrib/dracut/90zfs/zfs-lib.sh.in index 44021c6e5f..f470bfcc54 100755 --- a/contrib/dracut/90zfs/zfs-lib.sh.in +++ b/contrib/dracut/90zfs/zfs-lib.sh.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v getargbool >/dev/null || { diff --git a/contrib/dracut/90zfs/zfs-load-key.sh.in b/contrib/dracut/90zfs/zfs-load-key.sh.in index 85e55c51bf..ff586ef654 100755 --- a/contrib/dracut/90zfs/zfs-load-key.sh.in +++ b/contrib/dracut/90zfs/zfs-load-key.sh.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # only run this on systemd systems, we handle the decrypt in mount-zfs.sh in the mount hook otherwise [ -e /bin/systemctl ] || return 0 diff --git a/contrib/dracut/90zfs/zfs-needshutdown.sh.in b/contrib/dracut/90zfs/zfs-needshutdown.sh.in index e3d1b59cca..ddd3edae00 100755 --- a/contrib/dracut/90zfs/zfs-needshutdown.sh.in +++ b/contrib/dracut/90zfs/zfs-needshutdown.sh.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh diff --git a/contrib/initramfs/zfsunlock b/contrib/initramfs/zfsunlock index f6b6b9dbe1..cf8e452490 100755 --- a/contrib/initramfs/zfsunlock +++ b/contrib/initramfs/zfsunlock @@ -8,7 +8,7 @@ while [ ! -e /run/zfs_fs_name ]; do if [ -e /run/zfs_unlock_complete ]; then exit 0 fi - sleep 0.5 + sleep 1 done echo echo "Unlocking encrypted ZFS filesystems..." @@ -31,7 +31,7 @@ while [ ! -e /run/zfs_unlock_complete ]; do fi # Wait for another filesystem to unlock. while [ "$(cat /run/zfs_fs_name)" = "$zfs_fs_name" ] && [ ! -e /run/zfs_unlock_complete ]; do - sleep 0.5 + sleep 1 done else echo "Wrong password. Try again." diff --git a/scripts/dkms.mkconf b/scripts/dkms.mkconf index 8c55559733..28d9609f72 100755 --- a/scripts/dkms.mkconf +++ b/scripts/dkms.mkconf @@ -13,7 +13,7 @@ while getopts "n:v:c:f:" opt; do esac done -if [ -z "${pkgname}" -o -z "${pkgver}" -o -z "${filename}" ]; then +if [ -z "${pkgname}" ] || [ -z "${pkgver}" ] || [ -z "${filename}" ]; then echo "Usage: $PROG -n -v -c -f " exit 1 fi diff --git a/scripts/dkms.postbuild b/scripts/dkms.postbuild index 299c02d6ec..81de475877 100755 --- a/scripts/dkms.postbuild +++ b/scripts/dkms.postbuild @@ -12,8 +12,8 @@ while getopts "a:k:n:t:v:" opt; do esac done -if [ -z "${arch}" -o -z "${kver}" -o -z "${pkgname}" -o \ - -z "${tree}" -o -z "${pkgver}" ]; then +if [ -z "${arch}" ] || [ -z "${kver}" ] || [ -z "${pkgname}" ] || \ + [ -z "${tree}" ] || [ -z "${pkgver}" ]; then echo "Usage: $PROG -a -k -n " \ "-t -v " exit 1