From 2d9f82d89118240d19a6857c84b45f4481a5543b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 12 Nov 2020 23:06:24 +0100 Subject: [PATCH] dracut/zfs-load-key.sh: simplify import loop, quote variable assignments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The loop now has a less confusing condition and properly uses systemctl(1) is-failed's return code instead of that entire mess The assignments could turn into "var=val program" if encryptionroot or keylocation had whitespace in them As a bonus, this (mostly) silences shellcheck Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #11198 --- contrib/dracut/90zfs/zfs-load-key.sh.in | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/contrib/dracut/90zfs/zfs-load-key.sh.in b/contrib/dracut/90zfs/zfs-load-key.sh.in index ff586ef654..49d56e546c 100755 --- a/contrib/dracut/90zfs/zfs-load-key.sh.in +++ b/contrib/dracut/90zfs/zfs-load-key.sh.in @@ -17,10 +17,8 @@ [ "${root##zfs:}" = "${root}" ] && [ "${root##ZFS=}" = "${root}" ] && [ "$rootfstype" != "zfs" ] && exit 0 # There is a race between the zpool import and the pre-mount hooks, so we wait for a pool to be imported -while true; do - zpool list -H | grep -q -v '^$' && break - [ "$(systemctl is-failed zfs-import-cache.service)" = 'failed' ] && exit 1 - [ "$(systemctl is-failed zfs-import-scan.service)" = 'failed' ] && exit 1 +while [ "$(zpool list -H)" = "" ]; do + systemctl is-failed --quiet zfs-import-cache.service zfs-import-scan.service && exit 1 sleep 0.1s done @@ -34,11 +32,11 @@ else fi # if pool encryption is active and the zfs command understands '-o encryption' -if [ "$(zpool list -H -o feature@encryption $(echo "${BOOTFS}" | awk -F\/ '{print $1}'))" = 'active' ]; then +if [ "$(zpool list -H -o feature@encryption "$(echo "${BOOTFS}" | awk -F/ '{print $1}')")" = 'active' ]; then # if the root dataset has encryption enabled - ENCRYPTIONROOT=$(zfs get -H -o value encryptionroot "${BOOTFS}") + ENCRYPTIONROOT="$(zfs get -H -o value encryptionroot "${BOOTFS}")" # where the key is stored (in a file or loaded via prompt) - KEYLOCATION=$(zfs get -H -o value keylocation "${ENCRYPTIONROOT}") + KEYLOCATION="$(zfs get -H -o value keylocation "${ENCRYPTIONROOT}")" if ! [ "${ENCRYPTIONROOT}" = "-" ]; then KEYSTATUS="$(zfs get -H -o value keystatus "${ENCRYPTIONROOT}")" # continue only if the key needs to be loaded