Skip to content

Commit

Permalink
Merge pull request #88 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 5.7.1
  • Loading branch information
andyone authored Dec 13, 2016
2 parents 4d2c860 + 848b4fd commit b8b90e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 21 additions & 9 deletions system/info_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit b8b90e3

Please sign in to comment.