summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorнаб <[email protected]>2020-11-12 23:06:24 +0100
committerBrian Behlendorf <[email protected]>2020-11-19 16:20:42 -0800
commit2d9f82d89118240d19a6857c84b45f4481a5543b (patch)
tree50609c0c9f843542bab87b8ea3994c024b649269
parent85703f616ddb83bb94192e24fd8519661578aac2 (diff)
dracut/zfs-load-key.sh: simplify import loop, quote variable assignments
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 <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11198
-rwxr-xr-xcontrib/dracut/90zfs/zfs-load-key.sh.in12
1 files 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 ff586ef65..49d56e546 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