From 58e1475ec746bb69ca48a1d0ea455f8942ade43e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 4 Oct 2021 09:52:25 -0700 Subject: [PATCH] hostinfo: look up Synology hardware a more specific way Fixes #2991 Signed-off-by: Brad Fitzpatrick --- hostinfo/hostinfo_linux.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/hostinfo/hostinfo_linux.go b/hostinfo/hostinfo_linux.go index cb8ee2aed..f9bd5b283 100644 --- a/hostinfo/hostinfo_linux.go +++ b/hostinfo/hostinfo_linux.go @@ -22,13 +22,30 @@ import ( func init() { osVersion = osVersionLinux - if v, _ := os.ReadFile("/sys/firmware/devicetree/base/model"); len(v) > 0 { - // Look up "Raspberry Pi 4 Model B Rev 1.2", - // etc. Usually set on ARM SBCs. - SetDeviceModel(strings.Trim(string(v), "\x00\r\n\t ")) + if v := linuxDeviceModel(); v != "" { + SetDeviceModel(v) } } +func linuxDeviceModel() string { + for _, path := range []string{ + // First try the Synology-specific location. + // Example: "DS916+-j" + "/proc/sys/kernel/syno_hw_version", + + // Otherwise, try the Devicetree model, usually set on + // ARM SBCs, etc. + // Example: "Raspberry Pi 4 Model B Rev 1.2" + "/sys/firmware/devicetree/base/model", // Raspberry Pi 4 Model B Rev 1.2" + } { + b, _ := os.ReadFile(path) + if s := strings.Trim(string(b), "\x00\r\n\t "); s != "" { + return s + } + } + return "" +} + func osVersionLinux() string { dist := distro.Get() propFile := "/etc/os-release"