Fix various shellcheck findings

This includes fixes for

SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.
SC2005 (style): Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
SC2162 (info): read without -r will mangle backslashes.
SC2086 (info): Double quote to prevent globbing and word splitting.
SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

In addition add some source hints to prevent false positive findings.

Signed-off-by: Philipp Rudo <prudo@redhat.com>
Reviewed-by: Pingfan Liu <piliu@redhat.com>
This commit is contained in:
Philipp Rudo 2023-09-06 10:49:36 +02:00 committed by Coiby Xu
parent fc7c65312a
commit 026edc2b59
2 changed files with 11 additions and 7 deletions

View File

@ -197,7 +197,7 @@ get_bind_mount_source()
local _fsroot _src_nofsroot
_mnt=$(df "$1" | tail -1 | awk '{print $NF}')
_path=${1#$_mnt}
_path=${1#"$_mnt"}
_src=$(get_mount_info SOURCE target "$_mnt" -f)
_opt=$(get_mount_info OPTIONS target "$_mnt" -f)
@ -214,7 +214,7 @@ get_bind_mount_source()
echo "$_mnt$_path" && return
fi
_fsroot=${_src#${_src_nofsroot}[}
_fsroot=${_src#"${_src_nofsroot}"[}
_fsroot=${_fsroot%]}
_mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f)
@ -223,7 +223,7 @@ get_bind_mount_source()
local _subvol
_subvol=${_opt#*subvol=}
_subvol=${_subvol%,*}
_fsroot=${_fsroot#$_subvol}
_fsroot=${_fsroot#"$_subvol"}
fi
echo "$_mnt$_fsroot$_path"
}
@ -270,7 +270,7 @@ kdump_get_persistent_dev()
dev=$(blkid -L "${dev#LABEL=}")
;;
esac
echo $(get_persistent_dev "$dev")
get_persistent_dev "$dev"
}
is_ostree()
@ -823,7 +823,7 @@ get_recommend_size()
while read -r -d , range; do
# need to use non-default IFS as double spaces are used as a
# single delimiter while commas aren't...
IFS=, read start start_unit end end_unit size <<< \
IFS=, read -r start start_unit end end_unit size <<< \
"$(echo "$range" | sed -n "s/\([0-9]\+\)\([GT]\?\)-\([0-9]*\)\([GT]\?\):\([0-9]\+[MG]\)/\1,\2,\3,\4,\5/p")"
# aka. 102400T

View File

@ -29,14 +29,17 @@ if [[ -f /etc/sysconfig/kdump ]]; then
fi
[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
. $dracutbasedir/dracut-functions.sh
# shellcheck source=/dev/null
. "$dracutbasedir"/dracut-functions.sh
if [[ ${__SOURCED__:+x} ]]; then
KDUMP_LIB_PATH=.
else
KDUMP_LIB_PATH=/lib/kdump
fi
# shellcheck source=./kdump-lib.sh
. $KDUMP_LIB_PATH/kdump-lib.sh
# shellcheck source=./kdump-logger.sh
. $KDUMP_LIB_PATH/kdump-logger.sh
#initiate the kdump logger
@ -247,7 +250,7 @@ restore_default_initrd()
if [[ $default_checksum != "$backup_checksum" ]]; then
dwarn "WARNING: checksum mismatch! Can't restore original initrd.."
else
rm -f $INITRD_CHECKSUM_LOCATION
rm -f "$INITRD_CHECKSUM_LOCATION"
if mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD"; then
derror "Restoring original initrd as fadump mode is disabled."
sync -f "$DEFAULT_INITRD"
@ -497,6 +500,7 @@ check_drivers_modified()
# If it's dump target is on block device, detect the block driver
_target=$(get_block_dump_target)
if [[ -n $_target ]]; then
# shellcheck disable=SC2317
_record_block_drivers()
{
local _drivers