kdump-lib.sh: declare and assign separately

upstream: fedora
resolves: bz2003832
conflict: none

commit 20089dddd5
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 03:48:19 2021 +0800

    kdump-lib.sh: declare and assign separately

    See: https://github.com/koalaman/shellcheck/wiki/SC2155

    Signed-off-by: Kairui Song <kasong@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
This commit is contained in:
Tao Liu 2021-11-03 19:30:31 +08:00
parent 653edd848c
commit 040a2e259f

View File

@ -158,12 +158,15 @@ get_kdump_targets()
# part is the bind mounted directory which quotes by bracket "[]". # part is the bind mounted directory which quotes by bracket "[]".
get_bind_mount_source() get_bind_mount_source()
{ {
local _mnt=$(df "$1" | tail -1 | awk '{print $NF}') local _mnt _path _src _opt _fstype
local _path=${1#$_mnt} local _fsroot _src_nofsroot
local _src=$(get_mount_info SOURCE target "$_mnt" -f) _mnt=$(df "$1" | tail -1 | awk '{print $NF}')
local _opt=$(get_mount_info OPTIONS target "$_mnt" -f) _path=${1#$_mnt}
local _fstype=$(get_mount_info FSTYPE target "$_mnt" -f)
_src=$(get_mount_info SOURCE target "$_mnt" -f)
_opt=$(get_mount_info OPTIONS target "$_mnt" -f)
_fstype=$(get_mount_info FSTYPE target "$_mnt" -f)
# bind mount in fstab # bind mount in fstab
if [[ -d "$_src" ]] && [[ "$_fstype" = none ]] && (echo "$_opt" | grep -q "\bbind\b"); then if [[ -d "$_src" ]] && [[ "$_fstype" = none ]] && (echo "$_opt" | grep -q "\bbind\b"); then
@ -171,12 +174,12 @@ get_bind_mount_source()
fi fi
# direct mount # direct mount
local _src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f) _src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f)
if [[ $_src_nofsroot = "$_src" ]]; then if [[ $_src_nofsroot = "$_src" ]]; then
echo "$_mnt$_path" && return echo "$_mnt$_path" && return
fi fi
local _fsroot=${_src#${_src_nofsroot}[} _fsroot=${_src#${_src_nofsroot}[}
_fsroot=${_fsroot%]} _fsroot=${_fsroot%]}
_mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f)
@ -199,8 +202,9 @@ get_mntopt_from_target()
# $1: kdump target device # $1: kdump target device
get_kdump_mntpoint_from_target() get_kdump_mntpoint_from_target()
{ {
local _mntpoint=$(get_mntpoint_from_target "$1") local _mntpoint
_mntpoint=$(get_mntpoint_from_target "$1")
# mount under /sysroot if dump to root disk or mount under # mount under /sysroot if dump to root disk or mount under
# mount under /kdumproot if dump target is not mounted in first kernel # mount under /kdumproot if dump target is not mounted in first kernel
# mount under /kdumproot/$_mntpoint in other cases in 2nd kernel. # mount under /kdumproot/$_mntpoint in other cases in 2nd kernel.
@ -254,8 +258,9 @@ get_remote_host()
is_hostname() is_hostname()
{ {
local _hostname=$(echo "$1" | grep ":") local _hostname
_hostname=$(echo "$1" | grep ":")
if [[ -n "$_hostname" ]]; then if [[ -n "$_hostname" ]]; then
return 1 return 1
fi fi
@ -369,7 +374,7 @@ get_ifcfg_nmcli()
# $1: netdev name # $1: netdev name
get_ifcfg_legacy() get_ifcfg_legacy()
{ {
local ifcfg_file local ifcfg_file hwaddr
ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}" ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}"
[[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return
@ -377,7 +382,7 @@ get_ifcfg_legacy()
ifcfg_file=$(get_ifcfg_by_name "${1}") ifcfg_file=$(get_ifcfg_by_name "${1}")
[[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return
local hwaddr=$(get_hwaddr "${1}") hwaddr=$(get_hwaddr "${1}")
if [[ -n "$hwaddr" ]]; then if [[ -n "$hwaddr" ]]; then
ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}") ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}")
[[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return
@ -616,7 +621,7 @@ prepare_kexec_args()
# #
prepare_kdump_bootinfo() prepare_kdump_bootinfo()
{ {
local boot_imglist boot_dirlist boot_initrdlist local boot_img boot_imglist boot_dirlist boot_initrdlist
local machine_id local machine_id
if [[ -z "$KDUMP_KERNELVER" ]]; then if [[ -z "$KDUMP_KERNELVER" ]]; then
@ -628,7 +633,7 @@ prepare_kdump_bootinfo()
boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG" boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG"
# Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format # Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format
local boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)" boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)"
if [[ -n "$boot_img" ]]; then if [[ -n "$boot_img" ]]; then
boot_imglist="$boot_img $boot_imglist" boot_imglist="$boot_img $boot_imglist"
fi fi
@ -850,9 +855,11 @@ kdump_get_arch_recommend_size()
# $1: the block device to be checked in maj:min format # $1: the block device to be checked in maj:min format
get_luks_crypt_dev() get_luks_crypt_dev()
{ {
local _type
[[ -b /dev/block/$1 ]] || return 1 [[ -b /dev/block/$1 ]] || return 1
local _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE") _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE")
[[ $_type == "crypto_LUKS" ]] && echo "$1" [[ $_type == "crypto_LUKS" ]] && echo "$1"
for _x in "/sys/dev/block/$1/slaves/"*; do for _x in "/sys/dev/block/$1/slaves/"*; do
@ -927,7 +934,9 @@ try_decompress()
get_kernel_size() get_kernel_size()
{ {
# Prepare temp files: # Prepare temp files:
local img=$1 tmp=$(mktemp /tmp/vmlinux-XXX) local tmp img=$1
tmp=$(mktemp /tmp/vmlinux-XXX)
trap 'rm -f "$tmp"' 0 trap 'rm -f "$tmp"' 0
# Try to check if it's a vmlinux already # Try to check if it's a vmlinux already