tpm2_ptool shell script to create primary if it doesn't exist yet

The following shell script checks if a primary object exists in the TPM. If it does not, it initializes the TPM using tpm2_ptool init. If a primary already exists, it simply outputs a message indicating that.

It doesn’t matter if one or more primaries exist; the script will only initialize if none are found.

if [ -z "$(tpm2_ptool listprimaries)" ]; then
    tpm2_ptool init
else
    echo "Primary already exists"
fi