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

diff --git a/modules.d/95zfcp_rules/.shchkdir b/modules.d/95zfcp_rules/.shchkdir
new file mode 100644 (file)
index 0000000..e69de29
index cf8cf055265a8a04a20e916a2d9142bf5e44a498..b93e007ccb197275e3ef9a22f4043f250170d6db 100755 (executable)
@@ -4,9 +4,10 @@
 cmdline() {
     is_zfcp() {
         local _dev=$1
-        local _devpath=$(
-            cd -P /sys/dev/block/$_dev
-            echo $PWD
+        local _devpath
+        _devpath=$(
+            cd -P /sys/dev/block/"$_dev" || exit
+            echo "$PWD"
         )
         local _sdev _scsiid _hostno _lun _wwpn _ccw _port_type
         local _allow_lun_scan _is_npiv
@@ -14,22 +15,22 @@ cmdline() {
         _allow_lun_scan=$(cat /sys/module/zfcp/parameters/allow_lun_scan)
         [ "${_devpath#*/sd}" == "$_devpath" ] && return 1
         _sdev="${_devpath%%/block/*}"
-        [ -e ${_sdev}/fcp_lun ] || return 1
+        [ -e "${_sdev}"/fcp_lun ] || return 1
         _scsiid="${_sdev##*/}"
         _hostno="${_scsiid%%:*}"
-        [ -d /sys/class/fc_host/host${_hostno} ] || return 1
-        _port_type=$(cat /sys/class/fc_host/host${_hostno}/port_type)
+        [ -d /sys/class/fc_host/host"${_hostno}" ] || return 1
+        _port_type=$(cat /sys/class/fc_host/host"${_hostno}"/port_type)
         case "$_port_type" in
             NPIV*)
                 _is_npiv=1
                 ;;
         esac
-        _ccw=$(cat ${_sdev}/hba_id)
+        _ccw=$(cat "${_sdev}"/hba_id)
         if [ "$_is_npiv" ] && [ "$_allow_lun_scan" = "Y" ]; then
             echo "rd.zfcp=${_ccw}"
         else
-            _lun=$(cat ${_sdev}/fcp_lun)
-            _wwpn=$(cat ${_sdev}/wwpn)
+            _lun=$(cat "${_sdev}"/fcp_lun)
+            _wwpn=$(cat "${_sdev}"/wwpn)
             echo "rd.zfcp=${_ccw},${_wwpn},${_lun}"
         fi
         return 0
index 7ea49c840a1fcf456f92873d116e7fb89c19258a..499bfe38cbcd42511b38f4b864ee89779f28f797 100755 (executable)
@@ -7,13 +7,13 @@ create_udev_rule() {
     local _rule=/etc/udev/rules.d/51-zfcp-${ccw}.rules
     local _cu_type _dev_type
 
-    if [ -x /sbin/cio_ignore ] && cio_ignore -i $ccw > /dev/null; then
-        cio_ignore -r $ccw
+    if [ -x /sbin/cio_ignore ] && cio_ignore -i "$ccw" > /dev/null; then
+        cio_ignore -r "$ccw"
     fi
 
-    if [ -e /sys/bus/ccw/devices/${ccw} ]; then
-        read _cu_type < /sys/bus/ccw/devices/${ccw}/cutype
-        read _dev_type < /sys/bus/ccw/devices/${ccw}/devtype
+    if [ -e /sys/bus/ccw/devices/"${ccw}" ]; then
+        read -r _cu_type < /sys/bus/ccw/devices/"${ccw}"/cutype
+        read -r _dev_type < /sys/bus/ccw/devices/"${ccw}"/devtype
     fi
     if [ "$_cu_type" != "1731/03" ]; then
         return 0
@@ -23,21 +23,21 @@ create_udev_rule() {
     fi
 
     if [ ! -f "$_rule" ]; then
-        cat > $_rule << EOF
+        cat > "$_rule" << EOF
 ACTION=="add", SUBSYSTEM=="ccw", KERNEL=="$ccw", IMPORT{program}="collect $ccw %k ${ccw} zfcp"
 ACTION=="add", SUBSYSTEM=="drivers", KERNEL=="zfcp", IMPORT{program}="collect $ccw %k ${ccw} zfcp"
 ACTION=="add", ENV{COLLECT_$ccw}=="0", ATTR{[ccw/$ccw]online}="1"
 EOF
     fi
     [ -z "$wwpn" ] || [ -z "$lun" ] && return
-    m=$(sed -n "/.*${wwpn}.*${lun}.*/p" $_rule)
+    m=$(sed -n "/.*${wwpn}.*${lun}.*/p" "$_rule")
     if [ -z "$m" ]; then
-        cat >> $_rule << EOF
+        cat >> "$_rule" << EOF
 ACTION=="add", KERNEL=="rport-*", ATTR{port_name}=="$wwpn", SUBSYSTEMS=="ccw", KERNELS=="$ccw", ATTR{[ccw/$ccw]$wwpn/unit_add}="$lun"
 EOF
     fi
-    if [ -x /sbin/cio_ignore ] && ! cio_ignore -i $ccw > /dev/null; then
-        cio_ignore -r $ccw
+    if [ -x /sbin/cio_ignore ] && ! cio_ignore -i "$ccw" > /dev/null; then
+        cio_ignore -r "$ccw"
     fi
 }
 
@@ -48,7 +48,7 @@ if [[ -f /sys/firmware/ipl/ipl_type && \
         _lun=$(cat /sys/firmware/ipl/lun)
         _ccw=$(cat /sys/firmware/ipl/device)
 
-        create_udev_rule $_ccw $_wwpn $_lun
+        create_udev_rule "$_ccw" "$_wwpn" "$_lun"
     )
 fi
 
@@ -56,9 +56,10 @@ for zfcp_arg in $(getargs rd.zfcp); do
     (
         OLDIFS="$IFS"
         IFS=","
+        # shellcheck disable=SC2086
         set $zfcp_arg
         IFS="$OLDIFS"
-        create_udev_rule $1 $2 $3
+        create_udev_rule "$1" "$2" "$3"
     )
 done
 
@@ -72,11 +73,11 @@ for zfcp_arg in $(getargs root=) $(getargs resume=); do
         if [ -n "$ccw_arg" ]; then
             OLDIFS="$IFS"
             IFS="-"
-            set -- $ccw_arg
+            set -- "$ccw_arg"
             IFS="$OLDIFS"
             _wwpn=${4%:*}
             _lun=${4#*:}
-            create_udev_rule $2 $wwpn $lun
+            create_udev_rule "$2" "$wwpn" "$lun"
         fi
     )
 done