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

diff --git a/modules.d/95dasd_rules/.shchkdir b/modules.d/95dasd_rules/.shchkdir
new file mode 100644 (file)
index 0000000..e69de29
index 3c43902a04ab8b50d0c6d5bdaf825bb240c7eb7d..bcd58589a1e59d9f0033733b226ccf8771123d01 100755 (executable)
@@ -4,9 +4,10 @@
 cmdline() {
     is_dasd() {
         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"
         )
 
         [ "${_devpath#*/dasd}" == "$_devpath" ] && return 1
@@ -52,7 +53,8 @@ install() {
     inst_multiple /usr/lib/udev/collect
     inst_hook cmdline 30 "$moddir/parse-dasd.sh"
     if [[ $hostonly_cmdline == "yes" ]]; then
-        local _dasd=$(cmdline)
+        local _dasd
+        _dasd=$(cmdline)
         [[ $_dasd ]] && printf "%s\n" "$_dasd" >> "${initdir}/etc/cmdline.d/95dasd.conf"
     fi
     if [[ $hostonly ]]; then
index bd7384c297f26e476ae7a788b6cd3224d77f1494..ec78a7f33e84d1bd4641bd0ba073b6ec5d945dad 100755 (executable)
@@ -3,16 +3,17 @@
 create_udev_rule() {
     local ccw=$1
     local _drv _cu_type _dev_type
-    local _rule=/etc/udev/rules.d/51-dasd-${ccw}.rules
+    local _rule="/etc/udev/rules.d/51-dasd-${ccw}.rules"
 
-    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
+
     case "$_cu_type" in
         3990/* | 2105/* | 2107/* | 1750/* | 9343/*)
             _drv=dasd-eckd
@@ -33,85 +34,45 @@ create_udev_rule() {
     esac
     [ -z "${_drv}" ] && return 0
 
-    [ -e ${_rule} ] && return 0
+    [ -e "${_rule}" ] && return 0
 
-    cat > $_rule << EOF
+    cat > "$_rule" << EOF
 ACTION=="add", SUBSYSTEM=="ccw", KERNEL=="$ccw", IMPORT{program}="collect $ccw %k ${ccw} $_drv"
 ACTION=="add", SUBSYSTEM=="drivers", KERNEL=="$_drv", IMPORT{program}="collect $ccw %k ${ccw} $_drv"
 ACTION=="add", ENV{COLLECT_$ccw}=="0", ATTR{[ccw/$ccw]online}="1"
 EOF
 }
 
-if [[ -f /sys/firmware/ipl/ipl_type && \
-    $(< /sys/firmware/ipl/ipl_type) == "ccw" ]]; then
-    (
-        _ccw=$(cat /sys/firmware/ipl/device)
-
-        create_udev_rule $_ccw
-    )
+if [[ -f /sys/firmware/ipl/ipl_type ]] && [[ $(< /sys/firmware/ipl/ipl_type) == "ccw" ]]; then
+    create_udev_rule "$(< /sys/firmware/ipl/device)"
 fi
 
 for dasd_arg in $(getargs root=) $(getargs resume=); do
-    (
-        case $dasd_arg in
-            /dev/disk/by-path/ccw-*)
-                ccw_arg=${dasd_arg##*/}
-                ;;
-        esac
-        if [ -n "$ccw_arg" ]; then
-            OLDIFS="$IFS"
-            IFS="-"
-            set -- $ccw_arg
-            IFS="$OLDIFS"
-            create_udev_rule $2
-        fi
-    )
+    [[ $dasd_arg =~ /dev/disk/by-path/ccw-* ]] || continue
+
+    ccw_dev="${dasd_arg##*/ccw-}"
+    create_udev_rule "${ccw_dev%%-*}"
 done
 
 for dasd_arg in $(getargs rd.dasd=); do
-    (
-        OLDIFS="$IFS"
-        IFS=","
-        set -- $dasd_arg
-        IFS="$OLDIFS"
-        while (($# > 0)); do
-            case $1 in
-                autodetect | probeonly)
-                    shift
-                    ;;
-                *-*)
-                    range=$1
-                    OLDIFS="$IFS"
-                    IFS="-"
-                    set -- $range
-                    prefix=${1%.*}
-                    start=${1##*.}
-                    shift
-                    end=${1##.}
-                    shift
-                    IFS="$OLDIFS"
-                    for dev in $(seq $((16#$start)) $((16#$end))); do
-                        create_udev_rule "$(printf "%s.%04x" "$prefix" "$dev")"
-                    done
-                    ;;
-                *)
-                    dev=${1%(ro)}
-                    if [ "$dev" != "$1" ]; then
-                        ro=1
-                    fi
-                    OLDIFS="$IFS"
-                    IFS="."
-                    set -- $dev
-                    sid=$1
-                    shift
-                    ssid=$1
-                    shift
-                    chan=$1
-                    IFS="$OLDIFS"
-                    create_udev_rule "$(printf "%01x.%01x.%04x" $((16#$sid)) $((16#$ssid)) $((16#$chan)))"
-                    shift
-                    ;;
-            esac
-        done
-    )
+    IFS=',' read -r -a devs <<< "$dasd_arg"
+    declare -p devs
+    for dev in "${devs[@]}"; do
+        case "$dev" in
+            autodetect | probeonly) ;;
+
+            *-*)
+                IFS="-" read -r start end _ <<< "${dev%(ro)}"
+                prefix=${start%.*}
+                start=${start##*.}
+                for rdev in $(seq $((16#$start)) $((16#$end))); do
+                    create_udev_rule "$(printf "%s.%04x" "$prefix" "$rdev")"
+                done
+                ;;
+            *)
+                IFS="." read -r sid ssid chan _ <<< "${dev%(ro)}"
+                create_udev_rule "$(printf "%01x.%01x.%04x" $((16#$sid)) $((16#$ssid)) $((16#$chan)))"
+                ;;
+        esac
+    done
 done