[arch-projects] [RFC] Remove cut, grep and sed from mdadm initcpio hook
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
On 11/16/2011 03:34 AM, Gerardo Exequiel Pozzi wrote:
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
I guess that this code can be simplified a bit, does not make sense today differentiate between non-partitioned and partitioned md devs. From mdadm(8) manpage: "From kernel version, 2.6.28 the "non-partitioned array" can actually be partitioned. So the "md_dNN" names are no longer needed, and partitions such as "/dev/mdNNpXX" are possible." Maybe we can add some note if user wants the legacy name. -- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
participants (1)
-
Gerardo Exequiel Pozzi