Skip to content

Commit

Permalink
Ubuntu 22.04 integration: ShellCheck
Browse files Browse the repository at this point in the history
- Add new SC2312 global exclude.
  ```
  Consider invoking this command separately to avoid masking its return
  value (or use '|| true' to ignore). [SC2312]
  ```

- Correct errors detected by new ShellCheck version.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: szubersk <szuberskidamian@gmail.com>
Closes #14148
  • Loading branch information
szubersk authored and behlendorf committed Nov 18, 2022
1 parent c3b6fd3 commit a508796
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 94 deletions.
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ automake --version | awk '{print $NF; exit}' | (
dir="${dir%/Makefile.am}"
grep -q '%[CD]%' "$dir/Makefile.am" || continue

reldir="${dir#$root}"
reldir="${dir#"$root"}"
reldir="${reldir#/}"

canon_reldir="$(printf '%s' "$reldir" | tr -C 'a-zA-Z0-9@_' '_')"
Expand Down
3 changes: 2 additions & 1 deletion config/Shellcheck.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090]
# Not following: a was not specified as input (see shellcheck -x). [SC1091]
# Prefer putting braces around variable references even when not strictly required. [SC2250]
# Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore). [SC2312]
# In POSIX sh, 'local' is undefined. [SC2039] # older ShellCheck versions
# In POSIX sh, 'local' is undefined. [SC3043] # newer ShellCheck versions

Expand All @@ -17,7 +18,7 @@ PHONY += shellcheck
_STGT = $(subst ^,/,$(subst shellcheck-here-,,$@))
shellcheck-here-%:
if HAVE_SHELLCHECK
shellcheck --format=gcc --enable=all --exclude=SC1090,SC1091,SC2039,SC2250,SC3043 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") "$$([ -e "$(_STGT)" ] || echo "$(srcdir)/")$(_STGT)"
shellcheck --format=gcc --enable=all --exclude=SC1090,SC1091,SC2039,SC2250,SC2312,SC3043 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") "$$([ -e "$(_STGT)" ] || echo "$(srcdir)/")$(_STGT)"
else
@echo "skipping shellcheck of" $(_STGT) "because shellcheck is not installed"
endif
Expand Down
14 changes: 7 additions & 7 deletions contrib/bash_completion.d/zfs.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ __zfs_list_filesystems()
__zfs_match_snapshot()
{
local base_dataset="${cur%@*}"
if [ "$base_dataset" != "$cur" ]
if [[ "$base_dataset" != "$cur" ]]
then
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset"
else
if [ "$cur" != "" ] && __zfs_list_datasets "$cur" &> /dev/null
if [[ "$cur" != "" ]] && __zfs_list_datasets "$cur" &> /dev/null
then
$__ZFS_CMD list -H -o name -s name -t filesystem,volume -r "$cur" | tail -n +2
# We output the base dataset name even though we might be
Expand Down Expand Up @@ -104,7 +104,7 @@ __zfs_match_snapshot()
__zfs_match_snapshot_or_bookmark()
{
local base_dataset="${cur%[#@]*}"
if [ "$base_dataset" != "$cur" ]
if [[ "$base_dataset" != "$cur" ]]
then
if [[ $cur == *@* ]]
then
Expand All @@ -114,7 +114,7 @@ __zfs_match_snapshot_or_bookmark()
fi
else
$__ZFS_CMD list -H -o name -s name -t filesystem,volume
if [ -e "$cur" ] && $__ZFS_CMD list -H -o name -s name -t filesystem,volume "$cur" &> /dev/null
if [[ -e "$cur" ]] && $__ZFS_CMD list -H -o name -s name -t filesystem,volume "$cur" &> /dev/null
then
echo "$cur@"
echo "$cur#"
Expand All @@ -126,10 +126,10 @@ __zfs_match_multiple_snapshots()
{
local existing_opts
existing_opts="$(expr "$cur" : '\(.*\)[%,]')"
if [ -e "$existing_opts" ]
if [[ -e "$existing_opts" ]]
then
local base_dataset="${cur%@*}"
if [ "$base_dataset" != "$cur" ]
if [[ "$base_dataset" != "$cur" ]]
then
local cur="${cur##*,}"
if [[ $cur =~ ^%|%.*% ]]
Expand Down Expand Up @@ -199,7 +199,7 @@ __zfs_complete_multiple_options()

mapfile -t COMPREPLY < <(compgen -W "$options" -- "${cur##*,}")
existing_opts=$(expr "$cur" : '\(.*,\)')
if [ -n "$existing_opts" ]
if [[ -n "$existing_opts" ]]
then
COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" )
fi
Expand Down
18 changes: 9 additions & 9 deletions contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
get_devtype() {
local typ
typ=$(udevadm info --query=property --name="$1" | sed -n 's|^ID_FS_TYPE=||p')
if [ -z "$typ" ] ; then
if [[ -z "$typ" ]] ; then
typ=$(blkid -c /dev/null "$1" -o value -s TYPE)
fi
echo "$typ"
Expand All @@ -22,7 +22,7 @@ get_pool_devices() {
else
awk -F '\t' '/\t\/dev/ { print $2 }' "$poolconfigtemp" | \
while read -r pooldev ; do
if [ -e "$pooldev" ] ; then
if [[ -e "$pooldev" ]] ; then
resolved="$(readlink -f "$pooldev")"
dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)"
echo "$resolved"
Expand All @@ -38,15 +38,15 @@ find_zfs_block_devices() {
local fstype
local _
numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)"
if [ "$numfields" = "10" ] ; then
if [[ "$numfields" = "10" ]] ; then
fields="_ _ _ _ mp _ _ fstype dev _"
else
fields="_ _ _ _ mp _ _ _ fstype dev _"
fi
# shellcheck disable=SC2086
while read -r ${fields?} ; do
[ "$fstype" = "zfs" ] || continue
[ "$mp" = "$1" ] && get_pool_devices "${dev%%/*}"
[[ "$fstype" = "zfs" ]] || continue
[[ "$mp" = "$1" ]] && get_pool_devices "${dev%%/*}"
done < /proc/self/mountinfo
}

Expand All @@ -73,7 +73,7 @@ check() {
local _depdevtype

# shellcheck disable=SC2154
if [ -n "$hostonly" ]; then
if [[ -n "$hostonly" ]]; then

for mp in \
"/" \
Expand All @@ -92,17 +92,17 @@ if [ -n "$hostonly" ]; then
mp=$(readlink -f "$mp")
mountpoint "$mp" >/dev/null 2>&1 || continue
blockdevs=$(find_zfs_block_devices "$mp")
if [ -z "$blockdevs" ] ; then continue ; fi
if [[ -z "$blockdevs" ]] ; then continue ; fi
dinfo "zfsexpandknowledge: block devices backing ZFS dataset $mp: ${blockdevs//$'\n'/ }"
for dev in $blockdevs
do
array_contains "$dev" "${host_devs[@]}" || host_devs+=("$dev")
fstype=$(get_devtype "$dev")
host_fs_types["$dev"]="$fstype"
majmin=$(get_maj_min "$dev")
if [ -d "/sys/dev/block/$majmin/slaves" ] ; then
if [[ -d "/sys/dev/block/$majmin/slaves" ]] ; then
for _depdev in "/sys/dev/block/$majmin/slaves"/*; do
[ -f "$_depdev/dev" ] || continue
[[ -f "$_depdev/dev" ]] || continue
_depdev="/dev/${_depdev##*/}"
_depdevname=$(udevadm info --query=property --name="$_depdev" | sed -n 's|^DEVNAME=||p')
_depdevtype=$(get_devtype "$_depdevname")
Expand Down
6 changes: 3 additions & 3 deletions contrib/dracut/90zfs/module-setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

check() {
# We depend on udev-rules being loaded
[ "${1}" = "-d" ] && return 0
[[ "${1}" = "-d" ]] && return 0

# Verify the zfs tool chain
for tool in "zgenhostid" "zpool" "zfs" "mount.zfs"; do
Expand Down Expand Up @@ -50,7 +50,7 @@ install() {
fi

inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
if [ -n "${systemdutildir}" ]; then
if [[ -n "${systemdutildir}" ]]; then
inst_script "${moddir}/zfs-generator.sh" "${systemdutildir}/system-generators/dracut-zfs-generator"
fi
inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh"
Expand All @@ -68,7 +68,7 @@ install() {

# Synchronize initramfs and system hostid
if ! inst_simple -H @sysconfdir@/hostid; then
if HOSTID="$(hostid 2>/dev/null)" && [ "${HOSTID}" != "00000000" ]; then
if HOSTID="$(hostid 2>/dev/null)" && [[ "${HOSTID}" != "00000000" ]]; then
zgenhostid -o "${initdir}@sysconfdir@/hostid" "${HOSTID}"
mark_hostonly @sysconfdir@/hostid
fi
Expand Down
4 changes: 2 additions & 2 deletions contrib/initramfs/scripts/zfs
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ setup_snapshot_booting()
# rpool/ROOT/debian/boot@snap2 => rpool/ROOT/debian_snap2/boot
# rpool/ROOT/debian/usr@snap2 => rpool/ROOT/debian_snap2/usr
# rpool/ROOT/debian/var@snap2 => rpool/ROOT/debian_snap2/var
subfs="${s##$rootfs}"
subfs="${subfs%%@$snapname}"
subfs="${s##"$rootfs"}"
subfs="${subfs%%@"$snapname"}"

destfs="${rootfs}_${snapname}" # base fs.
[ -n "$subfs" ] && destfs="${destfs}$subfs" # + sub fs.
Expand Down
20 changes: 10 additions & 10 deletions scripts/common.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export ZTS_DIR=
export SCRIPT_DIR=

# General commands
export ZDB=${ZDB:-$SBIN_DIR/zdb}
export ZFS=${ZFS:-$SBIN_DIR/zfs}
export ZPOOL=${ZPOOL:-$SBIN_DIR/zpool}
export ZTEST=${ZTEST:-$SBIN_DIR/ztest}
export ZFS_SH=${ZFS_SH:-$SCRIPT_DIR/zfs.sh}
export ZDB="${ZDB:-$SBIN_DIR/zdb}"
export ZFS="${ZFS:-$SBIN_DIR/zfs}"
export ZPOOL="${ZPOOL:-$SBIN_DIR/zpool}"
export ZTEST="${ZTEST:-$SBIN_DIR/ztest}"
export ZFS_SH="${ZFS_SH:-$SCRIPT_DIR/zfs.sh}"

# Test Suite
export RUNFILE_DIR=${RUNFILE_DIR:-$ZTS_DIR/runfiles}
export TEST_RUNNER=${TEST_RUNNER:-$ZTS_DIR/test-runner/bin/test-runner.py}
export ZTS_REPORT=${ZTS_REPORT:-$ZTS_DIR/test-runner/bin/zts-report.py}
export STF_TOOLS=${STF_TOOLS:-$ZTS_DIR/test-runner}
export STF_SUITE=${STF_SUITE:-$ZTS_DIR/zfs-tests}
export RUNFILE_DIR="${RUNFILE_DIR:-$ZTS_DIR/runfiles}"
export TEST_RUNNER="${TEST_RUNNER:-$ZTS_DIR/test-runner/bin/test-runner.py}"
export ZTS_REPORT="${ZTS_REPORT:-$ZTS_DIR/test-runner/bin/zts-report.py}"
export STF_TOOLS="${STF_TOOLS:-$ZTS_DIR/test-runner}"
export STF_SUITE="${STF_SUITE:-$ZTS_DIR/zfs-tests}"
Loading

0 comments on commit a508796

Please sign in to comment.