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