提交 91a97374 编写于 作者: F Fabian Ruff

Add SuSe platform detection

上级 ce904df5
...@@ -208,7 +208,12 @@ func GetPlatformInformation() (platform string, family string, version string, e ...@@ -208,7 +208,12 @@ func GetPlatformInformation() (platform string, family string, version string, e
if err == nil { if err == nil {
version = getRedhatishVersion(contents) 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 // TODO: slackware detecion
} else if common.PathExists("/etc/arch-release") { } else if common.PathExists("/etc/arch-release") {
platform = "arch" platform = "arch"
...@@ -237,7 +242,7 @@ func GetPlatformInformation() (platform string, family string, version string, e ...@@ -237,7 +242,7 @@ func GetPlatformInformation() (platform string, family string, version string, e
family = "fedora" family = "fedora"
case "oracle", "centos", "redhat", "scientific", "enterpriseenterprise", "amazon", "xenserver", "cloudlinux", "ibm_powerkvm": case "oracle", "centos", "redhat", "scientific", "enterpriseenterprise", "amazon", "xenserver", "cloudlinux", "ibm_powerkvm":
family = "rhel" family = "rhel"
case "suse": case "suse", "opensuse":
family = "suse" family = "suse"
case "gentoo": case "gentoo":
family = "gentoo" family = "gentoo"
...@@ -276,6 +281,26 @@ func getRedhatishPlatform(contents []string) string { ...@@ -276,6 +281,26 @@ func getRedhatishPlatform(contents []string) string {
return f[0] 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) { func GetVirtualization() (string, string, error) {
var system string var system string
var role string var role string
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册