[arch-projects] [RFC] Remove cut, grep and sed from mdadm initcpio hook

Gerardo Exequiel Pozzi vmlinuz386 at yahoo.com.ar
Wed Nov 16 01:34:30 EST 2011


https://gist.github.com/1369428 (this patch)
https://gist.github.com/1369424 (standalone test script)

--- /lib/initcpio/hooks/mdadm    2011-09-14 04:10:48.000000000 -0300
+++ hooks/mdadm    2011-11-16 03:32:30.064535002 -0300
@@ -6,7 +6,7 @@
      # for partitionable raid, we need to load md_mod first!
      modprobe md_mod 2>/dev/null
      # If md is specified on commandline, create config file from those 
parameters.
-    if [ "$(echo $input | grep "md=")" ]; then
+    if [ -n "${md}" ]; then
          #Create initial mdadm.conf
          # scan all devices in /proc/partitions
          echo DEVICE partitions > $mdconfig
@@ -14,26 +14,30 @@
              case $i in
                  # raid
                  md=[0-9]*,/*)
-                    device="$(echo "$i" | sed -e 's|,/.*||g' -e 's|=||g')"
-                    array="$(echo $i | cut -d, -f2-)"
+                    device="${i%%,*}"
+                    device="${device/=/}"
+                    array="${i#*,}"
                      echo "ARRAY /dev/$device devices=$array" >> $mdconfig
                      ;;
                  # partitionable raid
                  md=d[0-9]*,/*)
-                    device="$(echo "$i" | sed -e 's|,/.*||g' -e 's|=|_|g')"
-                    array="$(echo $i | cut -d, -f2-)"
+                    device="${i%%,*}"
+                    device="${device/=/_}"
+                    array="${i#*,}"
                      echo "ARRAY /dev/$device devices=$array" >> $mdconfig
                      ;;
                  # raid UUID
-                md=[0-9]*,[0-9,a-z]*)
-                    device="$(echo "$i" | sed -e 's|,.*||g' -e 's|=||g')"
-                    array="$(echo $i | cut -d, -f2-)"
+                md=[0-9]*,[0-9,a-f]*)
+                    device="${i%%,*}"
+                    device="${device/=/}"
+                    array="${i#*,}"
                      echo "ARRAY /dev/$device UUID=$array" >> $mdconfig
                      ;;
                  # partitionable raid UUID
-                md=d[0-9]*,[0-9,a-z]*)
-                    device="$(echo "$i" | sed -e 's|,.*||g' -e 's|=|_|g')"
-                    array="$(echo $i | cut -d, -f2-)"
+                md=d[0-9]*,[0-9,a-f]*)
+                    device="${i%%,*}"
+                    device="${device/=/_}"
+                    array="${i#*,}"
                      echo "ARRAY /dev/$device UUID=$array" >> $mdconfig
                      ;;
              esac


-- 
Gerardo Exequiel Pozzi
\cos^2\alpha + \sin^2\alpha = 1



More information about the arch-projects mailing list