#!/bin/bash
BASE_COLLECTION_PATH="must-gather"
mkdir -p ${BASE_COLLECTION_PATH}

# Command line argument
SINCE_TIME=$1

# timestamp for starting of the script
START_TIME=$(date +%r)
start=$(date +%s)
printf "collection started at: %s \n" "${START_TIME}" >> ${BASE_COLLECTION_PATH}/gather-debug.log 2>&1


# Call other gather scripts
gather_namespaced_resources ${BASE_COLLECTION_PATH} "${SINCE_TIME}"
gather_clusterscoped_resources ${BASE_COLLECTION_PATH} "${SINCE_TIME}"


# timestamp for ending of the script
END_TIME=$(date +%r)
end=$(date +%s)
totalTime=$((end-start))
{
    printf "total time taken by collection was %s seconds \n" ${totalTime}
    printf "collection ended at: %s \n" "${END_TIME}"
    echo "deleting empty files"

} >> ${BASE_COLLECTION_PATH}/gather-debug.log 2>&1
find "${BASE_COLLECTION_PATH}" -empty -delete >> ${BASE_COLLECTION_PATH}/gather-debug.log 2>&1
exit 0
