[arch-projects] [RFC] Remove sed and cut from encrypt initcpio hook

Gerardo Exequiel Pozzi vmlinuz386 at yahoo.com.ar
Wed Nov 16 08:53:40 EST 2011


https://gist.github.com/1370102 (this patch)

There is no <<< in ash for doing "read a b c <<< $var" like in bash :(

--- /lib/initcpio/hooks/encrypt    2011-11-03 15:40:08.000000000 -0300
+++ hooks/encrypt    2011-11-16 10:41:44.724256727 -0300
@@ -6,17 +6,19 @@
      /sbin/modprobe -a -q dm-crypt >/dev/null 2>&1
      if [ -e "/sys/class/misc/device-mapper" ]; then
          if [ ! -e "/dev/mapper/control" ]; then
+            local major minor
+            IFS=: read major minor < /sys/class/misc/device-mapper/dev
              mkdir /dev/mapper
-            mknod "/dev/mapper/control" c $(cat 
/sys/class/misc/device-mapper/dev | sed 's|:| |')
+            mknod /dev/mapper/control c ${major} ${minor}
          fi
          [ "${quiet}" = "y" ] && CSQUIET=">/dev/null"

          # Get keyfile if specified
          ckeyfile="/crypto_keyfile.bin"
-        if [ "x${cryptkey}" != "x" ]; then
-            ckdev="$(echo "${cryptkey}" | cut -d: -f1)"
-            ckarg1="$(echo "${cryptkey}" | cut -d: -f2)"
-            ckarg2="$(echo "${cryptkey}" | cut -d: -f3)"
+        if [ -n "${cryptkey}" ]; then
+            IFS=: read ckdev ckarg1 ckarg2 << EOF
+${cryptkey}
+EOF
              if poll_device "${ckdev}" ${rootdelay}; then
                  case ${ckarg1} in
                      *[!0-9]*)
@@ -39,9 +41,9 @@

          if [ -n "${cryptdevice}" ]; then
              DEPRECATED_CRYPT=0
-            cryptdev="$(echo "${cryptdevice}" | cut -d: -f1)"
-            cryptname="$(echo "${cryptdevice}" | cut -d: -f2)"
-            cryptoptions="$(echo "${cryptdevice}" | cut -d: -f3)"
+            IFS=: read cryptdev cryptname cryptoptions << EOF
+${cryptdevice}
+EOF
          else
              DEPRECATED_CRYPT=1
              cryptdev="${root}"
@@ -107,16 +109,14 @@
                      return 1
                  fi
                  exe="/sbin/cryptsetup create ${cryptname} ${cryptdev} 
${cryptargs}"
-                tmp=$(echo "${crypto}" | cut -d: -f1)
-                [ -n "${tmp}" ] && exe="${exe} --hash \"${tmp}\""
-                tmp=$(echo "${crypto}" | cut -d: -f2)
-                [ -n "${tmp}" ] && exe="${exe} --cipher \"${tmp}\""
-                tmp=$(echo "${crypto}" | cut -d: -f3)
-                [ -n "${tmp}" ] && exe="${exe} --key-size \"${tmp}\""
-                tmp=$(echo "${crypto}" | cut -d: -f4)
-                [ -n "${tmp}" ] && exe="${exe} --offset \"${tmp}\""
-                tmp=$(echo "${crypto}" | cut -d: -f5)
-                [ -n "${tmp}" ] && exe="${exe} --skip \"${tmp}\""
+                IFS=: read c_hash c_cipher c_keysize c_offset c_skip << EOF
+${crypto}
+EOF
+                [ -n "${c_hash}" ] && exe="${exe} --hash '${c_hash}'"
+                [ -n "${c_cipher}" ] && exe="${exe} --cipher '${c_cipher}'"
+                [ -n "${c_keysize}" ] && exe="${exe} --key-size 
'${c_keysize}'"
+                [ -n "${c_offset}" ] && exe="${exe} --offset '${c_offset}'"
+                [ -n "${c_skip}" ] && exe="${exe} --skip '${c_skip}'"
                  if [ -f ${ckeyfile} ]; then
                      exe="${exe} --key-file ${ckeyfile}"
                  else

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



More information about the arch-projects mailing list