diff --git a/CHANGELOG.md b/CHANGELOG.md index f8919f76..b8b81c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### 12.50.0 * `[fmtc]` Added methods `TPrint`, `LPrint` and `TLPrint` +* `[system]` More fields support from `os-release` file * `[fmtc]` Added more usage examples ### 12.49.0 diff --git a/system/info.go b/system/info.go index cbe72384..18d99c67 100644 --- a/system/info.go +++ b/system/info.go @@ -156,6 +156,10 @@ type OSInfo struct { VersionCodename string `json:"version_codename"` ID string `json:"id"` IDLike string `json:"id_like"` + PlatformID string `json:"platform_id"` + Variant string `json:"variant"` + VariantID string `json:"variant_id"` + CPEName string `json:"cpe_name"` HomeURL string `json:"home_url"` BugReportURL string `json:"bugreport_url"` SupportURL string `json:"support_url"` diff --git a/system/info_linux.go b/system/info_linux.go index 228408d2..fcf13fb2 100644 --- a/system/info_linux.go +++ b/system/info_linux.go @@ -43,7 +43,7 @@ func GetSystemInfo() (*SystemInfo, error) { Hostname: byteSliceToString(info.Nodename), OS: byteSliceToString(info.Sysname), Distribution: formatDistName(osInfo.Name), - Version: osInfo.Version, + Version: osInfo.VersionID, Kernel: byteSliceToString(info.Release), Arch: byteSliceToString(info.Machine), ArchBits: getCPUArchBits(), @@ -68,28 +68,7 @@ func GetOSInfo() (*OSInfo, error) { name := strutil.ReadField(line, 0, false, "=") value := strings.Trim(strutil.ReadField(line, 1, false, "="), "\"") - switch name { - case "NAME": - info.Name = value - case "VERSION": - info.Version = value - case "ID": - info.ID = value - case "ID_LIKE": - info.IDLike = value - case "VERSION_ID": - info.VersionID = value - case "VERSION_CODENAME": - info.VersionCodename = value - case "PRETTY_NAME": - info.PrettyName = value - case "HOME_URL": - info.HomeURL = value - case "BUG_REPORT_URL": - info.BugReportURL = value - case "SUPPORT_URL": - info.SupportURL = value - } + applyOSInfo(info, name, value) } return info, nil @@ -97,6 +76,40 @@ func GetOSInfo() (*OSInfo, error) { // ////////////////////////////////////////////////////////////////////////////////// // +// applyOSInfo applies record from os-release +func applyOSInfo(info *OSInfo, name, value string) { + switch name { + case "NAME": + info.Name = value + case "VERSION": + info.Version = value + case "ID": + info.ID = value + case "ID_LIKE": + info.IDLike = value + case "PRETTY_NAME": + info.PrettyName = value + case "VERSION_ID": + info.VersionID = value + case "PLATFORM_ID": + info.PlatformID = value + case "VARIANT": + info.Variant = value + case "VARIANT_ID": + info.VariantID = value + case "CPE_NAME": + info.CPEName = value + case "VERSION_CODENAME": + info.VersionCodename = value + case "HOME_URL": + info.HomeURL = value + case "BUG_REPORT_URL": + info.BugReportURL = value + case "SUPPORT_URL": + info.SupportURL = value + } +} + // formatDistName formats distribution name func formatDistName(name string) string { switch strings.ToUpper(name) { diff --git a/system/info_linux_test.go b/system/info_linux_test.go index 64967644..d34ca243 100644 --- a/system/info_linux_test.go +++ b/system/info_linux_test.go @@ -620,7 +620,13 @@ VERSION_ID="20.10" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" -VERSION_CODENAME=groovy`) +VERSION_CODENAME=groovy +VARIANT="Server" +VARIANT_ID="server" +PLATFORM_ID="platform:el8" + +CPE_NAME="cpe:/o:oracle:linux:8:6:server" +`) sysInfo, err = GetSystemInfo() @@ -636,6 +642,10 @@ VERSION_CODENAME=groovy`) c.Assert(osInfo.VersionCodename, Equals, "groovy") c.Assert(osInfo.ID, Equals, "ubuntu") c.Assert(osInfo.IDLike, Equals, "debian") + c.Assert(osInfo.PlatformID, Equals, "platform:el8") + c.Assert(osInfo.Variant, Equals, "Server") + c.Assert(osInfo.VariantID, Equals, "server") + c.Assert(osInfo.CPEName, Equals, "cpe:/o:oracle:linux:8:6:server") c.Assert(osInfo.HomeURL, Equals, "https://www.ubuntu.com/") c.Assert(osInfo.BugReportURL, Equals, "https://bugs.launchpad.net/ubuntu/") c.Assert(osInfo.SupportURL, Equals, "https://help.ubuntu.com/")