blob: 697dbb0aa13fb149a2daeab9913f9f0b11c0a810 [file] [log] [blame]
#!/bin/bash
source /usr/share/firmware-versions/config
FORMAT="%-26s: %s\n"
function printFirmwareVersion() {
local redfishName="$1"
local displayName="$2"
# When display is required, it will show the version as "null" if the version is not found
# When display is optional, it will only show the version if the version can be found
local display="required"
if [[ ! -z "$3" ]]; then
display="$3"
fi
# Get redfish firmware version link
local targetUrl
if [[ "$redfishName" == "bmc" ]]; then
targetUrl="localhost$(curl -s localhost/redfish/v1/Managers/bmc | jq -r .Links.ActiveSoftwareImage.[])"
else
targetUrl="localhost/redfish/v1/UpdateService/FirmwareInventory/${redfishName}"
fi
# Show firmware version
local version="$(curl -s "$targetUrl" | jq .Version)"
if [[ "$display" == "optional" ]] && [[ "$version" == "null" ]]; then
# When version is not found, jq will return null
return
fi
printf "$FORMAT" "$displayName" "$version"
}
function platformSpecificVersions() {
# Load the config from platform and show the version
while [[ ! -z "$@" ]]; do
printFirmwareVersion "$1" "$2" "$3"
shift 3
done
}
function printStorageVersion() {
local storages="$(curl -s localhost/redfish/v1/Systems/system/Storage | jq -r .Members[][])"
local controller
local controllerCount
local version
for storage in ${storages[@]}; do
controllerCount=$(curl -s "localhost${storage}/Controllers" | jq -r '."Members@odata.count"')
for controller in $(curl -s "localhost${storage}/Controllers" | jq -r .Members[][]); do
# Only show if FirmwareVersion exist
if [ "$(curl -s "localhost${controller}" | jq 'has("FirmwareVersion")')" == "false" ]; then
continue
fi
version="$(curl -s "localhost${controller}" | jq -r .FirmwareVersion)"
# If there are multiple version in the controller, name it as $StorageName_$id
if [ $controllerCount -eq 1 ]; then
printf "$FORMAT" "$(basename $storage)" "$version"
else
printf "$FORMAT" "$(basename $storage)_$(basename $controller)" "$version"
fi
done
done
}
function main() {
printFirmwareVersion "bmc" "bmc"
printFirmwareVersion "bios_active" "bios"
# Platform Specific Version
platformSpecificVersions "${versionMap[@]}"
printStorageVersion
}
main