From dcb59c30d55f2c890f7937e1e5587a89164bc50d Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Nov 09 2021 13:13:59 +0000 Subject: bash scripts: replace '[ ]' with '[[ ]]' for bash scripts upstream: fedora resolves: bz2003832 conflict: function load_kdump_kernel_key() not presented in rhel9, so related patch hunk are removed. commit 70978c00e5a573f0901ac404067eaea2c6536370 Author: Kairui Song Date: Wed Sep 8 17:20:51 2021 +0800 bash scripts: replace '[ ]' with '[[ ]]' for bash scripts kdumpctl, mkdumprd, *-module-setup.sh only target bash, since they only run in first kernel and depend on dracut, and dracut depends on bash. So use '[[ ]]' to replace '[ ]'. This is a batch update done with following command: `sed -i -e 's/\(\s\)\[\s\([^]]*\)\s\]/\1\[\[\ \2 \]\]/g' kdumpctl, mkdumprd, *-module-setup.sh` and replaced [ ... -a ... ] with [[ ... ]] && [[ ... ]] manually. See https://tldp.org/LDP/abs/html/testconstructs.html for more details on '[[ ]]', it's more versatile, safer, and slightly faster than '[ ]'. This will also help shfmt to clean up the code in later commits. Signed-off-by: Kairui Song Acked-by: Philipp Rudo Signed-off-by: Tao Liu --- diff --git a/dracut-early-kdump-module-setup.sh b/dracut-early-kdump-module-setup.sh index b25d6b5..00546e0 100755 --- a/dracut-early-kdump-module-setup.sh +++ b/dracut-early-kdump-module-setup.sh @@ -6,8 +6,8 @@ KDUMP_KERNEL="" KDUMP_INITRD="" check() { - if [ ! -f /etc/sysconfig/kdump ] || [ ! -f /lib/kdump/kdump-lib.sh ]\ - || [ -n "${IN_KDUMP}" ] + if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]]\ + || [[ -n "${IN_KDUMP}" ]] then return 1 fi @@ -25,7 +25,7 @@ prepare_kernel_initrd() { prepare_kdump_bootinfo # $kernel is a variable from dracut - if [ "$KDUMP_KERNELVER" != $kernel ]; then + if [[ "$KDUMP_KERNELVER" != $kernel ]]; then dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \ "but the initramfs is generated for kernel version '$kernel'" fi @@ -33,12 +33,12 @@ prepare_kernel_initrd() { install() { prepare_kernel_initrd - if [ ! -f "$KDUMP_KERNEL" ]; then + if [[ ! -f "$KDUMP_KERNEL" ]]; then derror "Could not find required kernel for earlykdump," \ "earlykdump will not work!" return 1 fi - if [ ! -f "$KDUMP_INITRD" ]; then + if [[ ! -f "$KDUMP_INITRD" ]]; then derror "Could not find required kdump initramfs for earlykdump," \ "please ensure kdump initramfs is generated first," \ "earlykdump will not work!" diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 68b2874..141a67e 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -11,7 +11,7 @@ kdump_module_init() { check() { [[ $debug ]] && set -x #kdumpctl sets this explicitly - if [ -z "$IN_KDUMP" ] || [ ! -f /etc/kdump.conf ] + if [[ -z "$IN_KDUMP" ]] || [[ ! -f /etc/kdump.conf ]] then return 1 fi @@ -41,11 +41,11 @@ depends() { _dep="$_dep ssh-client" fi - if [ "$(uname -m)" = "s390x" ]; then + if [[ "$(uname -m)" = "s390x" ]]; then _dep="$_dep znet" fi - if [ -n "$( ls -A /sys/class/drm 2>/dev/null )" ] || [ -d /sys/module/hyperv_fb ]; then + if [[ -n "$( ls -A /sys/class/drm 2>/dev/null )" ]] || [[ -d /sys/module/hyperv_fb ]]; then add_opt_module drm fi @@ -57,19 +57,19 @@ depends() { } kdump_is_bridge() { - [ -d /sys/class/net/"$1"/bridge ] + [[ -d /sys/class/net/"$1"/bridge ]] } kdump_is_bond() { - [ -d /sys/class/net/"$1"/bonding ] + [[ -d /sys/class/net/"$1"/bonding ]] } kdump_is_team() { - [ -f /usr/bin/teamnl ] && teamnl $1 ports &> /dev/null + [[ -f /usr/bin/teamnl ]] && teamnl $1 ports &> /dev/null } kdump_is_vlan() { - [ -f /proc/net/vlan/"$1" ] + [[ -f /proc/net/vlan/"$1" ]] } # $1: netdev name @@ -78,7 +78,7 @@ source_ifcfg_file() { dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager." ifcfg_file=$(get_ifcfg_filename $1) - if [ -f "${ifcfg_file}" ]; then + if [[ -f "${ifcfg_file}" ]]; then . ${ifcfg_file} else dwarning "The ifcfg file of $1 is not found!" @@ -102,19 +102,19 @@ kdump_setup_dns() { else dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script" source_ifcfg_file "$_netdev" - [ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile" - [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile" + [[ -n "$DNS1" ]] && echo "nameserver=$DNS1" > "$_dnsfile" + [[ -n "$DNS2" ]] && echo "nameserver=$DNS2" >> "$_dnsfile" fi while read -r content; do _nameserver=$(echo $content | grep ^nameserver) - [ -z "$_nameserver" ] && continue + [[ -z "$_nameserver" ]] && continue _dns=$(echo $_nameserver | cut -d' ' -f2) - [ -z "$_dns" ] && continue + [[ -z "$_dns" ]] && continue - if [ ! -f $_dnsfile ] || ! grep -q "$_dns" "$_dnsfile" ; then + if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile" ; then echo "nameserver=$_dns" >> "$_dnsfile" fi done < "/etc/resolv.conf" @@ -243,11 +243,11 @@ kdump_static_ip() { _ipv6_flag="-6" fi - if [ -n "$_ipaddr" ]; then + if [[ -n "$_ipaddr" ]]; then _gateway=$(ip $_ipv6_flag route list dev $_netdev | \ awk '/^default /{print $3}' | head -n 1) - if [ "x" != "x"$_ipv6_flag ]; then + if [[ "x" != "x"$_ipv6_flag ]]; then # _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/" _netmask=${_ipaddr#*\/} _srcaddr="[$_srcaddr]" @@ -268,7 +268,7 @@ kdump_static_ip() { while read -r _route; do _target=$(echo $_route | cut -d ' ' -f1) _nexthop=$(echo $_route | cut -d ' ' -f3) - if [ "x" != "x"$_ipv6_flag ]; then + if [[ "x" != "x"$_ipv6_flag ]]; then _target="[$_target]" _nexthop="[$_nexthop]" fi @@ -297,7 +297,7 @@ kdump_handle_mulitpath_route() { if [[ "$_weight" -gt "$_max_weight" ]]; then _nexthop=$(echo "$_route" | cut -d ' ' -f3) _max_weight=$_weight - if [ "x" != "x"$_ipv6_flag ]; then + if [[ "x" != "x"$_ipv6_flag ]]; then _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" else _rule="rd.route=$_target:$_nexthop:$kdumpnic" @@ -322,7 +322,7 @@ kdump_get_mac_addr() { #of its slaves, we should use perm address kdump_get_perm_addr() { local addr=$(ethtool -P $1 | sed -e 's/Permanent address: //') - if [ -z "$addr" ] || [ "$addr" = "00:00:00:00:00:00" ] + if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]] then derror "Can't get the permanent address of $1" else @@ -420,7 +420,7 @@ kdump_setup_team() { #Buggy version teamdctl outputs to stderr! #Try to use the latest version of teamd. teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then derror "teamdctl failed." exit 1 @@ -460,25 +460,25 @@ find_online_znet_device() { local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" local NETWORK_DEVICES d ifname ONLINE - [ ! -d "$CCWGROUPBUS_DEVICEDIR" ] && return + [[ ! -d "$CCWGROUPBUS_DEVICEDIR" ]] && return NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) for d in $NETWORK_DEVICES do - [ ! -f "$d/online" ] && continue + [[ ! -f "$d/online" ]] && continue read -r ONLINE < $d/online - if [ $ONLINE -ne 1 ]; then + if [[ $ONLINE -ne 1 ]]; then continue fi # determine interface name, if there (only for qeth and if # device is online) - if [ -f $d/if_name ] + if [[ -f $d/if_name ]] then read -r ifname < $d/if_name - elif [ -d $d/net ] + elif [[ -d $d/net ]] then ifname=$(ls $d/net/) fi - [ -n "$ifname" ] && break + [[ -n "$ifname" ]] && break done echo -n "$ifname" } @@ -530,7 +530,7 @@ kdump_get_remote_ip() local _remote=$(get_remote_host $1) _remote_temp if is_hostname $_remote; then _remote_temp=$(getent ahosts $_remote | grep -v : | head -n 1) - if [ -z "$_remote_temp" ]; then + if [[ -z "$_remote_temp" ]]; then _remote_temp=$(getent ahosts $_remote | head -n 1) fi _remote=$(echo $_remote_temp | cut -d' ' -f1) @@ -565,7 +565,7 @@ kdump_install_net() { fi _static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic) - if [ -n "$_static" ]; then + if [[ -n "$_static" ]]; then _proto=none elif is_ipv6_address $_srcaddr; then _proto=auto6 @@ -580,7 +580,7 @@ kdump_install_net() { # so we have to avoid adding duplicates # We should also check /proc/cmdline for existing ip=xx arg. # For example, iscsi boot will specify ip=xxx arg in cmdline. - if [ ! -f $_ip_conf ] || ! grep -q $_ip_opts $_ip_conf &&\ + if [[ ! -f $_ip_conf ]] || ! grep -q $_ip_opts $_ip_conf &&\ ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then echo "$_ip_opts" >> $_ip_conf fi @@ -603,7 +603,7 @@ kdump_install_net() { kdump_setup_dns "$_netdev" "$_nm_show_cmd" - if [ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]; then + if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then # network-manager module needs this parameter echo "rd.neednet" >> ${initdir}/etc/cmdline.d/50neednet.conf fi @@ -615,8 +615,8 @@ kdump_install_net() { # the default gate way for network dump, eth1 in the fence kdump path will # call kdump_install_net again and we don't want eth1 to be the default # gateway. - if [ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ] && - [ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]; then + if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] && + [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then echo "kdumpnic=$kdumpnic" > ${initdir}/etc/cmdline.d/60kdumpnic.conf echo "bootdev=$kdumpnic" > ${initdir}/etc/cmdline.d/70bootdev.conf fi @@ -624,21 +624,21 @@ kdump_install_net() { # install etc/kdump/pre.d and /etc/kdump/post.d kdump_install_pre_post_conf() { - if [ -d /etc/kdump/pre.d ]; then + if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do - if [ -x "$file" ]; then + if [[ -x "$file" ]]; then dracut_install $file - elif [ $file != "/etc/kdump/pre.d/*" ]; then + elif [[ $file != "/etc/kdump/pre.d/*" ]]; then echo "$file is not executable" fi done fi - if [ -d /etc/kdump/post.d ]; then + if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do - if [ -x "$file" ]; then + if [[ -x "$file" ]]; then dracut_install $file - elif [ $file != "/etc/kdump/post.d/*" ]; then + elif [[ $file != "/etc/kdump/post.d/*" ]]; then echo "$file is not executable" fi done @@ -667,7 +667,7 @@ default_dump_target_install_conf() echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf # don't touch the path under root mount - if [ "$_mntpoint" != "/" ]; then + if [[ "$_mntpoint" != "/" ]]; then _save_path=${_save_path##"$_mntpoint"} fi @@ -748,10 +748,10 @@ kdump_get_iscsi_initiator() { local _initiator local initiator_conf="/etc/iscsi/initiatorname.iscsi" - [ -f "$initiator_conf" ] || return 1 + [[ -f "$initiator_conf" ]] || return 1 while read -r _initiator; do - [ -z "${_initiator%%#*}" ] && continue # Skip comment lines + [[ -z "${_initiator%%#*}" ]] && continue # Skip comment lines case $_initiator in InitiatorName=*) @@ -767,7 +767,7 @@ kdump_get_iscsi_initiator() { # Figure out iBFT session according to session type is_ibft() { - [ "$(kdump_iscsi_get_rec_val $1 "node.discovery_type")" = fw ] + [[ "$(kdump_iscsi_get_rec_val $1 "node.discovery_type")" = fw ]] } kdump_setup_iscsi_device() { @@ -800,18 +800,18 @@ kdump_setup_iscsi_device() { # get and set username and password details username=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username") - [ "$username" == "" ] && username="" + [[ "$username" == "" ]] && username="" password=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password") - [ "$password" == "" ] && password="" + [[ "$password" == "" ]] && password="" username_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username_in") - [ -n "$username" ] && userpwd_str="$username:$password" + [[ -n "$username" ]] && userpwd_str="$username:$password" # get and set incoming username and password details - [ "$username_in" == "" ] && username_in="" + [[ "$username_in" == "" ]] && username_in="" password_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password_in") - [ "$password_in" == "" ] && password_in="" + [[ "$password_in" == "" ]] && password_in="" - [ -n "$username_in" ] && userpwd_in_str=":$username_in:$password_in" + [[ -n "$username_in" ]] && userpwd_in_str=":$username_in:$password_in" kdump_install_net "$tgt_ipaddr" @@ -834,7 +834,7 @@ kdump_setup_iscsi_device() { # Setup initator initiator_str=$(kdump_get_iscsi_initiator) - [ $? -ne "0" ] && derror "Failed to get initiator name" && return 1 + [[ $? -ne "0" ]] && derror "Failed to get initiator name" && return 1 # If initiator details do not exist already, append. if ! grep -q "$initiator_str" $netroot_conf; then @@ -875,7 +875,7 @@ get_alias() { do # in /etc/hosts, alias can come at the 2nd column entries=$(grep $ip /etc/hosts | awk '{ $1=""; print $0 }') - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then alias_set="$alias_set $entries" fi done @@ -892,7 +892,7 @@ is_localhost() { hostnames="$hostnames $shortnames $aliasname" for name in ${hostnames}; do - if [ "$name" == "$nodename" ]; then + if [[ "$name" == "$nodename" ]]; then return 0 fi done @@ -925,7 +925,7 @@ get_pcs_fence_kdump_nodes() { # retrieves fence_kdump args from config file get_pcs_fence_kdump_args() { - if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then + if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then . $FENCE_KDUMP_CONFIG_FILE echo $FENCE_KDUMP_OPTS fi @@ -963,7 +963,7 @@ kdump_configure_fence_kdump () { echo "fence_kdump_nodes $nodes" >> ${kdump_cfg_file} args=$(get_pcs_fence_kdump_args) - if [ -n "$args" ]; then + if [[ -n "$args" ]]; then echo "fence_kdump_args $args" >> ${kdump_cfg_file} fi @@ -989,7 +989,7 @@ kdump_install_random_seed() { poolsize=$( ${initdir}/etc/systemd/system.conf.d/kdump.conf echo "DefaultTimeoutStartSec=300s" >> ${initdir}/etc/systemd/system.conf.d/kdump.conf diff --git a/kdumpctl b/kdumpctl index 6c6cf9c..9352932 100755 --- a/kdumpctl +++ b/kdumpctl @@ -27,7 +27,7 @@ standard_kexec_args="-d -p" # Some default values in case /etc/sysconfig/kdump doesn't include KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug" -if [ -f /etc/sysconfig/kdump ]; then +if [[ -f /etc/sysconfig/kdump ]]; then . /etc/sysconfig/kdump fi @@ -38,7 +38,7 @@ fi #initiate the kdump logger dlog_init -if [ $? -ne 0 ]; then +if [[ $? -ne 0 ]]; then echo "failed to initiate the kdump logger." exit 1 fi @@ -48,7 +48,7 @@ single_instance_lock() local rc timeout=5 exec 9>/var/lock/kdump - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Create file lock failed" exit 1 fi @@ -56,7 +56,7 @@ single_instance_lock() flock -n 9 rc=$? - while [ $rc -ne 0 ]; do + while [[ $rc -ne 0 ]]; do dinfo "Another app is currently holding the kdump lock; waiting for it to exit..." flock -w $timeout 9 rc=$? @@ -81,7 +81,7 @@ save_core() mkdir -p $coredir ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then mv $coredir/vmcore-incomplete $coredir/vmcore dinfo "saved a vmcore to $coredir" else @@ -91,12 +91,12 @@ save_core() # pass the dmesg to Abrt tool if exists, in order # to collect the kernel oops message. # https://fedorahosted.org/abrt/ - if [ -x /usr/bin/dumpoops ]; then + if [[ -x /usr/bin/dumpoops ]]; then ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg >/dev/null 2>&1 ddebug "dumpoops -d $coredir/dmesg" dumpoops -d $coredir/dmesg >/dev/null 2>&1 - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then dinfo "kernel oops has been collected by abrt tool" fi fi @@ -122,7 +122,7 @@ rebuild_kdump_initrd() { ddebug "rebuild kdump initrd: $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER" $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "mkdumprd: failed to make kdump initrd" return 1 fi @@ -141,7 +141,7 @@ rebuild_initrd() return 1 fi - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then rebuild_fadump_initrd else rebuild_kdump_initrd @@ -154,7 +154,7 @@ rebuild_initrd() check_exist() { for file in $1; do - if [ ! -e "$file" ]; then + if [[ ! -e "$file" ]]; then derror "Error: $file not found." return 1 fi @@ -165,7 +165,7 @@ check_exist() check_executable() { for file in $1; do - if [ ! -x "$file" ]; then + if [[ ! -x "$file" ]]; then derror "Error: $file is not executable." return 1 fi @@ -176,16 +176,16 @@ backup_default_initrd() { ddebug "backup default initrd: $DEFAULT_INITRD" - if [ ! -f "$DEFAULT_INITRD" ]; then + if [[ ! -f "$DEFAULT_INITRD" ]]; then return fi - if [ ! -e $DEFAULT_INITRD_BAK ]; then + if [[ ! -e $DEFAULT_INITRD_BAK ]]; then dinfo "Backing up $DEFAULT_INITRD before rebuild." # save checksum to verify before restoring sha1sum $DEFAULT_INITRD > $INITRD_CHECKSUM_LOCATION cp $DEFAULT_INITRD $DEFAULT_INITRD_BAK - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then dwarn "WARNING: failed to backup $DEFAULT_INITRD." rm -f $DEFAULT_INITRD_BAK fi @@ -196,17 +196,17 @@ restore_default_initrd() { ddebug "restore default initrd: $DEFAULT_INITRD" - if [ ! -f "$DEFAULT_INITRD" ]; then + if [[ ! -f "$DEFAULT_INITRD" ]]; then return fi # If a backup initrd exists, we must be switching back from # fadump to kdump. Restore the original default initrd. - if [ -f $DEFAULT_INITRD_BAK ] && [ -f $INITRD_CHECKSUM_LOCATION ]; then + if [[ -f $DEFAULT_INITRD_BAK ]] && [[ -f $INITRD_CHECKSUM_LOCATION ]]; then # verify checksum before restoring backup_checksum=$(sha1sum "$DEFAULT_INITRD_BAK" | awk '{ print $1 }') default_checksum=$(awk '{ print $1 }' "$INITRD_CHECKSUM_LOCATION") - if [ "$default_checksum" != "$backup_checksum" ]; then + if [[ "$default_checksum" != "$backup_checksum" ]]; then dwarn "WARNING: checksum mismatch! Can't restore original initrd.." else rm -f $INITRD_CHECKSUM_LOCATION @@ -226,7 +226,7 @@ check_config() case "$config_opt" in dracut_args) if [[ $config_val == *--mount* ]]; then - if [ $(echo $config_val | grep -o "\-\-mount" | wc -l) -ne 1 ]; then + if [[ $(echo $config_val | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then derror "Multiple mount targets specified in one \"dracut_args\"." return 1 fi @@ -234,7 +234,7 @@ check_config() fi ;; raw) - if [ -d "/proc/device-tree/ibm,opal/dump" ]; then + if [[ -d "/proc/device-tree/ibm,opal/dump" ]]; then dwarn "WARNING: Won't capture opalcore when 'raw' dump target is used." fi config_opt=_target @@ -262,8 +262,8 @@ check_config() return 1 fi - if [ -n "${_opt_rec[$config_opt]}" ]; then - if [ $config_opt == _target ]; then + if [[ -n "${_opt_rec[$config_opt]}" ]]; then + if [[ $config_opt == _target ]]; then derror "More than one dump targets specified" else derror "Duplicated kdump config value of option $config_opt" @@ -292,13 +292,13 @@ get_pcs_cluster_modified_files() time_stamp=$(pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | xargs -0 date +%s --date) - if [ -n $time_stamp -a $time_stamp -gt $image_time ]; then + if [[ -n $time_stamp ]] && [[ $time_stamp -gt $image_time ]]; then modified_files="cluster-cib" fi - if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then + if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then time_stamp=$(stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE) - if [ "$time_stamp" -gt "$image_time" ]; then + if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE" fi fi @@ -309,13 +309,13 @@ get_pcs_cluster_modified_files() setup_initrd() { prepare_kdump_bootinfo - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "failed to prepare for kdump bootinfo." return 1 fi DEFAULT_INITRD_BAK="$KDUMP_BOOTDIR/.$(basename $DEFAULT_INITRD).default" - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then TARGET_INITRD="$DEFAULT_INITRD" # backup initrd for reference before replacing it @@ -341,16 +341,16 @@ check_files_modified() EXTRA_BINS=$(kdump_get_conf_val kdump_post) CHECK_FILES=$(kdump_get_conf_val kdump_pre) HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" - if [ -d /etc/kdump/post.d ]; then + if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do - if [ -x "$file" ]; then + if [[ -x "$file" ]]; then POST_FILES="$POST_FILES $file" fi done fi - if [ -d /etc/kdump/pre.d ]; then + if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do - if [ -x "$file" ]; then + if [[ -x "$file" ]]; then PRE_FILES="$PRE_FILES $file" fi done @@ -367,8 +367,8 @@ check_files_modified() # Check for any updated extra module EXTRA_MODULES="$(kdump_get_conf_val extra_modules)" - if [ -n "$EXTRA_MODULES" ]; then - if [ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]; then + if [[ -n "$EXTRA_MODULES" ]]; then + if [[ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]]; then files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" fi for _module in $EXTRA_MODULES; do @@ -390,18 +390,18 @@ check_files_modified() # HOOKS is mandatory and need to check the modification time files="$files $HOOKS" check_exist "$files" && check_executable "$EXTRA_BINS" - [ $? -ne 0 ] && return 2 + [[ $? -ne 0 ]] && return 2 for file in $files; do - if [ -e "$file" ]; then + if [[ -e "$file" ]]; then time_stamp=$(stat -c "%Y" $file) - if [ "$time_stamp" -gt "$image_time" ]; then + if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $file" fi - if [ -L "$file" ]; then + if [[ -L "$file" ]]; then file=$(readlink -m $file) time_stamp=$(stat -c "%Y" $file) - if [ "$time_stamp" -gt "$image_time" ]; then + if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $file" fi fi @@ -410,7 +410,7 @@ check_files_modified() fi done - if [ -n "$modified_files" ]; then + if [[ -n "$modified_files" ]]; then dinfo "Detected change(s) in the following file(s): $modified_files" return 1 fi @@ -441,7 +441,7 @@ check_drivers_modified() # Include watchdog drivers if watchdog module is not omitted is_dracut_mod_omitted watchdog || _new_drivers+=" $(get_watchdog_drvs)" - [ -z "$_new_drivers" ] && return 0 + [[ -z "$_new_drivers" ]] && return 0 if is_fadump_capable; then _old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/fadump-kernel-modules.txt | tr '\n' ' ')" @@ -455,7 +455,7 @@ check_drivers_modified() # Skip deprecated/invalid driver name or built-in module _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name $_driver 2>/dev/null) _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n $_driver 2>/dev/null) - if [ $? -ne 0 ] || [ -z "$_module_name" ] || [[ "$_module_filename" = *"(builtin)"* ]]; then + if [[ $? -ne 0 ]] || [[ -z "$_module_name" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then continue fi if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then @@ -491,7 +491,7 @@ check_fs_modified() ddebug "_target=$_target _new_fstype=$_new_fstype" _new_dev=$(kdump_get_persistent_dev $_target) - if [ -z "$_new_dev" ]; then + if [[ -z "$_new_dev" ]]; then perror "Get persistent device name failed" return 2 fi @@ -532,19 +532,19 @@ check_system_modified() check_files_modified ret=$? - if [ $ret -ne 0 ]; then + if [[ $ret -ne 0 ]]; then return $ret fi check_fs_modified ret=$? - if [ $ret -ne 0 ]; then + if [[ $ret -ne 0 ]]; then return $ret fi check_drivers_modified ret=$? - if [ $ret -ne 0 ]; then + if [[ $ret -ne 0 ]]; then return $ret fi @@ -559,20 +559,20 @@ check_rebuild() setup_initrd - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then return 1 fi force_no_rebuild=$(kdump_get_conf_val force_no_rebuild) force_no_rebuild=${force_no_rebuild:-0} - if [ "$force_no_rebuild" != "0" ] && [ "$force_no_rebuild" != "1" ];then + if [[ "$force_no_rebuild" != "0" ]] && [[ "$force_no_rebuild" != "1" ]];then derror "Error: force_no_rebuild value is invalid" return 1 fi force_rebuild=$(kdump_get_conf_val force_rebuild) force_rebuild=${force_rebuild:-0} - if [ "$force_rebuild" != "0" ] && [ "$force_rebuild" != "1" ];then + if [[ "$force_rebuild" != "0" ]] && [[ "$force_rebuild" != "1" ]];then derror "Error: force_rebuild value is invalid" return 1 fi @@ -583,37 +583,37 @@ check_rebuild() fi # Will not rebuild kdump initrd - if [ "$force_no_rebuild" == "1" ]; then + if [[ "$force_no_rebuild" == "1" ]]; then return 0 fi #check to see if dependent files has been modified #since last build of the image file - if [ -f $TARGET_INITRD ]; then + if [[ -f $TARGET_INITRD ]]; then image_time=$(stat -c "%Y" $TARGET_INITRD 2>/dev/null) #in case of fadump mode, check whether the default/target #initrd is already built with dump capture capability - if [ "$DEFAULT_DUMP_MODE" == "fadump" ]; then + if [[ "$DEFAULT_DUMP_MODE" == "fadump" ]]; then capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$) fi fi check_system_modified ret=$? - if [ $ret -eq 2 ]; then + if [[ $ret -eq 2 ]]; then return 1 - elif [ $ret -eq 1 ];then + elif [[ $ret -eq 1 ]];then system_modified="1" fi - if [ $image_time -eq 0 ]; then + if [[ $image_time -eq 0 ]]; then dinfo "No kdump initial ramdisk found." - elif [ "$capture_capable_initrd" == "0" ]; then + elif [[ "$capture_capable_initrd" == "0" ]]; then dinfo "Rebuild $TARGET_INITRD with dump capture support" - elif [ "$force_rebuild" != "0" ]; then + elif [[ "$force_rebuild" != "0" ]]; then dinfo "Force rebuild $TARGET_INITRD" - elif [ "$system_modified" != "0" ]; then + elif [[ "$system_modified" != "0" ]]; then : else return 0 @@ -661,7 +661,7 @@ load_kdump() set +x exec 2>&12 12>&- - if [ $ret == 0 ]; then + if [[ $ret == 0 ]]; then dinfo "kexec: loaded kdump kernel" return 0 else @@ -676,7 +676,7 @@ check_ssh_config() case "$config_opt" in sshkey) # remove inline comments after the end of a directive. - if [ -f "$config_val" ]; then + if [[ -f "$config_val" ]]; then # canonicalize the path SSH_KEY_LOCATION=$(/usr/bin/readlink -m $config_val) else @@ -696,7 +696,7 @@ check_ssh_config() #make sure they've configured kdump.conf for ssh dumps local SSH_TARGET=$(echo -n $DUMP_TARGET | sed -n '/.*@/p') - if [ -z "$SSH_TARGET" ]; then + if [[ -z "$SSH_TARGET" ]]; then return 1 fi return 0 @@ -719,9 +719,9 @@ check_and_wait_network_ready() retval=$? # ssh exits with the exit status of the remote command or with 255 if an error occurred - if [ $retval -eq 0 ]; then + if [[ $retval -eq 0 ]]; then return 0 - elif [ $retval -ne 255 ]; then + elif [[ $retval -ne 255 ]]; then derror "Could not create $DUMP_TARGET:$SAVE_PATH, you should check the privilege on server side" return 1 fi @@ -729,12 +729,12 @@ check_and_wait_network_ready() # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa ddebug "$errmsg" echo $errmsg | grep -q "Permission denied\|No such file or directory\|Host key verification failed" - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\"" return 1 fi - if [ $warn_once -eq 1 ]; then + if [[ $warn_once -eq 1 ]]; then dwarn "Network dump target is not usable, waiting for it to be ready..." warn_once=0 fi @@ -742,7 +742,7 @@ check_and_wait_network_ready() cur=$(date +%s) diff=$((cur - start_time)) # 60s time out - if [ $diff -gt 180 ]; then + if [[ $diff -gt 180 ]]; then break; fi sleep 1 @@ -755,7 +755,7 @@ check_and_wait_network_ready() check_ssh_target() { check_and_wait_network_ready - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then return 1 fi return 0 @@ -764,7 +764,7 @@ check_ssh_target() propagate_ssh_key() { check_ssh_config - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "No ssh config specified in $KDUMP_CONFIG_FILE. Can't propagate" exit 1 fi @@ -773,7 +773,7 @@ propagate_ssh_key() local errmsg="Failed to propagate ssh key" #Check to see if we already created key, if not, create it. - if [ -f $KEYFILE ]; then + if [[ -f $KEYFILE ]]; then dinfo "Using existing keys..." else dinfo "Generating new ssh keys... " @@ -788,7 +788,7 @@ propagate_ssh_key() #now send the found key to the found server ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER RET=$? - if [ $RET == 0 ]; then + if [[ $RET == 0 ]]; then dinfo "$KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER" return 0 else @@ -812,13 +812,13 @@ check_current_fadump_status() { # Check if firmware-assisted dump has been registered. rc=$(<$FADUMP_REGISTER_SYS_NODE) - [ $rc -eq 1 ] && return 0 + [[ $rc -eq 1 ]] && return 0 return 1 } check_current_status() { - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then check_current_fadump_status else check_current_kdump_status @@ -833,8 +833,8 @@ save_raw() local raw_target raw_target=$(kdump_get_conf_val raw) - [ -z "$raw_target" ] && return 0 - [ -b "$raw_target" ] || { + [[ -z "$raw_target" ]] && return 0 + [[ -b "$raw_target" ]] || { derror "raw partition $raw_target not found" return 1 } @@ -844,14 +844,14 @@ save_raw() return 0 fi kdump_dir=$(kdump_get_conf_val path) - if [ -z "${kdump_dir}" ]; then + if [[ -z "${kdump_dir}" ]]; then coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" else coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")" fi mkdir -p "$coredir" - [ -d "$coredir" ] || { + [[ -d "$coredir" ]] || { derror "failed to create $coredir" return 1 } @@ -872,7 +872,7 @@ local_fs_dump_target() local _target _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf) - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then echo $_target|awk '{print $2}' fi } @@ -900,7 +900,7 @@ path_to_be_relabeled() _path=$(get_save_path) # if $_path is masked by other mount, we will not relabel it. _rmnt=$(df $_mnt/$_path 2>/dev/null | tail -1 | awk '{ print $NF }') - if [ "$_rmnt" == "$_mnt" ]; then + if [[ "$_rmnt" == "$_mnt" ]]; then echo $_mnt/$_path fi } @@ -910,13 +910,13 @@ selinux_relabel() local _path _i _attr _path=$(path_to_be_relabeled) - if [ -z "$_path" ] || ! [ -d "$_path" ] ; then + if [[ -z "$_path" ]] || ! [[ -d "$_path" ]] ; then return fi while IFS= read -r -d '' _i; do _attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null) - if [ -z "$_attr" ]; then + if [[ -z "$_attr" ]]; then restorecon "$_i"; fi done < <(find "$_path" -print0) @@ -929,13 +929,13 @@ check_fence_kdump_config() local nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in $nodes; do - if [ "$node" = "$hostname" ]; then + if [[ "$node" = "$hostname" ]]; then derror "Option fence_kdump_nodes cannot contain $hostname" return 1 fi # node can be ipaddr echo "$ipaddrs " | grep -q "$node " - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then derror "Option fence_kdump_nodes cannot contain $node" return 1 fi @@ -946,7 +946,7 @@ check_fence_kdump_config() check_dump_feasibility() { - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then return 0 fi @@ -968,7 +968,7 @@ start_fadump() start_dump() { - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then start_fadump else load_kdump @@ -986,14 +986,14 @@ check_failure_action_config() default_option=$(kdump_get_conf_val default) failure_action=$(kdump_get_conf_val failure_action) - if [ -z "$failure_action" -a -z "$default_option" ]; then + if [[ -z "$failure_action" ]] && [[ -z "$default_option" ]]; then return 0 - elif [ -n "$failure_action" -a -n "$default_option" ]; then + elif [[ -n "$failure_action" ]] && [[ -n "$default_option" ]]; then derror "Cannot specify 'failure_action' and 'default' option together" return 1 fi - if [ -n "$default_option" ]; then + if [[ -n "$default_option" ]]; then option="default" failure_action="$default_option" fi @@ -1013,7 +1013,7 @@ check_final_action_config() local final_action final_action=$(kdump_get_conf_val final_action) - if [ -z "$final_action" ]; then + if [[ -z "$final_action" ]]; then return 0 else case "$final_action" in @@ -1030,13 +1030,13 @@ check_final_action_config() start() { check_dump_feasibility - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi check_config - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1046,13 +1046,13 @@ start() fi save_raw - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi check_current_status - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then dwarn "Kdump already running: [WARNING]" return 0 fi @@ -1065,13 +1065,13 @@ start() fi check_rebuild - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi start_dump - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1082,18 +1082,18 @@ start() reload() { check_current_status - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then dwarn "Kdump was not running: [WARNING]" fi - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then reload_fadump return $? else stop_kdump fi - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Stopping kdump: [FAILED]" return 1 fi @@ -1101,13 +1101,13 @@ reload() dinfo "Stopping kdump: [OK]" setup_initrd - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi start_dump - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1135,7 +1135,7 @@ stop_kdump() $KEXEC -p -u fi - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "kexec: failed to unload kdump kernel" return 1 fi @@ -1147,7 +1147,7 @@ stop_kdump() reload_fadump() { echo 1 > $FADUMP_REGISTER_SYS_NODE - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then dinfo "fadump: re-registered successfully" return 0 else @@ -1155,7 +1155,7 @@ reload_fadump() # support is not enabled. Try stop/start from userspace # to handle such scenario. stop_fadump - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then start_fadump return $? fi @@ -1166,13 +1166,13 @@ reload_fadump() stop() { - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then stop_fadump else stop_kdump fi - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "Stopping kdump: [FAILED]" return 1 fi @@ -1183,7 +1183,7 @@ stop() rebuild() { check_config - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then return 1 fi @@ -1194,7 +1194,7 @@ rebuild() { fi setup_initrd - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then return 1 fi @@ -1211,7 +1211,7 @@ do_estimate() { local size_mb=$(( 1024 * 1024 )) setup_initrd - if [ ! -f "$TARGET_INITRD" ]; then + if [[ ! -f "$TARGET_INITRD" ]]; then derror "kdumpctl estimate: kdump initramfs is not built yet." exit 1 fi @@ -1328,7 +1328,7 @@ reset_crashkernel() { fi } -if [ ! -f "$KDUMP_CONFIG_FILE" ]; then +if [[ ! -f "$KDUMP_CONFIG_FILE" ]]; then derror "Error: No kdump config file found!" exit 1 fi @@ -1340,7 +1340,7 @@ main () case "$1" in start) - if [ -s /proc/vmcore ]; then + if [[ -s /proc/vmcore ]]; then save_core reboot else diff --git a/mkdumprd b/mkdumprd index 6621e30..3101d3f 100644 --- a/mkdumprd +++ b/mkdumprd @@ -6,7 +6,7 @@ # Written by Cong Wang # -if [ -f /etc/sysconfig/kdump ]; then +if [[ -f /etc/sysconfig/kdump ]]; then . /etc/sysconfig/kdump fi @@ -18,7 +18,7 @@ export IN_KDUMP=1 #initiate the kdump logger dlog_init -if [ $? -ne 0 ]; then +if [[ $? -ne 0 ]]; then echo "failed to initiate the kdump logger." exit 1 fi @@ -73,7 +73,7 @@ to_mount() { else # for non-nfs _target converting to use udev persistent name _pdev="$(kdump_get_persistent_dev $_target)" - if [ -z "$_pdev" ]; then + if [[ -z "$_pdev" ]]; then return 1 fi fi @@ -116,14 +116,14 @@ mkdir_save_path_ssh() _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) ssh -qn "${_opt[@]}" $1 mkdir -p $SAVE_PATH 2>&1 > /dev/null _ret=$? - if [ $_ret -ne 0 ]; then + if [[ $_ret -ne 0 ]]; then perror_exit "mkdir failed on $1:$SAVE_PATH" fi #check whether user has write permission on $1:$SAVE_PATH _dir=$(ssh -qn "${_opt[@]}" $1 mktemp -dqp $SAVE_PATH 2>/dev/null) _ret=$? - if [ $_ret -ne 0 ]; then + if [[ $_ret -ne 0 ]]; then perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" fi ssh -qn "${_opt[@]}" $1 rmdir $_dir @@ -164,11 +164,11 @@ check_size() { return esac - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then perror_exit "Check dump target size failed" fi - if [ $avail -lt $memtotal ]; then + if [[ $avail -lt $memtotal ]]; then dwarn "Warning: There might not be enough space to save a vmcore." dwarn " The size of $2 should be greater than $memtotal kilo bytes." fi @@ -178,7 +178,7 @@ check_save_path_fs() { local _path=$1 - if [ ! -d $_path ]; then + if [[ ! -d $_path ]]; then perror_exit "Dump path $_path does not exist." fi } @@ -190,7 +190,7 @@ mount_failure() local _fstype=$3 local msg="Failed to mount $_target" - if [ -n "$_mnt" ]; then + if [[ -n "$_mnt" ]]; then msg="$msg on $_mnt" fi @@ -210,11 +210,11 @@ check_user_configured_target() local _opt=$(get_mntopt_from_target $_target) local _fstype=$(get_fs_type_from_target $_target) - if [ -n "$_fstype" ]; then + if [[ -n "$_fstype" ]]; then # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf [[ $_fstype = "nfs"* ]] && _fstype=nfs - if [ -n "$_cfg_fs_type" ] && [ "$_fstype" != "$_cfg_fs_type" ]; then + if [[ -n "$_cfg_fs_type" ]] && [[ "$_fstype" != "$_cfg_fs_type" ]]; then perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\"" fi else @@ -224,11 +224,11 @@ check_user_configured_target() # For noauto mount, mount it inplace with default value. # Else use the temporary target directory - if [ -n "$_mnt" ]; then + if [[ -n "$_mnt" ]]; then if ! is_mounted "$_mnt"; then if [[ $_opt = *",noauto"* ]]; then mount $_mnt - [ $? -ne 0 ] && mount_failure "$_target" "$_mnt" "$_fstype" + [[ $? -ne 0 ]] && mount_failure "$_target" "$_mnt" "$_fstype" _mounted=$_mnt else perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" @@ -238,19 +238,19 @@ check_user_configured_target() _mnt=$MKDUMPRD_TMPMNT mkdir -p $_mnt mount $_target $_mnt -t $_fstype -o defaults - [ $? -ne 0 ] && mount_failure "$_target" "" "$_fstype" + [[ $? -ne 0 ]] && mount_failure "$_target" "" "$_fstype" _mounted=$_mnt fi # For user configured target, use $SAVE_PATH as the dump path within the target - if [ ! -d "$_mnt/$SAVE_PATH" ]; then + if [[ ! -d "$_mnt/$SAVE_PATH" ]]; then perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\"" fi check_size fs "$_target" # Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway - if [ -n "$_mounted" ]; then + if [[ -n "$_mounted" ]]; then umount -f -- $_mounted fi } @@ -260,7 +260,7 @@ verify_core_collector() { local _cmd="${1%% *}" local _params="${1#* }" - if [ "$_cmd" != "makedumpfile" ]; then + if [[ "$_cmd" != "makedumpfile" ]]; then if is_raw_dump_target; then dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually." fi @@ -284,7 +284,7 @@ verify_core_collector() { add_mount() { local _mnt=$(to_mount $@) - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then exit 1 fi @@ -316,7 +316,7 @@ for_each_block_target() local dev majmin for dev in $(get_kdump_targets); do - [ -b "$dev" ] || continue + [[ -b "$dev" ]] || continue majmin=$(get_maj_min $dev) check_block_and_slaves $1 $majmin && return 1 done @@ -331,10 +331,10 @@ is_unresettable() local path="/sys/$(udevadm info --query=all --path=/sys/dev/block/$1 | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" local resettable=1 - if [ -f "$path" ] + if [[ -f "$path" ]] then resettable="$(<"$path")" - [ $resettable -eq 0 -a "$OVERRIDE_RESETTABLE" -eq 0 ] && { + [[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && { local device=$(udevadm info --query=all --path=/sys/dev/block/$1 | awk -F= '/DEVNAME/{print $2}') derror "Error: Can not save vmcore because device $device is unresettable" return 0 @@ -359,7 +359,7 @@ check_resettable() for_each_block_target is_unresettable _ret=$? - [ $_ret -eq 0 ] && return + [[ $_ret -eq 0 ]] && return return 1 } @@ -385,7 +385,7 @@ fi # firstly get right SSH_KEY_LOCATION keyfile=$(kdump_get_conf_val sshkey) -if [ -f "$keyfile" ]; then +if [[ -f "$keyfile" ]]; then # canonicalize the path SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile) fi @@ -407,7 +407,7 @@ do perror_exit "Bad raw disk $config_val" } _praw=$(persistent_policy="by-id" kdump_get_persistent_dev $config_val) - if [ -z "$_praw" ]; then + if [[ -z "$_praw" ]]; then exit 1 fi add_dracut_arg "--device" "$_praw" @@ -438,7 +438,7 @@ done <<< "$(kdump_read_conf)" handle_default_dump_target -if [ -n "$extra_modules" ] +if [[ -n "$extra_modules" ]] then add_dracut_arg "--add-drivers" "$extra_modules" fi diff --git a/mkfadumprd b/mkfadumprd index 5c87933..ca9f362 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -2,7 +2,7 @@ # Generate an initramfs image that isolates dump capture capability within # the default initramfs using zz-fadumpinit dracut module. -if [ -f /etc/sysconfig/kdump ]; then +if [[ -f /etc/sysconfig/kdump ]]; then . /etc/sysconfig/kdump fi