kdump-lib.sh: replace '[ ]' with '[[ ]]' and get rid of legacy ``

upstream: fedora
resolves: bz2003832
conflict:
    Patch hunk modified for function is_secure_boot_enforced().

commit 30090f3a15
Author: Kairui Song <kasong@redhat.com>
Date:   Mon Sep 13 01:17:05 2021 +0800

    kdump-lib.sh: replace '[ ]' with '[[ ]]' and get rid of legacy ``

    Updated file syntax with following command:

    sed -i -e 's/\(\s\)\[\s\([^]]*\)\s\]/\1\[\[\ \2 \]\]/g' kdump-lib.sh
    (replace '[ ]' with '[[ ]]')

    sed -i -e 's/`\([^`]*\)`/\$(\1)/g' kdump-lib.sh
    (replace `...` with $(...))

    And manually updated [[ ... -a ... ]] and [[ ... -o ... ]] with && and
    ||.

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
This commit is contained in:
Tao Liu 2021-11-03 19:20:19 +08:00
parent 57daebe2f7
commit 60e5a1e7a5

View File

@ -13,16 +13,16 @@ is_fadump_capable()
{ {
# Check if firmware-assisted dump is enabled # Check if firmware-assisted dump is enabled
# if no, fallback to kdump check # if no, fallback to kdump check
if [ -f $FADUMP_ENABLED_SYS_NODE ]; then if [[ -f $FADUMP_ENABLED_SYS_NODE ]]; then
rc=`cat $FADUMP_ENABLED_SYS_NODE` rc=$(cat $FADUMP_ENABLED_SYS_NODE)
[ $rc -eq 1 ] && return 0 [[ $rc -eq 1 ]] && return 0
fi fi
return 1 return 1
} }
is_squash_available() { is_squash_available() {
for kmodule in squashfs overlay loop; do for kmodule in squashfs overlay loop; do
if [ -z "$KDUMP_KERNELVER" ]; then if [[ -z "$KDUMP_KERNELVER" ]]; then
modprobe --dry-run $kmodule &>/dev/null || return 1 modprobe --dry-run $kmodule &>/dev/null || return 1
else else
modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1 modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1
@ -40,7 +40,7 @@ is_pcs_fence_kdump()
{ {
# no pcs or fence_kdump_send executables installed? # no pcs or fence_kdump_send executables installed?
type -P pcs > /dev/null || return 1 type -P pcs > /dev/null || return 1
[ -x $FENCE_KDUMP_SEND ] || return 1 [[ -x $FENCE_KDUMP_SEND ]] || return 1
# fence kdump not configured? # fence kdump not configured?
(pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1 (pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1
@ -49,7 +49,7 @@ is_pcs_fence_kdump()
# Check if fence_kdump is configured using kdump options # Check if fence_kdump is configured using kdump options
is_generic_fence_kdump() is_generic_fence_kdump()
{ {
[ -x $FENCE_KDUMP_SEND ] || return 1 [[ -x $FENCE_KDUMP_SEND ]] || return 1
[[ $(kdump_get_conf_val fence_kdump_nodes) ]] [[ $(kdump_get_conf_val fence_kdump_nodes) ]]
} }
@ -59,10 +59,10 @@ to_dev_name() {
case "$dev" in case "$dev" in
UUID=*) UUID=*)
dev=`blkid -U "${dev#UUID=}"` dev=$(blkid -U "${dev#UUID=}")
;; ;;
LABEL=*) LABEL=*)
dev=`blkid -L "${dev#LABEL=}"` dev=$(blkid -L "${dev#LABEL=}")
;; ;;
esac esac
echo $dev echo $dev
@ -78,10 +78,10 @@ get_user_configured_dump_disk()
local _target local _target
_target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw") _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw")
[ -n "$_target" ] && echo $_target && return [[ -n "$_target" ]] && echo $_target && return
_target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")")
[ -b "$_target" ] && echo $_target [[ -b "$_target" ]] && echo $_target
} }
get_block_dump_target() get_block_dump_target()
@ -93,12 +93,12 @@ get_block_dump_target()
fi fi
_target=$(get_user_configured_dump_disk) _target=$(get_user_configured_dump_disk)
[ -n "$_target" ] && echo $(to_dev_name $_target) && return [[ -n "$_target" ]] && echo $(to_dev_name $_target) && return
# Get block device name from local save path # Get block device name from local save path
_path=$(get_save_path) _path=$(get_save_path)
_target=$(get_target_from_path $_path) _target=$(get_target_from_path $_path)
[ -b "$_target" ] && echo $(to_dev_name $_target) [[ -b "$_target" ]] && echo $(to_dev_name $_target)
} }
is_dump_to_rootfs() is_dump_to_rootfs()
@ -113,7 +113,7 @@ get_failure_action_target()
if is_dump_to_rootfs; then if is_dump_to_rootfs; then
# Get rootfs device name # Get rootfs device name
_target=$(get_root_fs_device) _target=$(get_root_fs_device)
[ -b "$_target" ] && echo $(to_dev_name $_target) && return [[ -b "$_target" ]] && echo $(to_dev_name $_target) && return
# Then, must be nfs root # Then, must be nfs root
echo "nfs" echo "nfs"
fi fi
@ -126,7 +126,7 @@ get_kdump_targets()
local kdump_targets local kdump_targets
_target=$(get_block_dump_target) _target=$(get_block_dump_target)
if [ -n "$_target" ]; then if [[ -n "$_target" ]]; then
kdump_targets=$_target kdump_targets=$_target
elif is_ssh_dump_target; then elif is_ssh_dump_target; then
kdump_targets="ssh" kdump_targets="ssh"
@ -136,7 +136,7 @@ get_kdump_targets()
# Add the root device if dump_to_rootfs is specified. # Add the root device if dump_to_rootfs is specified.
_root=$(get_failure_action_target) _root=$(get_failure_action_target)
if [ -n "$_root" -a "$kdump_targets" != "$_root" ]; then if [[ -n "$_root" ]] && [[ "$kdump_targets" != "$_root" ]]; then
kdump_targets="$kdump_targets $_root" kdump_targets="$kdump_targets $_root"
fi fi
@ -204,10 +204,10 @@ get_kdump_mntpoint_from_target()
# 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.
# systemd will be in charge to umount it. # systemd will be in charge to umount it.
if [ -z "$_mntpoint" ];then if [[ -z "$_mntpoint" ]];then
_mntpoint="/kdumproot" _mntpoint="/kdumproot"
else else
if [ "$_mntpoint" = "/" ];then if [[ "$_mntpoint" = "/" ]];then
_mntpoint="/sysroot" _mntpoint="/sysroot"
else else
_mntpoint="/kdumproot/$_mntpoint" _mntpoint="/kdumproot/$_mntpoint"
@ -223,10 +223,10 @@ kdump_get_persistent_dev() {
case "$dev" in case "$dev" in
UUID=*) UUID=*)
dev=`blkid -U "${dev#UUID=}"` dev=$(blkid -U "${dev#UUID=}")
;; ;;
LABEL=*) LABEL=*)
dev=`blkid -L "${dev#LABEL=}"` dev=$(blkid -L "${dev#LABEL=}")
;; ;;
esac esac
echo $(get_persistent_dev "$dev") echo $(get_persistent_dev "$dev")
@ -253,9 +253,9 @@ get_remote_host()
is_hostname() is_hostname()
{ {
local _hostname=`echo $1 | grep ":"` local _hostname=$(echo $1 | grep ":")
if [ -n "$_hostname" ]; then if [[ -n "$_hostname" ]]; then
return 1 return 1
fi fi
echo $1 | grep -q "[a-zA-Z]" echo $1 | grep -q "[a-zA-Z]"
@ -264,9 +264,9 @@ is_hostname()
# Copied from "/etc/sysconfig/network-scripts/network-functions" # Copied from "/etc/sysconfig/network-scripts/network-functions"
get_hwaddr() get_hwaddr()
{ {
if [ -f "/sys/class/net/${1}/address" ]; then if [[ -f "/sys/class/net/${1}/address" ]]; then
awk '{ print toupper($0) }' < /sys/class/net/${1}/address awk '{ print toupper($0) }' < /sys/class/net/${1}/address
elif [ -d "/sys/class/net/${1}" ]; then elif [[ -d "/sys/class/net/${1}" ]]; then
LC_ALL= LANG= ip -o link show ${1} 2>/dev/null | \ LC_ALL= LANG= ip -o link show ${1} 2>/dev/null | \
awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/, awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,
"\\1", 1)); }' "\\1", 1)); }'
@ -347,7 +347,7 @@ get_ifcfg_by_name()
is_nm_running() is_nm_running()
{ {
[ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ] [[ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ]]
} }
is_nm_handling() is_nm_handling()
@ -371,7 +371,7 @@ get_ifcfg_nmcli()
nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2>/dev/null \ nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2>/dev/null \
| grep "${1}" | head -1 | cut -d':' -f1) | grep "${1}" | head -1 | cut -d':' -f1)
ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}") ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}")
[ -z "${ifcfg_file}" ] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}") [[ -z "${ifcfg_file}" ]] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}")
fi fi
echo -n "${ifcfg_file}" echo -n "${ifcfg_file}"
@ -383,15 +383,15 @@ get_ifcfg_legacy()
local ifcfg_file local ifcfg_file
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
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}") local 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
fi fi
ifcfg_file=$(get_ifcfg_by_device "${1}") ifcfg_file=$(get_ifcfg_by_device "${1}")
@ -405,7 +405,7 @@ get_ifcfg_filename() {
local ifcfg_file local ifcfg_file
ifcfg_file=$(get_ifcfg_nmcli "${1}") ifcfg_file=$(get_ifcfg_nmcli "${1}")
if [ -z "${ifcfg_file}" ]; then if [[ -z "${ifcfg_file}" ]]; then
ifcfg_file=$(get_ifcfg_legacy "${1}") ifcfg_file=$(get_ifcfg_legacy "${1}")
fi fi
@ -432,11 +432,11 @@ is_dracut_mod_omitted() {
is_wdt_active() { is_wdt_active() {
local active local active
[ -d /sys/class/watchdog ] || return 1 [[ -d /sys/class/watchdog ]] || return 1
for dir in /sys/class/watchdog/*; do for dir in /sys/class/watchdog/*; do
[ -f "$dir/state" ] || continue [[ -f "$dir/state" ]] || continue
active=$(< "$dir/state") active=$(< "$dir/state")
[ "$active" = "active" ] && return 0 [[ "$active" = "active" ]] && return 0
done done
return 1 return 1
} }
@ -454,7 +454,7 @@ check_crash_mem_reserved()
local mem_reserved local mem_reserved
mem_reserved=$(cat /sys/kernel/kexec_crash_size) mem_reserved=$(cat /sys/kernel/kexec_crash_size)
if [ $mem_reserved -eq 0 ]; then if [[ $mem_reserved -eq 0 ]]; then
derror "No memory reserved for crash kernel" derror "No memory reserved for crash kernel"
return 1 return 1
fi fi
@ -464,7 +464,7 @@ check_crash_mem_reserved()
check_kdump_feasibility() check_kdump_feasibility()
{ {
if [ ! -e /sys/kernel/kexec_crash_loaded ]; then if [[ ! -e /sys/kernel/kexec_crash_loaded ]]; then
derror "Kdump is not supported on this kernel" derror "Kdump is not supported on this kernel"
return 1 return 1
fi fi
@ -474,13 +474,13 @@ check_kdump_feasibility()
check_current_kdump_status() check_current_kdump_status()
{ {
if [ ! -f /sys/kernel/kexec_crash_loaded ];then if [[ ! -f /sys/kernel/kexec_crash_loaded ]];then
derror "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel" derror "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel"
return 1 return 1
fi fi
rc=`cat /sys/kernel/kexec_crash_loaded` rc=$(cat /sys/kernel/kexec_crash_loaded)
if [ $rc == 1 ]; then if [[ $rc == 1 ]]; then
return 0 return 0
else else
return 1 return 1
@ -496,11 +496,11 @@ remove_cmdline_param()
shift shift
for arg in $@; do for arg in $@; do
cmdline=`echo $cmdline | \ cmdline=$(echo "$cmdline" | \
sed -e "s/\b$arg=[^ ]*//g" \ sed -e "s/\b$arg=[^ ]*//g" \
-e "s/^$arg\b//g" \ -e "s/^$arg\b//g" \
-e "s/[[:space:]]$arg\b//g" \ -e "s/[[:space:]]$arg\b//g" \
-e "s/\s\+/ /g"` -e "s/\s\+/ /g")
done done
echo $cmdline echo $cmdline
} }
@ -529,7 +529,7 @@ append_cmdline()
local newstr=${cmdline/$2/""} local newstr=${cmdline/$2/""}
# unchanged str implies argument wasn't there # unchanged str implies argument wasn't there
if [ "$cmdline" == "$newstr" ]; then if [[ "$cmdline" == "$newstr" ]]; then
cmdline="${cmdline} ${2}=${3}" cmdline="${cmdline} ${2}=${3}"
fi fi
@ -540,8 +540,8 @@ append_cmdline()
# 4GB of ram available. Returns 1 if we do, 0 if we dont # 4GB of ram available. Returns 1 if we do, 0 if we dont
need_64bit_headers() need_64bit_headers()
{ {
return `tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); \ return "$(tail -n 1 /proc/iomem | awk '{ split ($1, r, "-");
print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }'` print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }')"
} }
# Check if secure boot is being enforced. # Check if secure boot is being enforced.
@ -560,7 +560,7 @@ is_secure_boot_enforced()
# On powerpc, os-secureboot-enforcing DT property indicates whether secureboot # On powerpc, os-secureboot-enforcing DT property indicates whether secureboot
# is enforced. Return success, if it is found. # is enforced. Return success, if it is found.
if [ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]; then if [[ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]]; then
return 0 return 0
fi fi
@ -568,11 +568,11 @@ is_secure_boot_enforced()
secure_boot_file=$(find /sys/firmware/efi/efivars -name SecureBoot-* 2>/dev/null) secure_boot_file=$(find /sys/firmware/efi/efivars -name SecureBoot-* 2>/dev/null)
setup_mode_file=$(find /sys/firmware/efi/efivars -name SetupMode-* 2>/dev/null) setup_mode_file=$(find /sys/firmware/efi/efivars -name SetupMode-* 2>/dev/null)
if [ -f "$secure_boot_file" ] && [ -f "$setup_mode_file" ]; then if [[ -f "$secure_boot_file" ]] && [[ -f "$setup_mode_file" ]]; then
secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' $secure_boot_file|cut -d' ' -f 5) secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' $secure_boot_file|cut -d' ' -f 5)
setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' $setup_mode_file|cut -d' ' -f 5) setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' $setup_mode_file|cut -d' ' -f 5)
if [ "$secure_boot_byte" = "1" ] && [ "$setup_mode_byte" = "0" ]; then if [[ "$secure_boot_byte" = "1" ]] && [[ "$setup_mode_byte" = "0" ]]; then
return 0 return 0
fi fi
fi fi
@ -594,22 +594,22 @@ prepare_kexec_args()
local kexec_args=$1 local kexec_args=$1
local found_elf_args local found_elf_args
ARCH=`uname -m` ARCH=$(uname -m)
if [ "$ARCH" == "i686" -o "$ARCH" == "i386" ] if [[ "$ARCH" == "i686" ]] || [[ "$ARCH" == "i386" ]]
then then
need_64bit_headers need_64bit_headers
if [ $? == 1 ] if [[ $? == 1 ]]
then then
found_elf_args=`echo $kexec_args | grep elf32-core-headers` found_elf_args=$(echo $kexec_args | grep elf32-core-headers)
if [ -n "$found_elf_args" ] if [[ -n "$found_elf_args" ]]
then then
dwarn "Warning: elf32-core-headers overrides correct elf64 setting" dwarn "Warning: elf32-core-headers overrides correct elf64 setting"
else else
kexec_args="$kexec_args --elf64-core-headers" kexec_args="$kexec_args --elf64-core-headers"
fi fi
else else
found_elf_args=`echo $kexec_args | grep elf64-core-headers` found_elf_args=$(echo $kexec_args | grep elf64-core-headers)
if [ -z "$found_elf_args" ] if [[ -z "$found_elf_args" ]]
then then
kexec_args="$kexec_args --elf32-core-headers" kexec_args="$kexec_args --elf32-core-headers"
fi fi
@ -630,7 +630,7 @@ prepare_kdump_bootinfo()
local boot_imglist boot_dirlist boot_initrdlist curr_kver="$(uname -r)" local boot_imglist boot_dirlist boot_initrdlist curr_kver="$(uname -r)"
local machine_id local machine_id
if [ -z "$KDUMP_KERNELVER" ]; then if [[ -z "$KDUMP_KERNELVER" ]]; then
KDUMP_KERNELVER="$(uname -r)" KDUMP_KERNELVER="$(uname -r)"
fi fi
@ -640,20 +640,20 @@ prepare_kdump_bootinfo()
# 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="$(cat /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/")" local boot_img="$(cat /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/")"
if [ -n "$boot_img" ]; then if [[ -n "$boot_img" ]]; then
boot_imglist="$boot_img $boot_imglist" boot_imglist="$boot_img $boot_imglist"
fi fi
for dir in $boot_dirlist; do for dir in $boot_dirlist; do
for img in $boot_imglist; do for img in $boot_imglist; do
if [ -f "$dir/$img" ]; then if [[ -f "$dir/$img" ]]; then
KDUMP_KERNEL=$(echo $dir/$img | tr -s '/') KDUMP_KERNEL=$(echo $dir/$img | tr -s '/')
break 2 break 2
fi fi
done done
done done
if ! [ -e "$KDUMP_KERNEL" ]; then if ! [[ -e "$KDUMP_KERNEL" ]]; then
derror "Failed to detect kdump kernel location" derror "Failed to detect kdump kernel location"
return 1 return 1
fi fi
@ -664,7 +664,7 @@ prepare_kdump_bootinfo()
# Default initrd should just stay aside of kernel image, try to find it in KDUMP_BOOTDIR # Default initrd should just stay aside of kernel image, try to find it in KDUMP_BOOTDIR
boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd"
for initrd in $boot_initrdlist; do for initrd in $boot_initrdlist; do
if [ -f "$KDUMP_BOOTDIR/$initrd" ]; then if [[ -f "$KDUMP_BOOTDIR/$initrd" ]]; then
defaut_initrd_base="$initrd" defaut_initrd_base="$initrd"
DEFAULT_INITRD="$KDUMP_BOOTDIR/$defaut_initrd_base" DEFAULT_INITRD="$KDUMP_BOOTDIR/$defaut_initrd_base"
break break
@ -682,7 +682,7 @@ prepare_kdump_bootinfo()
kdump_initrd_base=${defaut_initrd_base}kdump kdump_initrd_base=${defaut_initrd_base}kdump
fi fi
# Place kdump initrd in `/var/lib/kdump` if `KDUMP_BOOTDIR` not writable # Place kdump initrd in $(/var/lib/kdump) if $(KDUMP_BOOTDIR) not writable
if [[ ! -w "$KDUMP_BOOTDIR" ]];then if [[ ! -w "$KDUMP_BOOTDIR" ]];then
var_target_initrd_dir="/var/lib/kdump" var_target_initrd_dir="/var/lib/kdump"
mkdir -p "$var_target_initrd_dir" mkdir -p "$var_target_initrd_dir"
@ -719,7 +719,7 @@ prepare_cmdline()
{ {
local cmdline id local cmdline id
if [ -z "$1" ]; then if [[ -z "$1" ]]; then
cmdline=$(cat /proc/cmdline) cmdline=$(cat /proc/cmdline)
else else
cmdline="$1" cmdline="$1"
@ -749,7 +749,7 @@ prepare_cmdline()
cmdline="${cmdline} $3" cmdline="${cmdline} $3"
id=$(get_bootcpu_apicid) id=$(get_bootcpu_apicid)
if [ ! -z ${id} ] ; then if [[ ! -z ${id} ]] ; then
cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id}) cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id})
fi fi
@ -794,7 +794,7 @@ get_recommend_size()
last_unit="" last_unit=""
start=${_ck_cmdline: :1} start=${_ck_cmdline: :1}
if [ $mem_size -lt $start ]; then if [[ $mem_size -lt $start ]]; then
echo "0M" echo "0M"
return return
fi fi
@ -804,10 +804,10 @@ get_recommend_size()
recommend=$(echo $i | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $2 }') recommend=$(echo $i | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $2 }')
size=${end: : -1} size=${end: : -1}
unit=${end: -1} unit=${end: -1}
if [ $unit == 'T' ]; then if [[ $unit == 'T' ]]; then
let size=$size*1024 let size=$size*1024
fi fi
if [ $mem_size -lt $size ]; then if [[ $mem_size -lt $size ]]; then
echo $recommend echo $recommend
IFS="$OLDIFS" IFS="$OLDIFS"
return return
@ -817,28 +817,28 @@ get_recommend_size()
} }
# return recommended size based on current system RAM size # return recommended size based on current system RAM size
# $1: kernel version, if not set, will defaults to `uname -r` # $1: kernel version, if not set, will defaults to $(uname -r)
kdump_get_arch_recommend_size() kdump_get_arch_recommend_size()
{ {
local kernel=$1 arch local kernel=$1 arch
if ! [ -r "/proc/iomem" ] ; then if ! [[ -r "/proc/iomem" ]] ; then
echo "Error, can not access /proc/iomem." echo "Error, can not access /proc/iomem."
return 1 return 1
fi fi
[ -z "$kernel" ] && kernel=$(uname -r) [[ -z "$kernel" ]] && kernel=$(uname -r)
ck_cmdline=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null) ck_cmdline=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null)
if [ -n "$ck_cmdline" ]; then if [[ -n "$ck_cmdline" ]]; then
ck_cmdline=${ck_cmdline#crashkernel=} ck_cmdline=${ck_cmdline#crashkernel=}
else else
arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]') arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]')
if [ "$arch" = "X86_64" ] || [ "$arch" = "S390X" ]; then if [[ "$arch" = "X86_64" ]] || [[ "$arch" = "S390X" ]]; then
ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M"
elif [ "$arch" = "AARCH64" ]; then elif [[ "$arch" = "AARCH64" ]]; then
ck_cmdline="2G-:448M" ck_cmdline="2G-:448M"
elif [ "$arch" = "PPC64LE" ]; then elif [[ "$arch" = "PPC64LE" ]]; then
if is_fadump_capable; then if is_fadump_capable; then
ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G"
else else
@ -914,7 +914,7 @@ try_decompress()
# "grep" that report the byte offset of the line instead of the pattern. # "grep" that report the byte offset of the line instead of the pattern.
# Try to find the header ($1) and decompress from here # Try to find the header ($1) and decompress from here
for pos in `tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"` for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2")
do do
if ! type -P $3 > /dev/null; then if ! type -P $3 > /dev/null; then
ddebug "Signiature detected but '$3' is missing, skip this decompressor" ddebug "Signiature detected but '$3' is missing, skip this decompressor"