blob: e0e4f4b18e522a90c49b93123305ae3ebc14db3a [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 main() {
printFirmwareVersion "bmc" "bmc"
printFirmwareVersion "bios_active" "bios"
# Platform Specific Version
platformSpecificVersions "${versionMap[@]}"
}
main