Skip to content

Commit 4968a10

Browse files
committed
fix: 支持centos6系统的repository获取
1 parent d87fb6c commit 4968a10

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

envinspection/osinfo_linux.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
package envinspection
22

3-
import "github.com/zcalusic/sysinfo"
3+
import (
4+
"io/ioutil"
5+
"regexp"
6+
"strings"
7+
8+
"github.com/zcalusic/sysinfo"
9+
)
410

511
func getOsInfo() string {
612
var si sysinfo.SysInfo
713
si.GetSysInfo()
814
var vendor = si.OS.Vendor
915
var version = si.OS.Version
16+
// centos/rhel 兼容补丁
17+
if vendor == "" || vendor == "unknown" {
18+
if content, err := ioutil.ReadFile("/etc/redhat-release"); err == nil {
19+
line := strings.ToLower(string(content))
20+
var re = regexp.MustCompile(`([a-zA-Z ]+) release ([0-9.]+)`)
21+
if m := re.FindStringSubmatch(line); len(m) == 3 {
22+
v := strings.TrimSpace(m[1])
23+
switch {
24+
case strings.Contains(v, "centos"):
25+
vendor = "centos"
26+
case strings.Contains(v, "red hat enterprise linux server"):
27+
vendor = "rhel"
28+
default:
29+
vendor = strings.ReplaceAll(v, " ", "_")
30+
}
31+
// 只保留大版本号
32+
ver := m[2]
33+
if idx := strings.Index(ver, "."); idx > 0 {
34+
version = ver[:idx]
35+
} else {
36+
version = ver
37+
}
38+
}
39+
}
40+
}
1041
switch vendor {
1142
case "opensuse-leap":
1243
vendor = "opensuse:leap"

0 commit comments

Comments
 (0)