diff --git a/src/zlevis b/src/zlevis new file mode 100644 index 0000000..fc9b701 --- /dev/null +++ b/src/zlevis @@ -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 $? \ No newline at end of file