#!/bin/bash

#install needed packages
apt -y install clevis clevis-tpm2 clevis-luks clevis-initramfs initramfs-tools

#proceed
echo -n Enter LUKS password:
read -s LUKSKEY
echo ""

echo -n "Enter LUKS device (ex: /dev/sda3): "
read LUKSDEVICE
echo ""

# Get UUID for device
LUKSUUID=$(blkid -s UUID -o value $LUKSDEVICE)

echo Adding $LUKSDEVICE to tpm for auto unlock.

clevis luks bind -d UUID=$LUKSUUID tpm2 '{"pcr_bank":"sha256"}' <<< "$LUKSKEY"

update-initramfs -u -k all

#check
clevis luks list -d UUID=$LUKSUUID

#delete example; -s is one of the slots reported by the previous command
#clevis luks unbind -d /dev/nvme0n1p3 -s 1 tpm2
