#!/bin/bash
file="/etc/crypttab"
by_uuid_path="/dev/disk/by-uuid"
cat "$file"| while read line
do
  if echo "$line" | grep -q "UUID="; then
	  disk=`echo "$line" | awk -F' ' '{gsub(/^UUID=/, "", $2); print $2}'`
    gpt=`ls -al "$by_uuid_path"|grep "$disk"|awk -F' ' '{gsub(/^..\/..\//,"",$(NF));printf $(NF)}'`
    diskgpt=`echo "/dev/""$gpt"`
	  sudo cryptsetup luksChangeKey $diskgpt --key-tpm
  fi
done
sudo tpm2_nvundefine 0x01bf0025

