Skip to content

Commit

Permalink
Pass --enable=all to shellcheck within contrib/
Browse files Browse the repository at this point in the history
- Remove `SHELLCHECK_IGNORE` in favor of inline suppressions
  and more general `SHELLCHECK_OPTS`.

- Exclude `SC2250` (turned on by `--enable=all`) globally

- Pass `--enable=all` to shellcheck for scripts in contrib/: it's
  very important to catch errors early in areas that are not easily
  testable.

Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: szubersk <szuberskidamian@gmail.com>
Closes openzfs#12760
  • Loading branch information
szubersk committed Nov 30, 2021
1 parent 4325de0 commit 34eef3e
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 50 deletions.
2 changes: 1 addition & 1 deletion config/Shellcheck.am
@@ -1,7 +1,7 @@
.PHONY: shellcheck
shellcheck: $(SCRIPTS) $(SHELLCHECKSCRIPTS)
if HAVE_SHELLCHECK
[ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; shellcheck $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") --exclude=SC1090,SC1091$(SHELLCHECK_IGNORE) --format=gcc $(SCRIPTS) $(SHELLCHECKSCRIPTS)
[ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; shellcheck --format=gcc --exclude=SC1090,SC1091,SC2250 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") $(SHELLCHECK_OPTS) $(SCRIPTS) $(SHELLCHECKSCRIPTS)
else
@[ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; echo "skipping shellcheck of" $(SCRIPTS) $(SHELLCHECKSCRIPTS) "because shellcheck is not installed"
endif
Expand Down
1 change: 1 addition & 0 deletions contrib/Makefile.am
Expand Up @@ -10,3 +10,4 @@ endif
DIST_SUBDIRS = bash_completion.d bpftrace dracut initramfs pam_zfs_key pyzfs zcp

SHELLCHECKDIRS = bash_completion.d bpftrace dracut initramfs
SHELLCHECK_OPTS = --enable=all
2 changes: 1 addition & 1 deletion contrib/bash_completion.d/Makefile.am
Expand Up @@ -10,4 +10,4 @@ SUBSTFILES += $(noinst_DATA)

SHELLCHECKSCRIPTS = $(noinst_DATA)
SHELLCHECK_SHELL = bash
SHELLCHECK_IGNORE = ,SC2207
SHELLCHECK_OPTS = --enable=all
60 changes: 30 additions & 30 deletions contrib/bash_completion.d/zfs.in
Expand Up @@ -185,9 +185,9 @@ __zfs_complete_ordered_arguments()
# shellcheck disable=SC2086
if __zfs_argument_chosen $list1
then
COMPREPLY=($(compgen -W "$list2 $extra" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$list2 $extra" -- "$cur")
else
COMPREPLY=($(compgen -W "$list1 $extra" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$list1 $extra" -- "$cur")
fi
}

Expand All @@ -197,9 +197,9 @@ __zfs_complete_multiple_options()
local cur=$2
local existing_opts

COMPREPLY=($(compgen -W "$options" -- "${cur##*,}"))
mapfile -t COMPREPLY < <(compgen -W "$options" -- "${cur##*,}")
existing_opts=$(expr "$cur" : '\(.*,\)')
if [[ $existing_opts ]]
if [ -n "$existing_opts" ]
then
COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" )
fi
Expand All @@ -210,7 +210,7 @@ __zfs_complete_switch()
local options=$1
if [[ ${cur:0:1} == - ]]
then
COMPREPLY=($(compgen -W "-{$options}" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "-{$options}" -- "$cur")
return 0
else
return 1
Expand Down Expand Up @@ -244,33 +244,33 @@ __zfs_complete()
if [[ ${prev##*/} == zfs ]]
then
cmds=$(__zfs_get_commands)
COMPREPLY=($(compgen -W "$cmds -?" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$cmds -?" -- "$cur")
return 0
fi

case "${cmd}" in
bookmark)
if __zfs_argument_chosen
then
COMPREPLY=($(compgen -W "${prev%@*}# ${prev/@/#}" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "${prev%@*}# ${prev/@/#}" -- "$cur")
else
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
fi
;;
clone)
case "${prev}" in
-o)
COMPREPLY=($(compgen -W "$(__zfs_get_editable_properties)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_get_editable_properties)" -- "$cur")
__zfs_complete_nospace
;;
*)
if ! __zfs_complete_switch "o,p"
then
if __zfs_argument_chosen
then
COMPREPLY=($(compgen -W "$(__zfs_list_datasets)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_list_datasets)" -- "$cur")
else
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
fi
fi
;;
Expand All @@ -279,7 +279,7 @@ __zfs_complete()
get)
case "${prev}" in
-d)
COMPREPLY=($(compgen -W "" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "" -- "$cur")
;;
-t)
__zfs_complete_multiple_options "filesystem volume snapshot bookmark all" "$cur"
Expand All @@ -296,7 +296,7 @@ __zfs_complete()
# shellcheck disable=SC2046
if __zfs_argument_chosen $(__zfs_get_properties)
then
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
else
__zfs_complete_multiple_options "$(__zfs_get_properties)" "$cur"
fi
Expand All @@ -313,7 +313,7 @@ __zfs_complete()
list)
case "${prev}" in
-d)
COMPREPLY=($(compgen -W "" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "" -- "$cur")
;;
-t)
__zfs_complete_multiple_options "filesystem volume snapshot bookmark all" "$cur"
Expand All @@ -322,51 +322,51 @@ __zfs_complete()
__zfs_complete_multiple_options "$(__zfs_get_properties)" "$cur"
;;
-s|-S)
COMPREPLY=($(compgen -W "$(__zfs_get_properties)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_get_properties)" -- "$cur")
;;
*)
if ! __zfs_complete_switch "H,r,d,o,t,s,S"
then
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
fi
;;
esac
;;
promote)
COMPREPLY=($(compgen -W "$(__zfs_list_filesystems)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_list_filesystems)" -- "$cur")
;;
rollback)
if ! __zfs_complete_switch "r,R,f"
then
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
fi
;;
send)
if ! __zfs_complete_switch "D,n,P,p,R,v,e,L,i,I"
then
if __zfs_argument_chosen
then
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
else
if [[ $prev == -*i* ]]
then
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot_or_bookmark)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot_or_bookmark)" -- "$cur")
else
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
fi
fi
fi
;;
snapshot)
case "${prev}" in
-o)
COMPREPLY=($(compgen -W "$(__zfs_get_editable_properties)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_get_editable_properties)" -- "$cur")
__zfs_complete_nospace
;;
*)
if ! __zfs_complete_switch "o,r"
then
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
__zfs_complete_nospace
fi
;;
Expand All @@ -379,12 +379,12 @@ __zfs_complete()
upgrade)
case "${prev}" in
-a|-V|-v)
COMPREPLY=($(compgen -W "" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "" -- "$cur")
;;
*)
if ! __zfs_complete_switch "a,V,v,r"
then
COMPREPLY=($(compgen -W "$(__zfs_list_filesystems)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_list_filesystems)" -- "$cur")
fi
;;
esac
Expand All @@ -397,7 +397,7 @@ __zfs_complete()
fi
;;
*)
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
;;
esac
if type __ltrim_colon_completions &> /dev/null
Expand Down Expand Up @@ -438,7 +438,7 @@ __zpool_complete()
if [[ ${prev##*/} == zpool ]]
then
cmds=$(__zpool_get_commands)
COMPREPLY=($(compgen -W "$cmds" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$cmds" -- "$cur")
return 0
fi

Expand All @@ -452,7 +452,7 @@ __zpool_complete()
then
_filedir -d
else
COMPREPLY=($(compgen -W "$(__zpool_list_pools) -d" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zpool_list_pools) -d" -- "$cur")
fi
return 0
;;
Expand All @@ -468,12 +468,12 @@ __zpool_complete()
then
_filedir
else
COMPREPLY=($(compgen -W "$pools" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$pools" -- "$cur")
fi
return 0
;;
*)
COMPREPLY=($(compgen -W "$(__zpool_list_pools)" -- "$cur"))
mapfile -t COMPREPLY < <(compgen -W "$(__zpool_list_pools)" -- "$cur")
return 0
;;
esac
Expand Down
1 change: 1 addition & 0 deletions contrib/bpftrace/Makefile.am
Expand Up @@ -5,3 +5,4 @@ EXTRA_DIST = \
zfs-trace.sh

SHELLCHECKSCRIPTS = zfs-trace.sh
SHELLCHECK_OPTS = --enable=all
1 change: 1 addition & 0 deletions contrib/dracut/02zfsexpandknowledge/Makefile.am
Expand Up @@ -5,4 +5,5 @@ pkgdracutdir = $(dracutdir)/modules.d/02zfsexpandknowledge
pkgdracut_SCRIPTS = \
module-setup.sh

SHELLCHECK_OPTS = --enable=all
SUBSTFILES += $(pkgdracut_SCRIPTS)
1 change: 1 addition & 0 deletions contrib/dracut/90zfs/Makefile.am
Expand Up @@ -19,6 +19,7 @@ pkgdracut_DATA = \
zfs-rollback-bootfs.service

SUBSTFILES += $(pkgdracut_SCRIPTS) $(pkgdracut_DATA)
SHELLCHECK_OPTS = --enable=all

# Provided by /bin/sleep, and, again, every implementation of that supports this
CHECKBASHISMS_IGNORE = -e 'sleep only takes one integer' -e 'sleep 0.'
2 changes: 1 addition & 1 deletion contrib/dracut/90zfs/export-zfs.sh.in
Expand Up @@ -20,7 +20,7 @@ _do_zpool_export() {
zpool list 2>&1 | vinfo
fi

return ${ret}
return "${ret}"
}

if command -v zpool >/dev/null; then
Expand Down
1 change: 1 addition & 0 deletions contrib/dracut/90zfs/import-opts-generator.sh.in
Expand Up @@ -2,4 +2,5 @@

. /lib/dracut-zfs-lib.sh

# shellcheck disable=SC2154
echo ZPOOL_IMPORT_OPTS="$ZPOOL_IMPORT_OPTS"
6 changes: 3 additions & 3 deletions contrib/dracut/90zfs/module-setup.sh.in
Expand Up @@ -61,9 +61,9 @@ install() {
dracut_install /usr/lib*/gcc/**/libgcc_s.so*
fi
# shellcheck disable=SC2050
if [ @LIBFETCH_DYNAMIC@ != 0 ]; then
if [ "@LIBFETCH_DYNAMIC@" != 0 ]; then
for d in $libdirs; do
[ -e "$d/"@LIBFETCH_SONAME@ ] && dracut_install "$d/"@LIBFETCH_SONAME@
[ -e "$d/@LIBFETCH_SONAME@" ] && dracut_install "$d/@LIBFETCH_SONAME@"
done
fi
dracut_install @mounthelperdir@/mount.zfs
Expand Down Expand Up @@ -107,7 +107,7 @@ install() {
for _service in "zfs-import-scan.service" "zfs-import-cache.service" ; do
dracut_install "@systemdunitdir@/$_service"
if ! [ -L "${initdir}/$systemdsystemunitdir/zfs-import.target.wants/$_service" ]; then
ln -sf ../$_service "${initdir}/$systemdsystemunitdir/zfs-import.target.wants/$_service"
ln -sf "../$_service" "${initdir}/$systemdsystemunitdir/zfs-import.target.wants/$_service"
type mark_hostonly >/dev/null 2>&1 && mark_hostonly "@systemdunitdir@/$_service"
fi
done
Expand Down
5 changes: 4 additions & 1 deletion contrib/dracut/90zfs/parse-zfs.sh.in
Expand Up @@ -49,11 +49,14 @@ case "${root}" in

info "ZFS: Set ${root} as bootfs."
;;

*)
info "ZFS: no ZFS-on-root"
esac

# Make sure Dracut is happy that we have a root and will wait for ZFS
# modules to settle before mounting.
if [ ${wait_for_zfs} -eq 1 ]; then
if [ "${wait_for_zfs}" -eq 1 ]; then
ln -s /dev/null /dev/root 2>/dev/null
initqueuedir="${hookdir}/initqueue/finished"
test -d "${initqueuedir}" || {
Expand Down
12 changes: 7 additions & 5 deletions contrib/dracut/90zfs/zfs-lib.sh.in
Expand Up @@ -70,6 +70,7 @@ import_pool() {
}

_mount_dataset_cb() {
# shellcheck disable=SC2154
mount -o zfsutil -t zfs "${1}" "${NEWROOT}${2}"
}

Expand All @@ -91,7 +92,7 @@ mount_dataset() {
fi
fi

return ${ret}
return "${ret}"
}

# for_relevant_root_children DATASET EXEC
Expand All @@ -117,7 +118,7 @@ for_relevant_root_children() {
;;
esac
done
exit ${_ret}
exit "${_ret}"
)
}

Expand All @@ -134,7 +135,7 @@ export_all() {
done
IFS="${OLDIFS}"

return ${ret}
return "${ret}"
}

# ask_for_password
Expand Down Expand Up @@ -171,6 +172,7 @@ ask_for_password() {
--ply-tries) ply_tries="$2"; shift;;
--tty-tries) tty_tries="$2"; shift;;
--tty-echo-off) tty_echo_off=yes;;
*) echo "ask_for_password(): wrong opt '$1'" >&2;;
esac
shift
done
Expand Down Expand Up @@ -202,6 +204,6 @@ ask_for_password() {
fi
} 9>/.console_lock

[ $ret -ne 0 ] && echo "Wrong password" >&2
return $ret
[ "$ret" -ne 0 ] && echo "Wrong password" >&2
return "$ret"
}
1 change: 1 addition & 0 deletions contrib/initramfs/Makefile.am
Expand Up @@ -7,6 +7,7 @@ dist_initrd_SCRIPTS = \

SUBDIRS = conf.d conf-hooks.d hooks scripts
SHELLCHECKDIRS = hooks scripts
SHELLCHECK_OPTS = --enable=all

EXTRA_DIST = \
README.initramfs.markdown
1 change: 1 addition & 0 deletions contrib/initramfs/hooks/Makefile.am
Expand Up @@ -7,4 +7,5 @@ hooks_SCRIPTS = \
zfs \
zfsunlock

SHELLCHECK_OPTS = --enable=all
SUBSTFILES += $(hooks_SCRIPTS)
4 changes: 2 additions & 2 deletions contrib/initramfs/hooks/zfs.in
Expand Up @@ -30,8 +30,8 @@ find /lib/ -type f -name "libgcc_s.so.[1-9]" | while read -r libgcc; do
done

# shellcheck disable=SC2050
if [ @LIBFETCH_DYNAMIC@ != 0 ]; then
find /lib/ -name @LIBFETCH_SONAME@ | while read -r libfetch; do
if [ "@LIBFETCH_DYNAMIC@" != 0 ]; then
find /lib/ -name "@LIBFETCH_SONAME@" | while read -r libfetch; do
copy_exec "$libfetch"
done
fi
Expand Down
1 change: 1 addition & 0 deletions contrib/initramfs/scripts/Makefile.am
Expand Up @@ -9,3 +9,4 @@ SUBDIRS = local-top

SHELLCHECKDIRS = $(SUBDIRS)
SHELLCHECK_SHELL = sh
SHELLCHECK_OPTS = --enable=all
2 changes: 2 additions & 0 deletions contrib/initramfs/scripts/local-top/Makefile.am
Expand Up @@ -4,3 +4,5 @@ localtopdir = /usr/share/initramfs-tools/scripts/local-top

dist_localtop_SCRIPTS = \
zfs

SHELLCHECK_OPTS = --enable=all

0 comments on commit 34eef3e

Please sign in to comment.