src/zlevis: add main binary w.r.t. issue #2
This commit is contained in:
parent
3344160e52
commit
788a251e6b
1 changed files with 39 additions and 0 deletions
39
src/zlevis
Normal file
39
src/zlevis
Normal file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
|
||||
# Summary of the script's functionality
|
||||
summary="A tool that enables automatic decryption of ZFS rpools with TPM2"
|
||||
|
||||
# Display summary if requested
|
||||
if [ "$1" = "--summary" ]; then
|
||||
echo "$summary"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Display usage information if input is from a terminal
|
||||
if [ -t 0 ]; then
|
||||
exec >&2
|
||||
echo "Usage: zlevis {decrypt|encrypt} {pool|*} [options]"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
decrypt)
|
||||
case "$2" in
|
||||
pool) zfs list -Ho tpm:jwe $3 | zlevis-decrypt;;
|
||||
*) zlevis-decrypt $2;;
|
||||
esac
|
||||
;;
|
||||
encrypt)
|
||||
case "$2" in
|
||||
pool) read -r -d . key || zfs set tpm:jwe=$(printf "%s" "$key" | zlevis-encrypt $4) $3;;
|
||||
*) zlevis-encrypt $2;;
|
||||
esac
|
||||
;;
|
||||
*) exit 1;;
|
||||
esac
|
||||
|
||||
# Exit with the status of the last command
|
||||
exit $?
|
Loading…
Reference in a new issue