#!/bin/bash

# we only remove specific file extensions generated during the run. We do not remove the dir itself or other file types to prevent potential severe damages if the paths are set incorrectly.
function cleanup {
    if [ "$ENABLE_CLEANUP" = "true" ]; then
        echo
        echo "Cleaning up..."
        if ! "$OP_RM" -rf "$CERT_GEN_DIR/$CERT_GEN_EXTENSIONS"; then
            echo "Error removing ${CERT_GEN_EXTENSIONS[*]} from $CERT_GEN_DIR from this machine. Check permissions and/or remove manually."
            exit 1
        fi
        echo "Done Cleaning up the intermediate provisioning artifacts. If exited abnormally (e.g. using CTRL+C), you still need to manually clean-up TPM state or certificate storage dir $CERT_STORE_DIR."
    else
        echo "Not cleaning up the intermediate provisioning artifacts. Do it manually."
        exit 1
    fi
}

