From d42a13b5601905e9a961de03196b6bb7148b22f4 Mon Sep 17 00:00:00 2001 From: Luc Date: Fri, 14 Feb 2025 23:15:36 +0100 Subject: [PATCH] src/zlevis: updated info call --- src/zlevis | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/zlevis b/src/zlevis index 06c9f2a..a81feed 100755 --- a/src/zlevis +++ b/src/zlevis @@ -12,30 +12,31 @@ if [ "$1" = "--summary" ]; then exit 0 fi +# Function to display usage information when called +info() { + exec >&2 + echo "Usage: \"zlevis {decrypt|encrypt} {pool|key} [options]\"" + exit 2 +} + +# Case statement to handle the argument path case "$1" in "decrypt") case "$2" in "pool") zfs list -Ho tpm:jwe "$3" | zlevis-decrypt;; "key") zlevis-decrypt;; - *) exit 1;; + *) info;; esac ;; "encrypt") case "$2" in - "pool") read -r -d . key || zfs set tpm:jwe=$(printf "%s" "$key" | zlevis-encrypt "$4") "$3";; + "pool") read -r -d . key && zfs set tpm:jwe=$(printf "%s" "$key" | zlevis-encrypt "$4") "$3";; "key") zlevis-encrypt "$3";; - *) exit 1;; + *) info;; esac ;; - *) exit 1;; + *) info;; esac -# Display usage information if input is from a terminal -if [ -t 0 ]; then - exec >&2 - echo "Usage: \"zlevis {decrypt|encrypt} {pool|key} [options]\"" - exit 2 -fi - # Exit with the status of the last command exit $? \ No newline at end of file