bash scripts: use $(...) notation instead of legacy `...`

upstream: fedora
resolves: bz2003832
conflict: none

commit 54cc5c44befa308e122d93221c65486164ffb3e5
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 01:48:52 2021 +0800

    bash scripts: use $(...) notation instead of legacy `...`

    This is a batch update done with following command:

    `sed -i -e 's/`\([^`]*\)`/\$(\1)/g' mkfadumprd mkdumprd \
     kdumpctl dracut-module-setup.sh dracut-fadump-module-setup.sh \
     dracut-early-kdump-module-setup.sh`

    And manually converted some corner cases. This fixes
    all related issues detected by shellcheck.
    Make it easier to do clean up in later commits.

    Check following link for reasons to switch to the new syntax:
    https://github.com/koalaman/shellcheck/wiki/SC2006

    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 16:24:01 +08:00
parent 67611bba2a
commit 16c2821171
2 changed files with 26 additions and 27 deletions

View File

@ -266,8 +266,8 @@ kdump_static_ip() {
/sbin/ip $_ipv6_flag route show | grep -v default |\ /sbin/ip $_ipv6_flag route show | grep -v default |\
grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\ grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\
while read -r _route; do while read -r _route; do
_target=`echo $_route | cut -d ' ' -f1` _target=$(echo $_route | cut -d ' ' -f1)
_nexthop=`echo $_route | cut -d ' ' -f3` _nexthop=$(echo $_route | cut -d ' ' -f3)
if [ "x" != "x"$_ipv6_flag ]; then if [ "x" != "x"$_ipv6_flag ]; then
_target="[$_target]" _target="[$_target]"
_nexthop="[$_nexthop]" _nexthop="[$_nexthop]"
@ -293,9 +293,9 @@ kdump_handle_mulitpath_route() {
[[ "$_target" == 'default' ]] && continue [[ "$_target" == 'default' ]] && continue
[[ "$_route" =~ .*via.*\ $_netdev ]] || continue [[ "$_route" =~ .*via.*\ $_netdev ]] || continue
_weight=`echo "$_route" | cut -d ' ' -f7` _weight=$(echo "$_route" | cut -d ' ' -f7)
if [[ "$_weight" -gt "$_max_weight" ]]; then if [[ "$_weight" -gt "$_max_weight" ]]; then
_nexthop=`echo "$_route" | cut -d ' ' -f3` _nexthop=$(echo "$_route" | cut -d ' ' -f3)
_max_weight=$_weight _max_weight=$_weight
if [ "x" != "x"$_ipv6_flag ]; then if [ "x" != "x"$_ipv6_flag ]; then
_rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic"
@ -305,7 +305,7 @@ kdump_handle_mulitpath_route() {
fi fi
else else
[[ -n "$_rule" ]] && echo "$_rule" [[ -n "$_rule" ]] && echo "$_rule"
_target=`echo "$_route" | cut -d ' ' -f1` _target=$(echo "$_route" | cut -d ' ' -f1)
_rule="" _max_weight=0 _weight=0 _rule="" _max_weight=0 _weight=0
fi fi
done >> ${initdir}/etc/cmdline.d/45route-static.conf\ done >> ${initdir}/etc/cmdline.d/45route-static.conf\
@ -383,7 +383,7 @@ kdump_setup_bond() {
local _netdev="$1" local _netdev="$1"
local _nm_show_cmd="$2" local _nm_show_cmd="$2"
local _dev _mac _slaves _kdumpdev _bondoptions local _dev _mac _slaves _kdumpdev _bondoptions
for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do for _dev in $(cat /sys/class/net/$_netdev/bonding/slaves); do
_mac=$(kdump_get_perm_addr $_dev) _mac=$(kdump_get_perm_addr $_dev)
_kdumpdev=$(kdump_setup_ifname $_dev) _kdumpdev=$(kdump_setup_ifname $_dev)
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf
@ -410,7 +410,7 @@ kdump_setup_bond() {
kdump_setup_team() { kdump_setup_team() {
local _netdev=$1 local _netdev=$1
local _dev _mac _slaves _kdumpdev local _dev _mac _slaves _kdumpdev
for _dev in `teamnl $_netdev ports | awk -F':' '{print $2}'`; do for _dev in $(teamnl $_netdev ports | awk -F':' '{print $2}'); do
_mac=$(kdump_get_perm_addr $_dev) _mac=$(kdump_get_perm_addr $_dev)
_kdumpdev=$(kdump_setup_ifname $_dev) _kdumpdev=$(kdump_setup_ifname $_dev)
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf
@ -529,11 +529,11 @@ kdump_get_remote_ip()
{ {
local _remote=$(get_remote_host $1) _remote_temp local _remote=$(get_remote_host $1) _remote_temp
if is_hostname $_remote; then if is_hostname $_remote; then
_remote_temp=`getent ahosts $_remote | grep -v : | head -n 1` _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` _remote_temp=$(getent ahosts $_remote | head -n 1)
fi fi
_remote=`echo $_remote_temp | cut -d' ' -f1` _remote=$(echo $_remote_temp | cut -d' ' -f1)
fi fi
echo $_remote echo $_remote
} }
@ -905,7 +905,7 @@ get_pcs_fence_kdump_nodes() {
pcs cluster sync > /dev/null 2>&1 && pcs cluster cib-upgrade > /dev/null 2>&1 pcs cluster sync > /dev/null 2>&1 && pcs cluster cib-upgrade > /dev/null 2>&1
# get cluster nodes from cluster cib, get interface and ip address # get cluster nodes from cluster cib, get interface and ip address
nodelist=`pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -` nodelist=$(pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -)
# nodelist is formed as 'uname="node1" uname="node2" ... uname="nodeX"' # nodelist is formed as 'uname="node1" uname="node2" ... uname="nodeX"'
# we need to convert each to node1, node2 ... nodeX in each iteration # we need to convert each to node1, node2 ... nodeX in each iteration

View File

@ -76,7 +76,7 @@ determine_dump_mode()
save_core() save_core()
{ {
coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`" coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")"
mkdir -p $coredir mkdir -p $coredir
ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete"
@ -290,15 +290,14 @@ get_pcs_cluster_modified_files()
is_generic_fence_kdump && return 1 is_generic_fence_kdump && return 1
is_pcs_fence_kdump || return 1 is_pcs_fence_kdump || return 1
time_stamp=`pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | \ time_stamp=$(pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | xargs -0 date +%s --date)
xargs -0 date +%s --date`
if [ -n $time_stamp -a $time_stamp -gt $image_time ]; then if [ -n $time_stamp -a $time_stamp -gt $image_time ]; then
modified_files="cluster-cib" modified_files="cluster-cib"
fi fi
if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then
time_stamp=`stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE` 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" modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE"
fi fi
@ -358,7 +357,7 @@ check_files_modified()
fi fi
HOOKS="$HOOKS $POST_FILES $PRE_FILES" HOOKS="$HOOKS $POST_FILES $PRE_FILES"
CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}') CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}')
CORE_COLLECTOR=`type -P $CORE_COLLECTOR` CORE_COLLECTOR=$(type -P $CORE_COLLECTOR)
# POST_FILES and PRE_FILES are already checked against executable, need not to check again. # POST_FILES and PRE_FILES are already checked against executable, need not to check again.
EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" EXTRA_BINS="$EXTRA_BINS $CHECK_FILES"
CHECK_FILES=$(kdump_get_conf_val extra_bins) CHECK_FILES=$(kdump_get_conf_val extra_bins)
@ -395,13 +394,13 @@ check_files_modified()
for file in $files; do for file in $files; do
if [ -e "$file" ]; then if [ -e "$file" ]; then
time_stamp=`stat -c "%Y" $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" modified_files="$modified_files $file"
fi fi
if [ -L "$file" ]; then if [ -L "$file" ]; then
file=$(readlink -m $file) file=$(readlink -m $file)
time_stamp=`stat -c "%Y" $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" modified_files="$modified_files $file"
fi fi
@ -591,7 +590,7 @@ check_rebuild()
#check to see if dependent files has been modified #check to see if dependent files has been modified
#since last build of the image file #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` image_time=$(stat -c "%Y" $TARGET_INITRD 2>/dev/null)
#in case of fadump mode, check whether the default/target #in case of fadump mode, check whether the default/target
#initrd is already built with dump capture capability #initrd is already built with dump capture capability
@ -696,7 +695,7 @@ check_ssh_config()
done <<< "$(kdump_read_conf)" done <<< "$(kdump_read_conf)"
#make sure they've configured kdump.conf for ssh dumps #make sure they've configured kdump.conf for ssh dumps
local SSH_TARGET=`echo -n $DUMP_TARGET | sed -n '/.*@/p'` local SSH_TARGET=$(echo -n $DUMP_TARGET | sed -n '/.*@/p')
if [ -z "$SSH_TARGET" ]; then if [ -z "$SSH_TARGET" ]; then
return 1 return 1
fi fi
@ -783,8 +782,8 @@ propagate_ssh_key()
fi fi
#now find the target ssh user and server to contact. #now find the target ssh user and server to contact.
SSH_USER=`echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1` SSH_USER=$(echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1)
SSH_SERVER=`echo $DUMP_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/'` SSH_SERVER=$(echo $DUMP_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/')
#now send the found key to the found server #now send the found key to the found server
ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER
@ -813,7 +812,7 @@ check_current_fadump_status()
{ {
# Check if firmware-assisted dump has been registered. # Check if firmware-assisted dump has been registered.
rc=$(<$FADUMP_REGISTER_SYS_NODE) rc=$(<$FADUMP_REGISTER_SYS_NODE)
[[ $rc -eq 1 ]] && return 0 [ $rc -eq 1 ] && return 0
return 1 return 1
} }
@ -846,9 +845,9 @@ save_raw()
fi fi
kdump_dir=$(kdump_get_conf_val path) 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"`" coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")"
else else
coredir="${kdump_dir}/`date +"%Y-%m-%d-%H:%M"`" coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")"
fi fi
mkdir -p "$coredir" mkdir -p "$coredir"
@ -925,8 +924,8 @@ selinux_relabel()
check_fence_kdump_config() check_fence_kdump_config()
{ {
local hostname=`hostname` local hostname=$(hostname)
local ipaddrs=`hostname -I` local ipaddrs=$(hostname -I)
local nodes=$(kdump_get_conf_val "fence_kdump_nodes") local nodes=$(kdump_get_conf_val "fence_kdump_nodes")
for node in $nodes; do for node in $nodes; do