Turn shellcheck into a normal make target. Fix new files it caught

This checks every file it checked (and a few more),
but explicitly instead of "if it works it works" best-effort
(which wasn't that good anyway)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #10512
Closes #12101
This commit is contained in:
наб
2021-05-21 23:43:38 +02:00
committed by Brian Behlendorf
parent d6f8f41c21
commit 132240507d
39 changed files with 213 additions and 107 deletions
+4
View File
@@ -1,3 +1,5 @@
include $(top_srcdir)/config/Shellcheck.am
SUBDIRS = bash_completion.d pyzfs zcp
if BUILD_LINUX
SUBDIRS += bpftrace dracut initramfs
@@ -6,3 +8,5 @@ if PAM_ZFS_ENABLED
SUBDIRS += pam_zfs_key
endif
DIST_SUBDIRS = bash_completion.d bpftrace dracut initramfs pam_zfs_key pyzfs zcp
SHELLCHECKDIRS = bash_completion.d bpftrace dracut initramfs
+5
View File
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am
bashcompletiondir = $(sysconfdir)/bash_completion.d
@@ -6,3 +7,7 @@ noinst_DATA = zfs
EXTRA_DIST += $(noinst_DATA)
SUBSTFILES += $(noinst_DATA)
SHELLCHECKSCRIPTS = $(noinst_DATA)
SHELLCHECK_SHELL = bash
SHELLCHECK_IGNORE = ,SC2207
+14 -9
View File
@@ -139,6 +139,7 @@ __zfs_match_multiple_snapshots()
fi
local range_start
range_start="$(expr "$cur" : '\(.*%\)')"
# shellcheck disable=SC2016
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset" | sed 's$.*@$'"$range_start"'$g'
fi
else
@@ -163,7 +164,7 @@ __zfs_argument_chosen()
then
return 0
fi
for property in $@
for property in "$@"
do
if [[ $prev == "$property"* ]]
then
@@ -181,6 +182,7 @@ __zfs_complete_ordered_arguments()
local list2=$2
local cur=$3
local extra=$4
# shellcheck disable=SC2086
if __zfs_argument_chosen $list1
then
COMPREPLY=($(compgen -W "$list2 $extra" -- "$cur"))
@@ -193,9 +195,10 @@ __zfs_complete_multiple_options()
{
local options=$1
local cur=$2
local existing_opts
COMPREPLY=($(compgen -W "$options" -- "${cur##*,}"))
local existing_opts=$(expr "$cur" : '\(.*,\)')
existing_opts=$(expr "$cur" : '\(.*,\)')
if [[ $existing_opts ]]
then
COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" )
@@ -290,6 +293,7 @@ __zfs_complete()
*)
if ! __zfs_complete_switch "H,r,p,d,o,t,s"
then
# shellcheck disable=SC2046
if __zfs_argument_chosen $(__zfs_get_properties)
then
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
@@ -303,7 +307,7 @@ __zfs_complete()
inherit)
if ! __zfs_complete_switch "r"
then
__zfs_complete_ordered_arguments "$(__zfs_get_inheritable_properties)" "$(__zfs_match_snapshot)" $cur
__zfs_complete_ordered_arguments "$(__zfs_get_inheritable_properties)" "$(__zfs_match_snapshot)" "$cur"
fi
;;
list)
@@ -369,7 +373,7 @@ __zfs_complete()
esac
;;
set)
__zfs_complete_ordered_arguments "$(__zfs_get_editable_properties)" "$(__zfs_match_snapshot)" $cur
__zfs_complete_ordered_arguments "$(__zfs_get_editable_properties)" "$(__zfs_match_snapshot)" "$cur"
__zfs_complete_nospace
;;
upgrade)
@@ -388,7 +392,7 @@ __zfs_complete()
destroy)
if ! __zfs_complete_switch "d,f,n,p,R,r,v"
then
__zfs_complete_multiple_options "$(__zfs_match_multiple_snapshots)" $cur
__zfs_complete_multiple_options "$(__zfs_match_multiple_snapshots)" "$cur"
__zfs_complete_nospace
fi
;;
@@ -425,7 +429,7 @@ __zpool_list_pools()
__zpool_complete()
{
local cur prev cmd cmds
local cur prev cmd cmds pools
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
@@ -440,7 +444,7 @@ __zpool_complete()
case "${cmd}" in
get)
__zfs_complete_ordered_arguments "$(__zpool_get_properties)" "$(__zpool_list_pools)" $cur
__zfs_complete_ordered_arguments "$(__zpool_get_properties)" "$(__zpool_list_pools)" "$cur"
return 0
;;
import)
@@ -453,12 +457,13 @@ __zpool_complete()
return 0
;;
set)
__zfs_complete_ordered_arguments "$(__zpool_get_editable_properties)" "$(__zpool_list_pools)" $cur
__zfs_complete_ordered_arguments "$(__zpool_get_editable_properties)" "$(__zpool_list_pools)" "$cur"
__zfs_complete_nospace
return 0
;;
add|attach|clear|create|detach|offline|online|remove|replace)
local pools="$(__zpool_list_pools)"
pools="$(__zpool_list_pools)"
# shellcheck disable=SC2086
if __zfs_argument_chosen $pools
then
_filedir
+4
View File
@@ -1,3 +1,7 @@
include $(top_srcdir)/config/Shellcheck.am
EXTRA_DIST = \
taskqlatency.bt \
zfs-trace.sh
SHELLCHECKSCRIPTS = zfs-trace.sh
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am
pkgdracutdir = $(dracutdir)/modules.d/02zfsexpandknowledge
pkgdracut_SCRIPTS = \
+1
View File
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am
pkgdracutdir = $(dracutdir)/modules.d/90zfs
pkgdracut_SCRIPTS = \
+3
View File
@@ -1,3 +1,6 @@
include $(top_srcdir)/config/Shellcheck.am
SUBDIRS = 02zfsexpandknowledge 90zfs
SHELLCHECKDIRS = $(SUBDIRS)
EXTRA_DIST = README.dracut.markdown
+3
View File
@@ -1,9 +1,12 @@
include $(top_srcdir)/config/Shellcheck.am
initrddir = /usr/share/initramfs-tools
dist_initrd_SCRIPTS = \
zfsunlock
SUBDIRS = conf.d conf-hooks.d hooks scripts
SHELLCHECKDIRS = hooks scripts
EXTRA_DIST = \
README.initramfs.markdown
+1
View File
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am
hooksdir = /usr/share/initramfs-tools/hooks
+6 -1
View File
@@ -1,6 +1,11 @@
include $(top_srcdir)/config/Shellcheck.am
scriptsdir = /usr/share/initramfs-tools/scripts
dist_scripts_DATA = \
dist_scripts_SCRIPTS = \
zfs
SUBDIRS = local-top
SHELLCHECKDIRS = $(SUBDIRS)
SHELLCHECK_SHELL = sh
@@ -1,3 +1,5 @@
include $(top_srcdir)/config/Shellcheck.am
localtopdir = /usr/share/initramfs-tools/scripts/local-top
dist_localtop_SCRIPTS = \
+31 -27
View File
@@ -5,6 +5,8 @@
#
# Enable this by passing boot=zfs on the kernel command line.
#
# $quiet, $root, $rpool, $bootfs come from the cmdline:
# shellcheck disable=SC2154
# Source the common functions
. /etc/zfs/zfs-functions
@@ -102,14 +104,10 @@ find_rootfs()
# Support function to get a list of all pools, separated with ';'
find_pools()
{
CMD="$*"
pools=$($CMD 2> /dev/null | \
pools=$("$@" 2> /dev/null | \
grep -E "pool:|^[a-zA-Z0-9]" | \
sed 's@.*: @@' | \
while read -r pool; do \
printf "%s" "$pool;"
done)
tr '\n' ';')
echo "${pools%%;}" # Return without the last ';'.
}
@@ -203,7 +201,7 @@ import_pool()
# exists).
if [ -n "$USE_DISK_BY_ID" ] && [ -z "$ZPOOL_IMPORT_PATH" ]
then
dirs="$(for dir in $(echo /dev/disk/by-*)
dirs="$(for dir in /dev/disk/by-*
do
# Ignore by-vdev here - we want it first!
echo "$dir" | grep -q /by-vdev && continue
@@ -329,6 +327,7 @@ mount_fs()
# Need the _original_ datasets mountpoint!
mountpoint=$(get_fs_value "$fs" mountpoint)
ZFS_CMD="mount -o zfsutil -t zfs"
if [ "$mountpoint" = "legacy" ] || [ "$mountpoint" = "none" ]; then
# Can't use the mountpoint property. Might be one of our
# clones. Check the 'org.zol:mountpoint' property set in
@@ -348,15 +347,11 @@ mount_fs()
fi
fi
# If it's not a legacy filesystem, it can only be a
# native one...
if [ "$mountpoint" = "legacy" ]; then
ZFS_CMD="mount -t zfs"
else
# If it's not a legacy filesystem, it can only be a
# native one...
ZFS_CMD="mount -o zfsutil -t zfs"
fi
else
ZFS_CMD="mount -o zfsutil -t zfs"
fi
# Possibly decrypt a filesystem using native encryption.
@@ -556,7 +551,6 @@ rollback_snap()
ask_user_snap()
{
fs="$1"
i=1
# We need to temporarily disable debugging. Set 'debug' so we
# remember to enabled it again.
@@ -569,16 +563,25 @@ ask_user_snap()
# Because we need the resulting snapshot, which is sent on
# stdout to the caller, we use stderr for our questions.
echo "What snapshot do you want to boot from?" > /dev/stderr
while read -r snap; do
echo " $i: ${snap}" > /dev/stderr
eval "$(echo SNAP_$i=$snap)"
i=$((i + 1))
done <<EOT
$("${ZFS}" list -H -oname -tsnapshot -r "${fs}")
EOT
# shellcheck disable=SC2046
IFS="
" set -- $("${ZFS}" list -H -oname -tsnapshot -r "${fs}")
echo "%s" " Snap nr [1-$((i-1))]? " > /dev/stderr
read -r snapnr
i=1
for snap in "$@"; do
echo " $i: $snap"
i=$((i + 1))
done > /dev/stderr
# expr instead of test here because [ a -lt 0 ] errors out,
# but expr falls back to lexicographical, which works out right
snapnr=0
while expr "$snapnr" "<" 1 > /dev/null ||
expr "$snapnr" ">" "$#" > /dev/null
do
printf "%s" "Snap nr [1-$#]? " > /dev/stderr
read -r snapnr
done
# Re-enable debugging.
if [ -n "${debug}" ]; then
@@ -586,7 +589,7 @@ EOT
set -x
fi
echo "$(eval echo '$SNAP_'$snapnr)"
eval echo '$'"$snapnr"
}
setup_snapshot_booting()
@@ -706,7 +709,7 @@ mountroot()
# ------------
# Look for the cache file (if any).
[ ! -f ${ZPOOL_CACHE} ] && unset ZPOOL_CACHE
[ ! -f "${ZPOOL_CACHE}" ] && unset ZPOOL_CACHE
# ------------
# Compatibility: 'ROOT' is for Debian GNU/Linux (etc),
@@ -796,7 +799,8 @@ mountroot()
#
# Reassign the variable by dumping the environment and
# stripping the zfs-bootfs= prefix. Let the shell handle
# quoting through the eval command.
# quoting through the eval command:
# shellcheck disable=SC2046
eval ZFS_RPOOL=$(set | sed -n -e 's,^zfs-bootfs=,,p')
fi
@@ -950,7 +954,7 @@ mountroot()
touch /run/zfs_unlock_complete
if [ -e /run/zfs_unlock_complete_notify ]; then
read -r zfs_unlock_complete_notify < /run/zfs_unlock_complete_notify
read -r < /run/zfs_unlock_complete_notify
fi
# ------------