src/zlevis: updated info call

This commit is contained in:
Luc Bijl 2025-02-14 23:15:36 +01:00
parent 6f2a105188
commit d42a13b560

View file

@ -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 $?