25 lines
No EOL
825 B
Bash
25 lines
No EOL
825 B
Bash
#!/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" ] && [ "$jwe" != "-" ]; 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 |