2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 06:47:20 +08:00

fix: opencloudos检查

This commit is contained in:
耗子
2024-10-17 13:20:24 +08:00
parent 7cb497929b
commit d30874a5d4

View File

@@ -1,23 +1,58 @@
package os
import (
"bufio"
"os"
"strings"
)
func readOSRelease() map[string]string {
file, err := os.Open("/etc/os-release")
if err != nil {
return nil
}
defer file.Close()
osRelease := make(map[string]string)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if len(line) > 0 && strings.Contains(line, "=") {
parts := strings.SplitN(line, "=", 2)
key := parts[0]
value := strings.Trim(parts[1], `"`)
osRelease[key] = value
}
}
return osRelease
}
// IsDebian 判断是否是 Debian 系统
func IsDebian() bool {
_, err := os.Stat("/etc/debian_version")
return err == nil
osRelease := readOSRelease()
if osRelease == nil {
return false
}
id, idLike := osRelease["ID"], osRelease["ID_LIKE"]
return id == "debian" || strings.Contains(idLike, "debian")
}
// IsRHEL 判断是否是 RHEL 系统
func IsRHEL() bool {
_, err := os.Stat("/etc/redhat-release")
return err == nil
osRelease := readOSRelease()
if osRelease == nil {
return false
}
id, idLike := osRelease["ID"], osRelease["ID_LIKE"]
return id == "tencentos" || id == "opencloudos" || id == "rhel" || strings.Contains(idLike, "rhel")
}
// IsUbuntu 判断是否是 Ubuntu 系统
func IsUbuntu() bool {
_, err := os.Stat("/etc/lsb-release")
return err == nil
osRelease := readOSRelease()
if osRelease == nil {
return false
}
id, idLike := osRelease["ID"], osRelease["ID_LIKE"]
return id == "ubuntu" || strings.Contains(idLike, "ubuntu")
}