]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(mdraid): shellcheck for modules.d/90mdraid
authorHarald Hoyer <harald@redhat.com>
Fri, 26 Mar 2021 09:29:22 +0000 (10:29 +0100)
committerHarald Hoyer <harald@hoyer.xyz>
Tue, 30 Mar 2021 02:16:57 +0000 (04:16 +0200)
modules.d/90mdraid/.shchkdir [new file with mode: 0644]
modules.d/90mdraid/md-shutdown.sh
modules.d/90mdraid/mdmon-pre-shutdown.sh
modules.d/90mdraid/mdraid-cleanup.sh
modules.d/90mdraid/mdraid-waitclean.sh
modules.d/90mdraid/mdraid_start.sh
modules.d/90mdraid/module-setup.sh
modules.d/90mdraid/parse-md.sh

diff --git a/modules.d/90mdraid/.shchkdir b/modules.d/90mdraid/.shchkdir
new file mode 100644 (file)
index 0000000..e69de29
index 3b87ad6d274f5327a08e85ed15f22211c1571bb6..5562ddb4aa43235e996227012e4e41b239ead1e4 100755 (executable)
@@ -17,7 +17,7 @@ _do_md_shutdown() {
 }
 
 if command -v mdadm > /dev/null; then
-    _do_md_shutdown $1
+    _do_md_shutdown "$1"
 else
     :
 fi
index 83c021bd40a39155cc793d4df7fa4676ccb7d63a..a5cd8509769478a23bfbf440f2134c6e79ad90a9 100755 (executable)
@@ -9,5 +9,5 @@ _do_mdmon_takeover() {
 }
 
 if command -v mdmon > /dev/null; then
-    _do_mdmon_takeover $1
+    _do_mdmon_takeover "$1"
 fi
index 4b7ae19dbf1ed7bbbb587fb9c05ce389fc3c6c9b..7cf17dd946b33221d8b04d26a7bc64f31f3c3972 100755 (executable)
@@ -5,7 +5,7 @@ type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
 containers=""
 for md in /dev/md[0-9_]*; do
     [ -b "$md" ] || continue
-    udevinfo="$(udevadm info --query=env --name=$md)"
+    udevinfo="$(udevadm info --query=env --name="$md")"
     strstr "$udevinfo" "DEVTYPE=partition" && continue
     if strstr "$udevinfo" "MD_LEVEL=container"; then
         containers="$containers $md"
index 6f166e2aae46b6a5a45ca4ac2b5822e3b3464fdc..557a62332add7a441d37e44c66a9013dbc3dfe4c 100755 (executable)
@@ -5,7 +5,7 @@ if getargbool 0 rd.md.waitclean; then
     containers=""
     for md in /dev/md[0-9_]*; do
         [ -b "$md" ] || continue
-        udevinfo="$(udevadm info --query=env --name=$md)"
+        udevinfo="$(udevadm info --query=env --name="$md")"
         strstr "$udevinfo" "DEVTYPE=partition" && continue
         if strstr "$udevinfo" "MD_LEVEL=container"; then
             containers="$containers $md"
index 325835a93d1cb2ae74bd2774722f859104f768aa..9ac171d3c8ee0054aa67aeb3285a23b5faaf1578 100755 (executable)
@@ -31,7 +31,9 @@ _md_start() {
 _md_force_run() {
     local _md
     local _UUID
-    local _MD_UUID=$(getargs rd.md.uuid -d rd_MD_UUID=)
+    local _MD_UUID
+
+    _MD_UUID=$(getargs rd.md.uuid -d rd_MD_UUID=)
     [ -n "$_MD_UUID" ] || getargbool 0 rd.auto || return
 
     if [ -n "$_MD_UUID" ]; then
index cb8dd7e009ddfc4f35f3353ca3a0d1d507f7cb62..30a7c01b50e00d97bd844bfb447c459db1b58f00 100755 (executable)
@@ -2,7 +2,8 @@
 
 # called by dracut
 check() {
-    local _rootdev
+    local dev holder
+
     # No mdadm?  No mdraid support.
     require_binaries mdadm expr || return 1
 
@@ -45,9 +46,9 @@ cmdline() {
         [[ ${host_fs_types[$dev]} != *_raid_member ]] && continue
 
         UUID=$(
-            /sbin/mdadm --examine --export $dev \
-                | while read line || [ -n "$line" ]; do
-                    [[ ${line#MD_UUID=} == $line ]] && continue
+            /sbin/mdadm --examine --export "$dev" \
+                | while read -r line || [[ "$line" ]]; do
+                    [[ ${line#MD_UUID=} == "$line" ]] && continue
                     printf "%s" "${line#MD_UUID=} "
                 done
         )
@@ -67,11 +68,12 @@ install() {
     local rule rule_path
     inst_multiple cat expr
     inst_multiple -o mdmon
-    inst $(command -v partx) /sbin/partx
-    inst $(command -v mdadm) /sbin/mdadm
+    inst "$(command -v partx)" /sbin/partx
+    inst "$(command -v mdadm)" /sbin/mdadm
 
     if [[ $hostonly_cmdline == "yes" ]]; then
-        local _raidconf=$(cmdline)
+        local _raidconf
+        _raidconf=$(cmdline)
         [[ $_raidconf ]] && printf "%s\n" "$_raidconf" >> "${initdir}/etc/cmdline.d/90mdraid.conf"
     fi
 
@@ -85,6 +87,7 @@ install() {
     # assembled
     for rule in 64-md-raid.rules 64-md-raid-assembly.rules; do
         rule_path="${initdir}${udevdir}/rules.d/${rule}"
+        # shellcheck disable=SC2016
         [ -f "${rule_path}" ] && sed -i -r \
             -e '/(RUN|IMPORT\{program\})\+?="[[:alpha:]/]*mdadm[[:blank:]]+(--incremental|-I)[[:blank:]]+(--export )?(\$env\{DEVNAME\}|\$tempnode|\$devnode)/d' \
             "${rule_path}"
@@ -128,16 +131,16 @@ install() {
     inst_script "$moddir/mdraid_start.sh" /sbin/mdraid_start
     if dracut_module_included "systemd"; then
         if [[ -e $dracutsysrootdir$systemdsystemunitdir/mdmon@.service ]]; then
-            inst_simple $systemdsystemunitdir/mdmon@.service
+            inst_simple "$systemdsystemunitdir"/mdmon@.service
         fi
         if [[ -e $dracutsysrootdir$systemdsystemunitdir/mdadm-last-resort@.service ]]; then
-            inst_simple $systemdsystemunitdir/mdadm-last-resort@.service
+            inst_simple "$systemdsystemunitdir"/mdadm-last-resort@.service
         fi
         if [[ -e $dracutsysrootdir$systemdsystemunitdir/mdadm-last-resort@.timer ]]; then
-            inst_simple $systemdsystemunitdir/mdadm-last-resort@.timer
+            inst_simple "$systemdsystemunitdir"/mdadm-last-resort@.timer
         fi
         if [[ -e $dracutsysrootdir$systemdsystemunitdir/mdadm-grow-continue@.service ]]; then
-            inst_simple $systemdsystemunitdir/mdadm-grow-continue@.service
+            inst_simple "$systemdsystemunitdir"/mdadm-grow-continue@.service
         fi
     fi
     inst_hook pre-shutdown 30 "$moddir/mdmon-pre-shutdown.sh"
index 55b38f09d1a7ad0eaa9e9fb2ef13631345144a8d..3a832e7dcfa5f08fe69c89bf4f1179172f18c750 100755 (executable)
@@ -1,11 +1,13 @@
 #!/bin/sh
+# we really need to use `expr substr` with dash
+# shellcheck disable=SC2003
 
 MD_UUID=$(getargs rd.md.uuid -d rd_MD_UUID=)
 # normalize the uuid
 MD_UUID=$(str_replace "$MD_UUID" "-" "")
 MD_UUID=$(str_replace "$MD_UUID" ":" "")
 
-if (! [ -n "$MD_UUID" ] && ! getargbool 0 rd.auto) || ! getargbool 1 rd.md -d -n rd_NO_MD; then
+if ([ -z "$MD_UUID" ] && ! getargbool 0 rd.auto) || ! getargbool 1 rd.md -d -n rd_NO_MD; then
     info "rd.md=0: removing MD RAID activation"
     udevproperty rd_NO_MD=1
 else
@@ -13,14 +15,15 @@ else
     if [ -n "$MD_UUID" ]; then
         for f in /etc/udev/rules.d/65-md-incremental*.rules; do
             [ -e "$f" ] || continue
-            while read line || [ -n "$line" ]; do
+            while read -r line || [ -n "$line" ]; do
                 if [ "${line%%UUID CHECK}" != "$line" ]; then
                     for uuid in $MD_UUID; do
-                        printf 'ENV{ID_FS_UUID}=="%s", GOTO="md_uuid_ok"\n' "$(expr substr $uuid 1 8)-$(expr substr $uuid 9 4)-$(expr substr $uuid 13 4)-$(expr substr $uuid 17 4)-$(expr substr $uuid 21 12)"
+                        printf 'ENV{ID_FS_UUID}=="%s", GOTO="md_uuid_ok"\n' "$(expr substr "$uuid" 1 8)-$(expr substr "$uuid" 9 4)-$(expr substr "$uuid" 13 4)-$(expr substr "$uuid" 17 4)-$(expr substr "$uuid" 21 12)"
                     done
+                    # shellcheck disable=SC2016
                     printf 'IMPORT{program}="/sbin/mdadm --examine --export $tempnode"\n'
                     for uuid in $MD_UUID; do
-                        printf 'ENV{MD_UUID}=="%s", GOTO="md_uuid_ok"\n' "$(expr substr $uuid 1 8):$(expr substr $uuid 9 8):$(expr substr $uuid 17 8):$(expr substr $uuid 25 8)"
+                        printf 'ENV{MD_UUID}=="%s", GOTO="md_uuid_ok"\n' "$(expr substr "$uuid" 1 8):$(expr substr "$uuid" 9 8):$(expr substr "$uuid" 17 8):$(expr substr "$uuid" 25 8)"
                     done
                     printf 'GOTO="md_end"\n'
                     printf 'LABEL="md_uuid_ok"\n'
@@ -31,7 +34,7 @@ else
             mv "${f}.new" "$f"
         done
         for uuid in $MD_UUID; do
-            uuid="$(expr substr $uuid 1 8):$(expr substr $uuid 9 8):$(expr substr $uuid 17 8):$(expr substr $uuid 25 8)"
+            uuid="$(expr substr "$uuid" 1 8):$(expr substr "$uuid" 9 8):$(expr substr "$uuid" 17 8):$(expr substr "$uuid" 25 8)"
             wait_for_dev "/dev/disk/by-id/md-uuid-${uuid}"
         done
     fi
@@ -39,12 +42,12 @@ fi
 
 if [ -e /etc/mdadm.conf ] && getargbool 1 rd.md.conf -d -n rd_NO_MDADMCONF; then
     udevproperty rd_MDADMCONF=1
-    rm -f -- $hookdir/pre-pivot/*mdraid-cleanup.sh
+    rm -f -- "$hookdir"/pre-pivot/*mdraid-cleanup.sh
 fi
 
 if ! getargbool 1 rd.md.conf -d -n rd_NO_MDADMCONF; then
     rm -f -- /etc/mdadm/mdadm.conf /etc/mdadm.conf
-    ln -s $(command -v mdraid-cleanup) $hookdir/pre-pivot/31-mdraid-cleanup.sh 2> /dev/null
+    ln -s "$(command -v mdraid-cleanup)" "$hookdir"/pre-pivot/31-mdraid-cleanup.sh 2> /dev/null
 fi
 
 # noiswmd nodmraid for anaconda / rc.sysinit compatibility