1*9eb4e482SDhruvaraj Subhashchandran#!/bin/bash
2*9eb4e482SDhruvaraj Subhashchandran# shellcheck disable=SC2154
3*9eb4e482SDhruvaraj Subhashchandran
4*9eb4e482SDhruvaraj Subhashchandran# Constants
5*9eb4e482SDhruvaraj Subhashchandrandeclare -rx DUMP_MANAGER='xyz.openbmc_project.Dump.Manager'
6*9eb4e482SDhruvaraj Subhashchandrandeclare -rx DUMP_PATH='/xyz/openbmc_project/dump/opdump/entry'
7*9eb4e482SDhruvaraj Subhashchandrandeclare -rx DUMP_PROP='xyz.openbmc_project.Common.Progress'
8*9eb4e482SDhruvaraj Subhashchandran
9*9eb4e482SDhruvaraj Subhashchandran# Variables
10*9eb4e482SDhruvaraj Subhashchandrandeclare -x DRIVER=""
11*9eb4e482SDhruvaraj Subhashchandrandeclare -x YAML_FILE=""
12*9eb4e482SDhruvaraj Subhashchandrandeclare -x ADDL_DATA_PATH=""
13*9eb4e482SDhruvaraj Subhashchandrandeclare -x START_TIME=0
14*9eb4e482SDhruvaraj Subhashchandrandeclare -x END_TIME=0
15*9eb4e482SDhruvaraj Subhashchandran
16*9eb4e482SDhruvaraj Subhashchandran# Initialize variables
17*9eb4e482SDhruvaraj Subhashchandranfunction initialize_variables() {
18*9eb4e482SDhruvaraj Subhashchandran    DRIVER=$(awk -F '[=()]' '/VERSION_ID/ {print $2}' /etc/os-release)
19*9eb4e482SDhruvaraj Subhashchandran    YAML_FILE="$content_path/info.yaml"
20*9eb4e482SDhruvaraj Subhashchandran    ADDL_DATA_PATH="$content_path/plat_dump/additional_data/"
21*9eb4e482SDhruvaraj Subhashchandran}
22*9eb4e482SDhruvaraj Subhashchandran
23*9eb4e482SDhruvaraj Subhashchandran# Function to get the dump start and completed time
24*9eb4e482SDhruvaraj Subhashchandranfunction dump_time_details() {
25*9eb4e482SDhruvaraj Subhashchandran    START_TIME=$(busctl get-property "$DUMP_MANAGER" "$DUMP_PATH/$dump_id" \
26*9eb4e482SDhruvaraj Subhashchandran        "$DUMP_PROP" StartTime | awk '{print $2}')
27*9eb4e482SDhruvaraj Subhashchandran    END_TIME=$(busctl get-property "$DUMP_MANAGER" "$DUMP_PATH/$dump_id" \
28*9eb4e482SDhruvaraj Subhashchandran        "$DUMP_PROP" CompletedTime | awk '{print $2}')
29*9eb4e482SDhruvaraj Subhashchandran
30*9eb4e482SDhruvaraj Subhashchandran    if [ -z "$START_TIME" ] || [ "$START_TIME" -eq 0 ]; then
31*9eb4e482SDhruvaraj Subhashchandran        echo "Could not fetch start time for $dump_id. Setting manually"
32*9eb4e482SDhruvaraj Subhashchandran        START_TIME=$(date +%s)
33*9eb4e482SDhruvaraj Subhashchandran    fi
34*9eb4e482SDhruvaraj Subhashchandran
35*9eb4e482SDhruvaraj Subhashchandran    start=$(date -d @"$START_TIME" +'%Y-%m-%d %H:%M:%S')
36*9eb4e482SDhruvaraj Subhashchandran    if [ -z "$END_TIME" ] || [ "$END_TIME" -eq 0 ]; then
37*9eb4e482SDhruvaraj Subhashchandran        echo "Could not fetch end time for $dump_id. Setting manually"
38*9eb4e482SDhruvaraj Subhashchandran        END_TIME=$(date +%s)
39*9eb4e482SDhruvaraj Subhashchandran    fi
40*9eb4e482SDhruvaraj Subhashchandran    end=$(date -d @"$END_TIME" +'%Y-%m-%d %H:%M:%S')
41*9eb4e482SDhruvaraj Subhashchandran
42*9eb4e482SDhruvaraj Subhashchandran    printf "dump-start-time: %s\n" "$start" >> "$YAML_FILE"
43*9eb4e482SDhruvaraj Subhashchandran    printf "dump-end-time: %s\n" "$end" >> "$YAML_FILE"
44*9eb4e482SDhruvaraj Subhashchandran}
45*9eb4e482SDhruvaraj Subhashchandran
46*9eb4e482SDhruvaraj Subhashchandran# Function to fetch additional details
47*9eb4e482SDhruvaraj Subhashchandranfunction get_addl_data() {
48*9eb4e482SDhruvaraj Subhashchandran    if [ -d "$ADDL_DATA_PATH" ]; then
49*9eb4e482SDhruvaraj Subhashchandran        for entry in "$ADDL_DATA_PATH"/*; do
50*9eb4e482SDhruvaraj Subhashchandran            while IFS= read -r line; do
51*9eb4e482SDhruvaraj Subhashchandran                echo "$line" >> "$YAML_FILE"
52*9eb4e482SDhruvaraj Subhashchandran            done < "$entry"
53*9eb4e482SDhruvaraj Subhashchandran        done
54*9eb4e482SDhruvaraj Subhashchandran    fi
55*9eb4e482SDhruvaraj Subhashchandran}
56*9eb4e482SDhruvaraj Subhashchandran
57*9eb4e482SDhruvaraj Subhashchandran# Function to write data to info.yaml file
58*9eb4e482SDhruvaraj Subhashchandranfunction write_to_info_file() {
59*9eb4e482SDhruvaraj Subhashchandran    {
60*9eb4e482SDhruvaraj Subhashchandran        printf "%s\n" "# SPDX-License-Identifier: GPL-2.0"
61*9eb4e482SDhruvaraj Subhashchandran        printf "%s\n" "%YAML 1.2"
62*9eb4e482SDhruvaraj Subhashchandran        printf "%s\n\n" "---"
63*9eb4e482SDhruvaraj Subhashchandran        printf "generation: p10\n"
64*9eb4e482SDhruvaraj Subhashchandran        printf "driver: %s\n" "$DRIVER"
65*9eb4e482SDhruvaraj Subhashchandran    } >> "$YAML_FILE"
66*9eb4e482SDhruvaraj Subhashchandran    dump_time_details
67*9eb4e482SDhruvaraj Subhashchandran    get_addl_data
68*9eb4e482SDhruvaraj Subhashchandran}
69*9eb4e482SDhruvaraj Subhashchandran
70*9eb4e482SDhruvaraj Subhashchandran# Run main
71*9eb4e482SDhruvaraj Subhashchandraninitialize_variables
72*9eb4e482SDhruvaraj Subhashchandranwrite_to_info_file
73*9eb4e482SDhruvaraj Subhashchandran
74