diff --git a/changelog.md b/changelog.md index 4cc7a47f..05d0a410 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ ## Changelog +#### v5.7.1 + +* `[usage]` Improved build info output +* `[system]` Improved OS version search process + #### v5.7.0 * `[process]` `GetTree` now can return tree for custom root process diff --git a/system/info_linux.go b/system/info_linux.go index f40e743b..069198a5 100644 --- a/system/info_linux.go +++ b/system/info_linux.go @@ -51,19 +51,19 @@ func getDistributionInfo() (string, string) { case isFileExist("/etc/centos-release"): distribution = LINUX_CENTOS - version = getReleasePart("/etc/centos-release", 2) + version = getReleasePart("/etc/centos-release") case isFileExist("/etc/fedora-release"): distribution = LINUX_FEDORA - version = getReleasePart("/etc/fedora-release", 2) + version = getReleasePart("/etc/fedora-release") case isFileExist("/etc/gentoo-release"): distribution = LINUX_GENTOO - version = getReleasePart("/etc/gentoo-release", 4) + version = getReleasePart("/etc/gentoo-release") case isFileExist("/etc/redhat-release"): distribution = LINUX_RHEL - version = getReleasePart("/etc/redhat-release", 6) + version = getReleasePart("/etc/redhat-release") case isFileExist("/etc/SuSE-release"): distribution = LINUX_SUSE @@ -81,20 +81,32 @@ func getDistributionInfo() (string, string) { return distribution, version } -func getReleasePart(file string, field int) string { +func getReleasePart(file string) string { data, err := ioutil.ReadFile(file) if err != nil || len(data) == 0 { return "" } - versionSlice := strings.Split(string(data), " ") + return findOSVersionNumber(string(data)) +} - if len(versionSlice) < field+1 { - return "" +func findOSVersionNumber(data string) string { +WORDLOOP: + for _, word := range strings.Split(data, " ") { + for _, r := range word { + switch r { + case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.': + continue + default: + continue WORDLOOP + } + } + + return word } - return versionSlice[field] + return "" } func getRawRelease(file string) string { diff --git a/usage/usage.go b/usage/usage.go index b629c675..e096b36a 100644 --- a/usage/usage.go +++ b/usage/usage.go @@ -184,7 +184,7 @@ func (about *About) Render() { switch { case about.Build != "": fmtc.Printf( - "\n{*c}%s {c}%s{!}{s}%s (%s){!} - %s\n\n", + "\n{*c}%s {c}%s{!}{s}%s{!} {s-}(%s){!} - %s\n\n", about.App, about.Version, about.Release, about.Build, about.Desc, )