Skip to content

Commit a508796

Browse files
szuberskbehlendorf
authored andcommitted
Ubuntu 22.04 integration: ShellCheck
- 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 <[email protected]> Reviewed-by: Richard Yao <[email protected]> Reviewed-by: George Melikov <[email protected]> Signed-off-by: szubersk <[email protected]> Closes #14148
1 parent c3b6fd3 commit a508796

File tree

10 files changed

+95
-94
lines changed

10 files changed

+95
-94
lines changed

autogen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ automake --version | awk '{print $NF; exit}' | (
1616
dir="${dir%/Makefile.am}"
1717
grep -q '%[CD]%' "$dir/Makefile.am" || continue
1818

19-
reldir="${dir#$root}"
19+
reldir="${dir#"$root"}"
2020
reldir="${reldir#/}"
2121

2222
canon_reldir="$(printf '%s' "$reldir" | tr -C 'a-zA-Z0-9@_' '_')"

config/Shellcheck.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090]
44
# Not following: a was not specified as input (see shellcheck -x). [SC1091]
55
# Prefer putting braces around variable references even when not strictly required. [SC2250]
6+
# Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore). [SC2312]
67
# In POSIX sh, 'local' is undefined. [SC2039] # older ShellCheck versions
78
# In POSIX sh, 'local' is undefined. [SC3043] # newer ShellCheck versions
89

@@ -17,7 +18,7 @@ PHONY += shellcheck
1718
_STGT = $(subst ^,/,$(subst shellcheck-here-,,$@))
1819
shellcheck-here-%:
1920
if HAVE_SHELLCHECK
20-
shellcheck --format=gcc --enable=all --exclude=SC1090,SC1091,SC2039,SC2250,SC3043 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") "$$([ -e "$(_STGT)" ] || echo "$(srcdir)/")$(_STGT)"
21+
shellcheck --format=gcc --enable=all --exclude=SC1090,SC1091,SC2039,SC2250,SC2312,SC3043 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") "$$([ -e "$(_STGT)" ] || echo "$(srcdir)/")$(_STGT)"
2122
else
2223
@echo "skipping shellcheck of" $(_STGT) "because shellcheck is not installed"
2324
endif

contrib/bash_completion.d/zfs.in

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ __zfs_list_filesystems()
6363
__zfs_match_snapshot()
6464
{
6565
local base_dataset="${cur%@*}"
66-
if [ "$base_dataset" != "$cur" ]
66+
if [[ "$base_dataset" != "$cur" ]]
6767
then
6868
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset"
6969
else
70-
if [ "$cur" != "" ] && __zfs_list_datasets "$cur" &> /dev/null
70+
if [[ "$cur" != "" ]] && __zfs_list_datasets "$cur" &> /dev/null
7171
then
7272
$__ZFS_CMD list -H -o name -s name -t filesystem,volume -r "$cur" | tail -n +2
7373
# We output the base dataset name even though we might be
@@ -104,7 +104,7 @@ __zfs_match_snapshot()
104104
__zfs_match_snapshot_or_bookmark()
105105
{
106106
local base_dataset="${cur%[#@]*}"
107-
if [ "$base_dataset" != "$cur" ]
107+
if [[ "$base_dataset" != "$cur" ]]
108108
then
109109
if [[ $cur == *@* ]]
110110
then
@@ -114,7 +114,7 @@ __zfs_match_snapshot_or_bookmark()
114114
fi
115115
else
116116
$__ZFS_CMD list -H -o name -s name -t filesystem,volume
117-
if [ -e "$cur" ] && $__ZFS_CMD list -H -o name -s name -t filesystem,volume "$cur" &> /dev/null
117+
if [[ -e "$cur" ]] && $__ZFS_CMD list -H -o name -s name -t filesystem,volume "$cur" &> /dev/null
118118
then
119119
echo "$cur@"
120120
echo "$cur#"
@@ -126,10 +126,10 @@ __zfs_match_multiple_snapshots()
126126
{
127127
local existing_opts
128128
existing_opts="$(expr "$cur" : '\(.*\)[%,]')"
129-
if [ -e "$existing_opts" ]
129+
if [[ -e "$existing_opts" ]]
130130
then
131131
local base_dataset="${cur%@*}"
132-
if [ "$base_dataset" != "$cur" ]
132+
if [[ "$base_dataset" != "$cur" ]]
133133
then
134134
local cur="${cur##*,}"
135135
if [[ $cur =~ ^%|%.*% ]]
@@ -199,7 +199,7 @@ __zfs_complete_multiple_options()
199199

200200
mapfile -t COMPREPLY < <(compgen -W "$options" -- "${cur##*,}")
201201
existing_opts=$(expr "$cur" : '\(.*,\)')
202-
if [ -n "$existing_opts" ]
202+
if [[ -n "$existing_opts" ]]
203203
then
204204
COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" )
205205
fi

contrib/dracut/02zfsexpandknowledge/module-setup.sh.in

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
get_devtype() {
44
local typ
55
typ=$(udevadm info --query=property --name="$1" | sed -n 's|^ID_FS_TYPE=||p')
6-
if [ -z "$typ" ] ; then
6+
if [[ -z "$typ" ]] ; then
77
typ=$(blkid -c /dev/null "$1" -o value -s TYPE)
88
fi
99
echo "$typ"
@@ -22,7 +22,7 @@ get_pool_devices() {
2222
else
2323
awk -F '\t' '/\t\/dev/ { print $2 }' "$poolconfigtemp" | \
2424
while read -r pooldev ; do
25-
if [ -e "$pooldev" ] ; then
25+
if [[ -e "$pooldev" ]] ; then
2626
resolved="$(readlink -f "$pooldev")"
2727
dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)"
2828
echo "$resolved"
@@ -38,15 +38,15 @@ find_zfs_block_devices() {
3838
local fstype
3939
local _
4040
numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)"
41-
if [ "$numfields" = "10" ] ; then
41+
if [[ "$numfields" = "10" ]] ; then
4242
fields="_ _ _ _ mp _ _ fstype dev _"
4343
else
4444
fields="_ _ _ _ mp _ _ _ fstype dev _"
4545
fi
4646
# shellcheck disable=SC2086
4747
while read -r ${fields?} ; do
48-
[ "$fstype" = "zfs" ] || continue
49-
[ "$mp" = "$1" ] && get_pool_devices "${dev%%/*}"
48+
[[ "$fstype" = "zfs" ]] || continue
49+
[[ "$mp" = "$1" ]] && get_pool_devices "${dev%%/*}"
5050
done < /proc/self/mountinfo
5151
}
5252

@@ -73,7 +73,7 @@ check() {
7373
local _depdevtype
7474

7575
# shellcheck disable=SC2154
76-
if [ -n "$hostonly" ]; then
76+
if [[ -n "$hostonly" ]]; then
7777

7878
for mp in \
7979
"/" \
@@ -92,17 +92,17 @@ if [ -n "$hostonly" ]; then
9292
mp=$(readlink -f "$mp")
9393
mountpoint "$mp" >/dev/null 2>&1 || continue
9494
blockdevs=$(find_zfs_block_devices "$mp")
95-
if [ -z "$blockdevs" ] ; then continue ; fi
95+
if [[ -z "$blockdevs" ]] ; then continue ; fi
9696
dinfo "zfsexpandknowledge: block devices backing ZFS dataset $mp: ${blockdevs//$'\n'/ }"
9797
for dev in $blockdevs
9898
do
9999
array_contains "$dev" "${host_devs[@]}" || host_devs+=("$dev")
100100
fstype=$(get_devtype "$dev")
101101
host_fs_types["$dev"]="$fstype"
102102
majmin=$(get_maj_min "$dev")
103-
if [ -d "/sys/dev/block/$majmin/slaves" ] ; then
103+
if [[ -d "/sys/dev/block/$majmin/slaves" ]] ; then
104104
for _depdev in "/sys/dev/block/$majmin/slaves"/*; do
105-
[ -f "$_depdev/dev" ] || continue
105+
[[ -f "$_depdev/dev" ]] || continue
106106
_depdev="/dev/${_depdev##*/}"
107107
_depdevname=$(udevadm info --query=property --name="$_depdev" | sed -n 's|^DEVNAME=||p')
108108
_depdevtype=$(get_devtype "$_depdevname")

contrib/dracut/90zfs/module-setup.sh.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

88
# Verify the zfs tool chain
99
for tool in "zgenhostid" "zpool" "zfs" "mount.zfs"; do
@@ -50,7 +50,7 @@ install() {
5050
fi
5151

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

6969
# Synchronize initramfs and system hostid
7070
if ! inst_simple -H @sysconfdir@/hostid; then
71-
if HOSTID="$(hostid 2>/dev/null)" && [ "${HOSTID}" != "00000000" ]; then
71+
if HOSTID="$(hostid 2>/dev/null)" && [[ "${HOSTID}" != "00000000" ]]; then
7272
zgenhostid -o "${initdir}@sysconfdir@/hostid" "${HOSTID}"
7373
mark_hostonly @sysconfdir@/hostid
7474
fi

contrib/initramfs/scripts/zfs

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ setup_snapshot_booting()
640640
# rpool/ROOT/debian/boot@snap2 => rpool/ROOT/debian_snap2/boot
641641
# rpool/ROOT/debian/usr@snap2 => rpool/ROOT/debian_snap2/usr
642642
# rpool/ROOT/debian/var@snap2 => rpool/ROOT/debian_snap2/var
643-
subfs="${s##$rootfs}"
644-
subfs="${subfs%%@$snapname}"
643+
subfs="${s##"$rootfs"}"
644+
subfs="${subfs%%@"$snapname"}"
645645

646646
destfs="${rootfs}_${snapname}" # base fs.
647647
[ -n "$subfs" ] && destfs="${destfs}$subfs" # + sub fs.

scripts/common.sh.in

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ export ZTS_DIR=
88
export SCRIPT_DIR=
99

1010
# General commands
11-
export ZDB=${ZDB:-$SBIN_DIR/zdb}
12-
export ZFS=${ZFS:-$SBIN_DIR/zfs}
13-
export ZPOOL=${ZPOOL:-$SBIN_DIR/zpool}
14-
export ZTEST=${ZTEST:-$SBIN_DIR/ztest}
15-
export ZFS_SH=${ZFS_SH:-$SCRIPT_DIR/zfs.sh}
11+
export ZDB="${ZDB:-$SBIN_DIR/zdb}"
12+
export ZFS="${ZFS:-$SBIN_DIR/zfs}"
13+
export ZPOOL="${ZPOOL:-$SBIN_DIR/zpool}"
14+
export ZTEST="${ZTEST:-$SBIN_DIR/ztest}"
15+
export ZFS_SH="${ZFS_SH:-$SCRIPT_DIR/zfs.sh}"
1616

1717
# Test Suite
18-
export RUNFILE_DIR=${RUNFILE_DIR:-$ZTS_DIR/runfiles}
19-
export TEST_RUNNER=${TEST_RUNNER:-$ZTS_DIR/test-runner/bin/test-runner.py}
20-
export ZTS_REPORT=${ZTS_REPORT:-$ZTS_DIR/test-runner/bin/zts-report.py}
21-
export STF_TOOLS=${STF_TOOLS:-$ZTS_DIR/test-runner}
22-
export STF_SUITE=${STF_SUITE:-$ZTS_DIR/zfs-tests}
18+
export RUNFILE_DIR="${RUNFILE_DIR:-$ZTS_DIR/runfiles}"
19+
export TEST_RUNNER="${TEST_RUNNER:-$ZTS_DIR/test-runner/bin/test-runner.py}"
20+
export ZTS_REPORT="${ZTS_REPORT:-$ZTS_DIR/test-runner/bin/zts-report.py}"
21+
export STF_TOOLS="${STF_TOOLS:-$ZTS_DIR/test-runner}"
22+
export STF_SUITE="${STF_SUITE:-$ZTS_DIR/zfs-tests}"

0 commit comments

Comments
 (0)