From 032ecd95c94b77f3f08237e0f765b355dacb9573 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 26 Mar 2021 10:29:30 +0100 Subject: [PATCH] fix(zfcp_rules): shellcheck for modules.d/95zfcp_rules --- modules.d/95zfcp_rules/.shchkdir | 0 modules.d/95zfcp_rules/module-setup.sh | 19 +++++++++-------- modules.d/95zfcp_rules/parse-zfcp.sh | 29 +++++++++++++------------- 3 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 modules.d/95zfcp_rules/.shchkdir diff --git a/modules.d/95zfcp_rules/.shchkdir b/modules.d/95zfcp_rules/.shchkdir new file mode 100644 index 000000000..e69de29bb diff --git a/modules.d/95zfcp_rules/module-setup.sh b/modules.d/95zfcp_rules/module-setup.sh index cf8cf0552..b93e007cc 100755 --- a/modules.d/95zfcp_rules/module-setup.sh +++ b/modules.d/95zfcp_rules/module-setup.sh @@ -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 diff --git a/modules.d/95zfcp_rules/parse-zfcp.sh b/modules.d/95zfcp_rules/parse-zfcp.sh index 7ea49c840..499bfe38c 100755 --- a/modules.d/95zfcp_rules/parse-zfcp.sh +++ b/modules.d/95zfcp_rules/parse-zfcp.sh @@ -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 -- 2.47.2