Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of os-release #77

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions app/inventory/system_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,13 @@ func (systemInfo *SystemInfo) gatherNetworkInfo() error {
return nil
}

const defaultPlatformInfo = "unknown"

// parseOSRelease extracts flavor and os_version information from os-release file.
func (systemInfo *SystemInfo) parseOSRelease() error {
// Set defaults to unknown
systemInfo.Flavor = "unknown"
systemInfo.OSVersion = "unknown"
systemInfo.Flavor = defaultPlatformInfo
systemInfo.OSVersion = defaultPlatformInfo

data, err := utils.ParseEnvFile("/etc/os-release")

Expand All @@ -209,24 +211,25 @@ func (systemInfo *SystemInfo) parseOSRelease() error {
return nil
}

if _, ok := data["VERSION_ID"]; !ok {
return nil
}

id := canonify(strings.ToLower(data["ID"]))
versionID := canonify(data["VERSION_ID"])
version := strings.Split(versionID, "_")
systemInfo.Flavor = fmt.Sprintf("%s_%s", id, version[0])
systemInfo.Flavor = canonify(strings.ToLower(data["ID"]))

if _, ok := data["VERSION"]; ok {

idUppercaseFirst := []rune(data["ID"])
idUppercaseFirst[0] = unicode.ToUpper(idUppercaseFirst[0])
systemInfo.OSVersion = fmt.Sprintf("%s %s", string(idUppercaseFirst), data["VERSION"])
}

if _, ok := data["VERSION_ID"]; !ok {
return nil
}

systemInfo.OSVersion = fmt.Sprintf("%s %s", strings.ToTitle(data["ID"]), data["VERSION_ID"])
versionID := canonify(data["VERSION_ID"])
version := strings.Split(versionID, "_")
systemInfo.Flavor = fmt.Sprintf("%s_%s", systemInfo.Flavor, version[0])

if systemInfo.OSVersion == defaultPlatformInfo {
systemInfo.OSVersion = fmt.Sprintf("%s %s", strings.ToTitle(data["ID"]), data["VERSION_ID"])
}
return nil
}

Expand Down
Loading