xref: /openbmc/openpower-debug-collector/dump/tools/common/include/gendumpinfo (revision ed53dc7daa1d1fc866c17c5abbb8ec1bddc33bae)
19eb4e482SDhruvaraj Subhashchandran#!/bin/bash
29eb4e482SDhruvaraj Subhashchandran# shellcheck disable=SC2154
39eb4e482SDhruvaraj Subhashchandran
49eb4e482SDhruvaraj Subhashchandran# Constants
59eb4e482SDhruvaraj Subhashchandrandeclare -rx DUMP_MANAGER='xyz.openbmc_project.Dump.Manager'
69eb4e482SDhruvaraj Subhashchandrandeclare -rx DUMP_PATH='/xyz/openbmc_project/dump/opdump/entry'
79eb4e482SDhruvaraj Subhashchandrandeclare -rx DUMP_PROP='xyz.openbmc_project.Common.Progress'
89eb4e482SDhruvaraj Subhashchandran
99eb4e482SDhruvaraj Subhashchandran# Variables
109eb4e482SDhruvaraj Subhashchandrandeclare -x DRIVER=""
119eb4e482SDhruvaraj Subhashchandrandeclare -x YAML_FILE=""
129eb4e482SDhruvaraj Subhashchandrandeclare -x ADDL_DATA_PATH=""
139eb4e482SDhruvaraj Subhashchandrandeclare -x START_TIME=0
149eb4e482SDhruvaraj Subhashchandrandeclare -x END_TIME=0
159eb4e482SDhruvaraj Subhashchandran
169eb4e482SDhruvaraj Subhashchandran# Initialize variables
179eb4e482SDhruvaraj Subhashchandranfunction initialize_variables() {
189eb4e482SDhruvaraj Subhashchandran    DRIVER=$(awk -F '[=()]' '/VERSION_ID/ {print $2}' /etc/os-release)
199eb4e482SDhruvaraj Subhashchandran    YAML_FILE="$content_path/info.yaml"
209eb4e482SDhruvaraj Subhashchandran    ADDL_DATA_PATH="$content_path/plat_dump/additional_data/"
219eb4e482SDhruvaraj Subhashchandran}
229eb4e482SDhruvaraj Subhashchandran
239eb4e482SDhruvaraj Subhashchandran# Function to get the dump start and completed time
249eb4e482SDhruvaraj Subhashchandranfunction dump_time_details() {
259eb4e482SDhruvaraj Subhashchandran    START_TIME=$(busctl get-property "$DUMP_MANAGER" "$DUMP_PATH/$dump_id" \
269eb4e482SDhruvaraj Subhashchandran        "$DUMP_PROP" StartTime | awk '{print $2}')
279eb4e482SDhruvaraj Subhashchandran    END_TIME=$(busctl get-property "$DUMP_MANAGER" "$DUMP_PATH/$dump_id" \
289eb4e482SDhruvaraj Subhashchandran        "$DUMP_PROP" CompletedTime | awk '{print $2}')
299eb4e482SDhruvaraj Subhashchandran
309eb4e482SDhruvaraj Subhashchandran    if [ -z "$START_TIME" ] || [ "$START_TIME" -eq 0 ]; then
319eb4e482SDhruvaraj Subhashchandran        echo "Could not fetch start time for $dump_id. Setting manually"
329eb4e482SDhruvaraj Subhashchandran        START_TIME=$(date +%s)
339eb4e482SDhruvaraj Subhashchandran    fi
349eb4e482SDhruvaraj Subhashchandran
359eb4e482SDhruvaraj Subhashchandran    start=$(date -d @"$START_TIME" +'%Y-%m-%d %H:%M:%S')
369eb4e482SDhruvaraj Subhashchandran    if [ -z "$END_TIME" ] || [ "$END_TIME" -eq 0 ]; then
379eb4e482SDhruvaraj Subhashchandran        echo "Could not fetch end time for $dump_id. Setting manually"
389eb4e482SDhruvaraj Subhashchandran        END_TIME=$(date +%s)
399eb4e482SDhruvaraj Subhashchandran    fi
409eb4e482SDhruvaraj Subhashchandran    end=$(date -d @"$END_TIME" +'%Y-%m-%d %H:%M:%S')
419eb4e482SDhruvaraj Subhashchandran
429eb4e482SDhruvaraj Subhashchandran    printf "dump-start-time: %s\n" "$start" >> "$YAML_FILE"
439eb4e482SDhruvaraj Subhashchandran    printf "dump-end-time: %s\n" "$end" >> "$YAML_FILE"
449eb4e482SDhruvaraj Subhashchandran}
459eb4e482SDhruvaraj Subhashchandran
469eb4e482SDhruvaraj Subhashchandran# Function to fetch additional details
479eb4e482SDhruvaraj Subhashchandranfunction get_addl_data() {
489eb4e482SDhruvaraj Subhashchandran    if [ -d "$ADDL_DATA_PATH" ]; then
499eb4e482SDhruvaraj Subhashchandran        for entry in "$ADDL_DATA_PATH"/*; do
509eb4e482SDhruvaraj Subhashchandran            while IFS= read -r line; do
519eb4e482SDhruvaraj Subhashchandran                echo "$line" >> "$YAML_FILE"
529eb4e482SDhruvaraj Subhashchandran            done < "$entry"
539eb4e482SDhruvaraj Subhashchandran        done
549eb4e482SDhruvaraj Subhashchandran    fi
559eb4e482SDhruvaraj Subhashchandran}
569eb4e482SDhruvaraj Subhashchandran
579eb4e482SDhruvaraj Subhashchandran# Function to write data to info.yaml file
589eb4e482SDhruvaraj Subhashchandranfunction write_to_info_file() {
599eb4e482SDhruvaraj Subhashchandran    {
609eb4e482SDhruvaraj Subhashchandran        printf "%s\n" "# SPDX-License-Identifier: GPL-2.0"
619eb4e482SDhruvaraj Subhashchandran        printf "%s\n" "%YAML 1.2"
629eb4e482SDhruvaraj Subhashchandran        printf "%s\n\n" "---"
639eb4e482SDhruvaraj Subhashchandran        printf "generation: p10\n"
649eb4e482SDhruvaraj Subhashchandran        printf "driver: %s\n" "$DRIVER"
659eb4e482SDhruvaraj Subhashchandran    } >> "$YAML_FILE"
669eb4e482SDhruvaraj Subhashchandran    dump_time_details
679eb4e482SDhruvaraj Subhashchandran    get_addl_data
68*ed53dc7dSSwethaParasa    cat "$content_path/errorInfo" >> "$YAML_FILE"
699eb4e482SDhruvaraj Subhashchandran}
709eb4e482SDhruvaraj Subhashchandran
719eb4e482SDhruvaraj Subhashchandran# Run main
729eb4e482SDhruvaraj Subhashchandraninitialize_variables
739eb4e482SDhruvaraj Subhashchandranwrite_to_info_file
749eb4e482SDhruvaraj Subhashchandran
75