Skip to content

Commit

Permalink
Merge pull request #49 from databus23/suse_detection
Browse files Browse the repository at this point in the history
Add SuSe platform detection
  • Loading branch information
shirou committed Jun 18, 2015
2 parents ce904df + 91a9737 commit c71f9ee
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions host/host_linux.go
Expand Up @@ -208,7 +208,12 @@ func GetPlatformInformation() (platform string, family string, version string, e
if err == nil {
version = getRedhatishVersion(contents)
}
// TODO: suse detection
} else if common.PathExists("/etc/SuSE-release") {
contents, err := common.ReadLines("/etc/SuSE-release")
if err == nil {
version = getSuseVersion(contents)
platform = getSusePlatform(contents)
}
// TODO: slackware detecion
} else if common.PathExists("/etc/arch-release") {
platform = "arch"
Expand Down Expand Up @@ -237,7 +242,7 @@ func GetPlatformInformation() (platform string, family string, version string, e
family = "fedora"
case "oracle", "centos", "redhat", "scientific", "enterpriseenterprise", "amazon", "xenserver", "cloudlinux", "ibm_powerkvm":
family = "rhel"
case "suse":
case "suse", "opensuse":
family = "suse"
case "gentoo":
family = "gentoo"
Expand Down Expand Up @@ -276,6 +281,26 @@ func getRedhatishPlatform(contents []string) string {
return f[0]
}

func getSuseVersion(contents []string) string {
version := ""
for _, line := range contents {
if matches := regexp.MustCompile(`VERSION = ([\d.]+)`).FindStringSubmatch(line); matches != nil {
version = matches[1]
} else if matches := regexp.MustCompile(`PATCHLEVEL = ([\d]+)`).FindStringSubmatch(line); matches != nil {
version = version + "." + matches[1]
}
}
return version
}

func getSusePlatform(contents []string) string {
c := strings.ToLower(strings.Join(contents, ""))
if strings.Contains(c, "opensuse") {
return "opensuse"
}
return "suse"
}

func GetVirtualization() (string, string, error) {
var system string
var role string
Expand Down

0 comments on commit c71f9ee

Please sign in to comment.