1#!/bin/bash 2# 3# config: 2 50 4# @brief: Collect redundant OS information. 5 6# shellcheck disable=SC1091 7. "$DREPORT_INCLUDE/functions" 8 9desc="Redundant firmware info" 10file_name="redundant-os-release" 11 12# Declare necessary dbus interfaces 13dbus_object="xyz.openbmc_project.Software.BMC.Updater" 14dbus_tree_command="busctl tree" 15dbus_property_command="busctl get-property" 16dbus_object_priority_method="xyz.openbmc_project.Software.RedundancyPriority" 17dbus_object_priority="Priority" 18dbus_object_version_method="xyz.openbmc_project.Software.Version" 19dbus_object_version="Version" 20 21# Declare an array to store the results of dbus command 22read_array=() 23 24IFS=$'\n' read -r -d '' -a read_array < <( eval "$dbus_tree_command" "$dbus_object" && printf '\0' ) 25 26array_length=${#read_array[@]} 27 28# If there is only one FW image on the BMC, return then and there 29if [ "$array_length" -lt 5 ]; then 30 return "$SUCCESS" 31fi 32 33firmware1=$(echo "${read_array[3]}" | xargs) 34firmware2=$(echo "${read_array[4]}" | xargs) 35 36if [ -n "$firmware1" ]; then 37 firmware1=${firmware1:3} 38fi 39 40if [ -n "$firmware2" ]; then 41 firmware2=${firmware2:3} 42fi 43 44redundant_firmware="" 45dbus_command="$dbus_property_command $dbus_object $firmware1 $dbus_object_priority_method \ 46 $dbus_object_priority" 47 48# Get the priority of the image. 49# The one with the highest prirority amongst the two is the backup one 50firmware1_priority=$(eval "$dbus_command" | grep -w "1" | cut -d' ' -f 2) 51 52if [ -n "$firmware1_priority" ]; then 53 dbus_command="$dbus_property_command $dbus_object $firmware1 $dbus_object_version_method \ 54 $dbus_object_version" 55 redundant_firmware=$(eval "$dbus_command" | cut -d' ' -f 2-) 56else 57 dbus_command="$dbus_property_command $dbus_object $firmware2 $dbus_object_priority_method \ 58 $dbus_object_priority" 59 firmware2_priority=$(eval "$dbus_command" | grep -w "1" | cut -d' ' -f 2) 60 if [ -n "$firmware2_priority" ]; then 61 dbus_command="$dbus_property_command $dbus_object $firmware2 $dbus_object_version_method \ 62 $dbus_object_version" 63 redundant_firmware=$(eval "$dbus_command" | cut -d' ' -f 2-) 64 fi 65fi 66 67if [ -n "$redundant_firmware" ]; then 68 command="printf \"\nREDUNDANT_FW=%s\n\" \"\$redundant_firmware\"" 69 add_cmd_output "$command" "$file_name" "$desc" 70else 71 log_warnig "No redundant FW available" 72fi 73 74