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 <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #11198
This commit is contained in:
parent
85703f616d
commit
2d9f82d891
|
@ -17,10 +17,8 @@
|
||||||
[ "${root##zfs:}" = "${root}" ] && [ "${root##ZFS=}" = "${root}" ] && [ "$rootfstype" != "zfs" ] && exit 0
|
[ "${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
|
# 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
|
while [ "$(zpool list -H)" = "" ]; do
|
||||||
zpool list -H | grep -q -v '^$' && break
|
systemctl is-failed --quiet zfs-import-cache.service zfs-import-scan.service && exit 1
|
||||||
[ "$(systemctl is-failed zfs-import-cache.service)" = 'failed' ] && exit 1
|
|
||||||
[ "$(systemctl is-failed zfs-import-scan.service)" = 'failed' ] && exit 1
|
|
||||||
sleep 0.1s
|
sleep 0.1s
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -34,11 +32,11 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if pool encryption is active and the zfs command understands '-o encryption'
|
# 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
|
# 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)
|
# 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
|
if ! [ "${ENCRYPTIONROOT}" = "-" ]; then
|
||||||
KEYSTATUS="$(zfs get -H -o value keystatus "${ENCRYPTIONROOT}")"
|
KEYSTATUS="$(zfs get -H -o value keystatus "${ENCRYPTIONROOT}")"
|
||||||
# continue only if the key needs to be loaded
|
# continue only if the key needs to be loaded
|
||||||
|
|
Loading…
Reference in New Issue