fix for gpu parsing
This commit is contained in:
parent
083db53aa4
commit
5add247d4a
51
main.go
51
main.go
@ -169,39 +169,60 @@ func getCpu() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getGpu() string {
|
func getGpu() string {
|
||||||
out, err := exec.Command("sh", "-c", "lspci | grep -E 'VGA|3D'").Output()
|
out, err := exec.Command("sh", "-c", "lspci -mm | grep -E 'VGA|3D'").Output()
|
||||||
if err != nil || len(out) == 0 {
|
if err != nil || len(out) == 0 {
|
||||||
return "Unknown or no GPU"
|
return "Unknown GPU"
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||||
var gpus []string
|
var gpus []string
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
parts := strings.Split(line, ": ")
|
re := regexp.MustCompile(`"([^"]+)"`)
|
||||||
if len(parts) > 1 {
|
matches := re.FindAllStringSubmatch(line, -1)
|
||||||
cleaned := cleanGpuString(parts[len(parts)-1])
|
|
||||||
if cleaned != "" {
|
if len(matches) >= 3 {
|
||||||
gpus = append(gpus, cleaned)
|
vendor := matches[1][1]
|
||||||
}
|
device := matches[2][1]
|
||||||
|
|
||||||
|
cleaned := cleanGpuString(vendor + " " + device)
|
||||||
|
gpus = append(gpus, cleaned)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(gpus) > 0 {
|
if len(gpus) > 0 {
|
||||||
return strings.Join(gpus, " / ")
|
return strings.Join(gpus, " / ")
|
||||||
}
|
}
|
||||||
|
|
||||||
return "GPU not found"
|
return "GPU not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanGpuString(raw string) string {
|
func cleanGpuString(raw string) string {
|
||||||
re := regexp.MustCompile(`\[.*?]|\(.*?\)`)
|
prettyNameRe := regexp.MustCompile(`\[(.*?)]`)
|
||||||
res := re.ReplaceAllString(raw, "")
|
match := prettyNameRe.FindStringSubmatch(raw)
|
||||||
|
|
||||||
res = strings.ReplaceAll(res, "Corporation", "")
|
res := raw
|
||||||
res = strings.ReplaceAll(res, "Controller", "")
|
if len(match) > 1 {
|
||||||
res = strings.ReplaceAll(res, "VGA compatible", "")
|
vendor := ""
|
||||||
res = strings.ReplaceAll(res, "3D", "")
|
if strings.Contains(strings.ToLower(raw), "nvidia") {
|
||||||
|
vendor = "NVIDIA "
|
||||||
|
}
|
||||||
|
if strings.Contains(strings.ToLower(raw), "intel") {
|
||||||
|
vendor = "Intel "
|
||||||
|
}
|
||||||
|
if strings.Contains(strings.ToLower(raw), "amd") {
|
||||||
|
vendor = "AMD "
|
||||||
|
}
|
||||||
|
|
||||||
|
res = vendor + match[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
re := regexp.MustCompile(`\(.*?\)|\[.*?]`)
|
||||||
|
res = re.ReplaceAllString(res, "")
|
||||||
|
|
||||||
|
fluff := []string{"Corporation", "Controller", "VGA compatible", "3D", "Graphics", "Device"}
|
||||||
|
for _, word := range fluff {
|
||||||
|
res = strings.ReplaceAll(res, word, "")
|
||||||
|
}
|
||||||
|
|
||||||
return strings.Join(strings.Fields(res), " ")
|
return strings.Join(strings.Fields(res), " ")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user