Add initramfs compliant zlevis-fetch.

This commit is contained in:
Luc Bijl 2024-11-17 19:13:04 +01:00
parent 5bb178349f
commit 2b5f370781

25
src/zlevis-fetch Normal file
View file

@ -0,0 +1,25 @@
#!/bin/sh
# Exit immediately if a command exits with a non-zero status
set -e
# Check if zlevis-decrypt is present
command -v zlevis-decrypt > /dev/null || exit 1
# Read ZFS dataset information.
zfs list -Ho name,encryption,keystatus,encryptionroot,tpm:jwe | while IFS=$'\t' read -r ds enc keystatus encroot jwe; do
# Check if the dataset is the encryption root.
if [ "$ds" = "$encroot" ] && [ "$enc" != "off" ] && [ "$key" != "-" ]; then
if [ "$keystatus" = "available" ]; then
echo "Pool $ds already unlocked"
else
echo "Loading key for $ds"
if echo -n "$jwe" | zlevis-decrypt | zfs load-key -L prompt "$ds"; then
echo "Unlocked $ds"
else
echo "FAILED TO UNLOCK $ds" >&2
exit 1
fi
fi
fi
done