]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(fcoe): shellcheck for modules.d/95fcoe
authorHarald Hoyer <harald@redhat.com>
Fri, 26 Mar 2021 09:29:26 +0000 (10:29 +0100)
committerHarald Hoyer <harald@hoyer.xyz>
Mon, 29 Mar 2021 11:21:55 +0000 (13:21 +0200)
modules.d/95fcoe/.shchkdir [new file with mode: 0644]
modules.d/95fcoe/fcoe-edd.sh
modules.d/95fcoe/fcoe-genrules.sh [deleted file]
modules.d/95fcoe/fcoe-up.sh
modules.d/95fcoe/module-setup.sh
modules.d/95fcoe/parse-fcoe.sh
modules.d/95fcoe/stop-fcoe.sh

diff --git a/modules.d/95fcoe/.shchkdir b/modules.d/95fcoe/.shchkdir
new file mode 100644 (file)
index 0000000..e69de29
index dd28724c784513b161bf0984e6e823e63ea97d35..17f8a7c1429dd63c99cc7bb7ad68ab640d229ad5 100755 (executable)
@@ -35,15 +35,15 @@ for disk in /sys/firmware/edd/int13_*; do
     for nic in "${disk}"/pci_dev/net/*; do
         [ -d "$nic" ] || continue
         if [ -n "${dev_port}" -a -e "${nic}/dev_port" ]; then
-            if [ "$(cat ${nic}/dev_port)" -ne "${dev_port}" ]; then
+            if [ "$(cat "${nic}"/dev_port)" -ne "${dev_port}" ]; then
                 continue
             fi
         fi
-        if [ -e ${nic}/address ]; then
+        if [ -e "${nic}"/address ]; then
             fcoe_interface=${nic##*/}
             if ! [ -e "/tmp/.fcoe-$fcoe_interface" ]; then
                 /sbin/fcoe-up "$fcoe_interface" "$dcb"
-                > "/tmp/.fcoe-$fcoe_interface"
+                > "/tmp/.fcoe-$fcoe_interface"
             fi
         fi
     done
diff --git a/modules.d/95fcoe/fcoe-genrules.sh b/modules.d/95fcoe/fcoe-genrules.sh
deleted file mode 100755 (executable)
index 3d9f47a..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-# We use (fcoe_interface or fcoe_mac) and fcoe_dcb as set by parse-fcoe.sh
-# If neither mac nor interface are set we don't continue
-[ -z "$fcoe_interface" -a -z "$fcoe_mac" ] && return
-
-# Write udev rules
-{
-    if [ -n "$fcoe_mac" ]; then
-        printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_mac" "$fcoe_dcb" "$fcoe_mode"
-        printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --timeout --unique --name fcoe-timeout-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_mac" "$fcoe_dcb" "$fcoe_mode"
-    else
-        printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_interface" "$fcoe_dcb" "$fcoe_mode"
-        printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --timeout --unique --name fcoe-timeout-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_interface" "$fcoe_dcb" "$fcoe_mode"
-    fi
-} >> /etc/udev/rules.d/92-fcoe.rules
index 17799e5046b06428fd2c2ac6d340a56a2db7b8db..3d670b7331ac5e35e45560b4b4a9cc29b45813df 100755 (executable)
@@ -18,42 +18,42 @@ dcb=$2
 mode=$3
 vlan="yes"
 
-iflink=$(cat /sys/class/net/$netif/iflink)
-ifindex=$(cat /sys/class/net/$netif/ifindex)
+iflink=$(cat /sys/class/net/"$netif"/iflink)
+ifindex=$(cat /sys/class/net/"$netif"/ifindex)
 if [ "$iflink" != "$ifindex" ]; then
     # Skip VLAN devices
     exit 0
 fi
 
-ip link set dev $netif up
+ip link set dev "$netif" up
 linkup "$netif"
 
 # Some fcoemon implementations expect --syslog=true
 syslogopt="--syslog"
 if fcoemon -h | grep syslog | grep -q yes; then
-    fcoemonyes="$syslogopt=yes"
+    syslogopt="$syslogopt=yes"
 fi
 
-netdriver=$(readlink -f /sys/class/net/$netif/device/driver)
+netdriver=$(readlink -f /sys/class/net/"$netif"/device/driver)
 netdriver=${netdriver##*/}
 
 write_fcoemon_cfg() {
-    [ -f /etc/fcoe/cfg-$netif ] && return
-    echo FCOE_ENABLE=\"yes\" > /etc/fcoe/cfg-$netif
+    [ -f /etc/fcoe/cfg-"$netif" ] && return
+    echo FCOE_ENABLE=\"yes\" > /etc/fcoe/cfg-"$netif"
     if [ "$dcb" = "dcb" ]; then
-        echo DCB_REQUIRED=\"yes\" >> /etc/fcoe/cfg-$netif
+        echo DCB_REQUIRED=\"yes\" >> /etc/fcoe/cfg-"$netif"
     else
-        echo DCB_REQUIRED=\"no\" >> /etc/fcoe/cfg-$netif
+        echo DCB_REQUIRED=\"no\" >> /etc/fcoe/cfg-"$netif"
     fi
     if [ "$vlan" = "yes" ]; then
-        echo AUTO_VLAN=\"yes\" >> /etc/fcoe/cfg-$netif
+        echo AUTO_VLAN=\"yes\" >> /etc/fcoe/cfg-"$netif"
     else
-        echo AUTO_VLAN=\"no\" >> /etc/fcoe/cfg-$netif
+        echo AUTO_VLAN=\"no\" >> /etc/fcoe/cfg-"$netif"
     fi
     if [ "$mode" = "vn2vn" ]; then
-        echo MODE=\"vn2vn\" >> /etc/fcoe/cfg-$netif
+        echo MODE=\"vn2vn\" >> /etc/fcoe/cfg-"$netif"
     else
-        echo MODE=\"fabric\" >> /etc/fcoe/cfg-$netif
+        echo MODE=\"fabric\" >> /etc/fcoe/cfg-"$netif"
     fi
 }
 
index c7fb32c22ad6550b5d909e736bdc5adf6c369eee..3de85c21ed9c2861fc0b7aed0599717d024c3fa7 100755 (executable)
@@ -3,14 +3,14 @@
 # called by dracut
 check() {
     is_fcoe() {
-        block_is_fcoe $1 || return 1
+        block_is_fcoe "$1" || return 1
     }
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         for_each_host_dev_and_slaves is_fcoe || return 255
     }
 
-    require_binaries dcbtool fipvlan lldpad ip readlink fcoemon fcoeadm || return 1
+    require_binaries dcbtool fipvlan lldpad ip readlink fcoemon fcoeadm tr || return 1
     return 0
 }
 
@@ -28,12 +28,12 @@ installkernel() {
 get_vlan_parent() {
     local link=$1
 
-    [ -d $link ] || return
-    read iflink < $link/iflink
+    [ -d "$link" ] || return
+    read -r iflink < "$link"/iflink
     for if in /sys/class/net/*; do
-        read idx < $if/ifindex
-        if [ $idx -eq $iflink ]; then
-            echo ${if##*/}
+        read -r idx < "$if"/ifindex
+        if [ "$idx" -eq "$iflink" ]; then
+            echo "${if##*/}"
         fi
     done
 }
@@ -42,27 +42,27 @@ get_vlan_parent() {
 cmdline() {
     {
         for c in /sys/bus/fcoe/devices/ctlr_*; do
-            [ -L $c ] || continue
-            read enabled < $c/enabled
-            read mode < $c/mode
-            [ $enabled -eq 0 ] && continue
-            if [ $mode = "VN2VN" ]; then
+            [ -L "$c" ] || continue
+            read -r enabled < "$c"/enabled
+            read -r mode < "$c"/mode
+            [ "$enabled" -eq 0 ] && continue
+            if [ "$mode" = "VN2VN" ]; then
                 mode="vn2vn"
             else
                 mode="fabric"
             fi
             d=$(
-                cd -P $c
-                echo $PWD
+                cd -P "$c" || exit
+                echo "$PWD"
             )
             i=${d%/*}
             ifname=${i##*/}
-            read mac < ${i}/address
-            s=$(dcbtool gc ${i##*/} dcb 2> /dev/null | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
+            read -r mac < "${i}"/address
+            s=$(dcbtool gc "${i##*/}" dcb 2> /dev/null | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
             if [ -z "$s" ]; then
-                p=$(get_vlan_parent ${i})
+                p=$(get_vlan_parent "${i}")
                 if [ "$p" ]; then
-                    s=$(dcbtool gc ${p} dcb 2> /dev/null | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
+                    s=$(dcbtool gc "${p}" dcb 2> /dev/null | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
                     ifname=${p##*/}
                 fi
             fi
@@ -78,11 +78,14 @@ cmdline() {
             # DCB_REQUIRED in "/etc/fcoe/cfg-xxx" is expected to set to "no".
             #
             # Force "nodcb" if there's any DCB_REQUIRED="no"(child or vlan parent).
-            grep -q '^[[:blank:]]*DCB_REQUIRED="no"' /etc/fcoe/cfg-${i##*/} &> /dev/null
-            [ $? -eq 0 ] && dcb="nodcb"
+            if grep -q '^[[:blank:]]*DCB_REQUIRED="no"' /etc/fcoe/cfg-"${i##*/}" &> /dev/null; then
+                dcb="nodcb"
+            fi
+
             if [ "$p" ]; then
-                grep -q '^[[:blank:]]*DCB_REQUIRED="no"' /etc/fcoe/cfg-${p} &> /dev/null
-                [ $? -eq 0 ] && dcb="nodcb"
+                if grep -q '^[[:blank:]]*DCB_REQUIRED="no"' /etc/fcoe/cfg-"${p}" &> /dev/null; then
+                    dcb="nodcb"
+                fi
             fi
 
             echo "ifname=${ifname}:${mac}"
@@ -93,7 +96,7 @@ cmdline() {
 
 # called by dracut
 install() {
-    inst_multiple ip dcbtool fipvlan lldpad readlink lldptool fcoemon fcoeadm
+    inst_multiple ip dcbtool fipvlan lldpad readlink lldptool fcoemon fcoeadm tr
     if [[ -e $dracutsysrootdir/etc/hba.conf ]]; then
         inst_libdir_file 'libhbalinux.so*'
         inst_simple "/etc/hba.conf"
@@ -103,14 +106,14 @@ install() {
     mkdir -m 0755 -p "$initdir/etc/fcoe"
 
     if [[ $hostonly_cmdline == "yes" ]]; then
-        local _fcoeconf=$(cmdline)
+        local _fcoeconf
+        _fcoeconf=$(cmdline)
         [[ $_fcoeconf ]] && printf "%s\n" "$_fcoeconf" >> "${initdir}/etc/cmdline.d/95fcoe.conf"
     fi
     inst_multiple "/etc/fcoe/cfg-*"
 
     inst "$moddir/fcoe-up.sh" "/sbin/fcoe-up"
     inst "$moddir/fcoe-edd.sh" "/sbin/fcoe-edd"
-    inst "$moddir/fcoe-genrules.sh" "/sbin/fcoe-genrules.sh"
     inst_hook pre-trigger 03 "$moddir/lldpad.sh"
     inst_hook cmdline 99 "$moddir/parse-fcoe.sh"
     inst_hook cleanup 90 "$moddir/cleanup-fcoe.sh"
index c165cefcfa24f3c7b9cc09af962602ff37ae264c..bde6b62f53415ffddefc39bf790dd0679ef59d26 100755 (executable)
 # fcoe=eth0:nodcb:vn2vn
 # fcoe=4a:3f:4c:04:f8:d7:nodcb:fabric
 
+if [ -z "$fcoe" ] && ! getarg fcoe=; then
+    # If it's not set we don't continue
+    return 0
+fi
+
 if ! getargbool 1 rd.fcoe -d -n rd.nofcoe; then
     info "rd.fcoe=0: skipping fcoe"
     return 0
 fi
 
-[ -z "$fcoe" ] && fcoe=$(getarg fcoe=)
-
-# If it's not set we don't continue
-[ -z "$fcoe" ] && return
-
-[ -e /sys/bus/fcoe/ctlr_create ] || modprobe -b -a fcoe || modprobe -b -a libfcoe || die "FCoE requested but kernel/initrd does not support FCoE"
+if ! [ -e /sys/bus/fcoe/ctlr_create ] && ! modprobe -b -a fcoe && ! modprobe -b -a libfcoe; then
+    die "FCoE requested but kernel/initrd does not support FCoE"
+fi
 
 initqueue --onetime modprobe -b -q bnx2fc
 
 parse_fcoe_opts() {
+    local fcoe_interface
+    local fcoe_dcb
+    local fcoe_mode
+    local fcoe_mac
     local OLDIFS="$IFS"
     local IFS=:
-    set $fcoe
+    # shellcheck disable=SC2086
+    # shellcheck disable=SC2048
+    set -- $*
     IFS="$OLDIFS"
 
     case $# in
@@ -38,48 +46,61 @@ parse_fcoe_opts() {
             fcoe_interface=$1
             fcoe_dcb=$2
             fcoe_mode="fabric"
-            return 0
+            unset fcoe_mac
             ;;
         3)
             fcoe_interface=$1
             fcoe_dcb=$2
             fcoe_mode=$3
-            return 0
+            unset fcoe_mac
             ;;
         7)
-            fcoe_mac=$1:$2:$3:$4:$5:$6
+            fcoe_mac=$(echo "$1:$2:$3:$4:$5:$6" | tr "[:upper:]" "[:lower:]")
             fcoe_dcb=$7
             fcoe_mode="fabric"
-            return 0
+            unset fcoe_interface
             ;;
         8)
-            fcoe_mac=$1:$2:$3:$4:$5:$6
+            fcoe_mac=$(echo "$1:$2:$3:$4:$5:$6" | tr "[:upper:]" "[:lower:]")
             fcoe_dcb=$7
             fcoe_mode=$8
-            return 0
+            unset fcoe_interface
             ;;
         *)
             warn "Invalid arguments for fcoe=$fcoe"
             return 1
             ;;
     esac
-}
-
-parse_fcoe_opts
 
-if [ "$fcoe_interface" = "edd" ]; then
     if [ "$fcoe_dcb" != "nodcb" -a "$fcoe_dcb" != "dcb" ]; then
         warn "Invalid FCoE DCB option: $fcoe_dcb"
     fi
-    /sbin/initqueue --settled --unique /sbin/fcoe-edd $fcoe_dcb
-else
-    for fcoe in $(getargs fcoe=); do
-        unset fcoe_mac
-        unset fcoe_interface
-        parse_fcoe_opts
-        if [ "$fcoe_dcb" != "nodcb" -a "$fcoe_dcb" != "dcb" ]; then
-            warn "Invalid FCoE DCB option: $fcoe_dcb"
+
+    if [ "$fcoe_interface" = "edd" ]; then
+        /sbin/initqueue --settled --unique /sbin/fcoe-edd "$fcoe_dcb"
+        return 0
+    fi
+
+    if [ -z "$fcoe_interface" -a -z "$fcoe_mac" ]; then
+        warn "fcoe: Neither interface nor MAC specified for fcoe=$fcoe"
+        return 1
+    fi
+
+    {
+        if [ -n "$fcoe_mac" ]; then
+            # shellcheck disable=SC2016
+            printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_mac" "$fcoe_dcb" "$fcoe_mode"
+            # shellcheck disable=SC2016
+            printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --timeout --unique --name fcoe-timeout-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_mac" "$fcoe_dcb" "$fcoe_mode"
+        else
+            # shellcheck disable=SC2016
+            printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_interface" "$fcoe_dcb" "$fcoe_mode"
+            # shellcheck disable=SC2016
+            printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --timeout --unique --name fcoe-timeout-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_interface" "$fcoe_dcb" "$fcoe_mode"
         fi
-        . $(command -v fcoe-genrules.sh)
-    done
-fi
+    } >> /etc/udev/rules.d/92-fcoe.rules
+}
+
+for fcoe in $fcoe $(getargs fcoe=); do
+    parse_fcoe_opts "$fcoe"
+done
index bd523c9d71824509bba0cc8d3fb3f1d72ac1daf7..f481d56736d4d8d8077cb2282a7b13b19ee1498f 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
 for f in /sys/bus/fcoe/devices/ctlr_*; do
-    [ -e $f ] || continue
-    echo 0 > $f/enabled
+    [ -e "$f" ] || continue
+    echo 0 > "$f"/enabled
 done