#!/bin/bash # shellcheck disable=SC2154 # Constants declare -rx DUMP_MANAGER='xyz.openbmc_project.Dump.Manager' declare -rx DUMP_PATH='/xyz/openbmc_project/dump/opdump/entry' declare -rx DUMP_PROP='xyz.openbmc_project.Common.Progress' # Variables declare -x DRIVER="" declare -x YAML_FILE="" declare -x ADDL_DATA_PATH="" declare -x START_TIME=0 declare -x END_TIME=0 # Initialize variables function initialize_variables() { DRIVER=$(awk -F '[=()]' '/VERSION_ID/ {print $2}' /etc/os-release) YAML_FILE="$content_path/info.yaml" ADDL_DATA_PATH="$content_path/plat_dump/additional_data/" } # Function to get the dump start and completed time function dump_time_details() { START_TIME=$(busctl get-property "$DUMP_MANAGER" "$DUMP_PATH/$dump_id" \ "$DUMP_PROP" StartTime | awk '{print $2}') END_TIME=$(busctl get-property "$DUMP_MANAGER" "$DUMP_PATH/$dump_id" \ "$DUMP_PROP" CompletedTime | awk '{print $2}') if [ -z "$START_TIME" ] || [ "$START_TIME" -eq 0 ]; then echo "Could not fetch start time for $dump_id. Setting manually" START_TIME=$(date +%s) fi start=$(date -d @"$START_TIME" +'%Y-%m-%d %H:%M:%S') if [ -z "$END_TIME" ] || [ "$END_TIME" -eq 0 ]; then echo "Could not fetch end time for $dump_id. Setting manually" END_TIME=$(date +%s) fi end=$(date -d @"$END_TIME" +'%Y-%m-%d %H:%M:%S') printf "dump-start-time: %s\n" "$start" >> "$YAML_FILE" printf "dump-end-time: %s\n" "$end" >> "$YAML_FILE" } # Function to fetch additional details function get_addl_data() { if [ -d "$ADDL_DATA_PATH" ]; then for entry in "$ADDL_DATA_PATH"/*; do while IFS= read -r line; do echo "$line" >> "$YAML_FILE" done < "$entry" done fi } # Function to write data to info.yaml file function write_to_info_file() { { printf "%s\n" "# SPDX-License-Identifier: GPL-2.0" printf "%s\n" "%YAML 1.2" printf "%s\n\n" "---" printf "generation: p10\n" printf "driver: %s\n" "$DRIVER" } >> "$YAML_FILE" dump_time_details get_addl_data } # Run main initialize_variables write_to_info_file