|
|
@@ -8,6 +8,7 @@ package distro
|
|
|
import (
|
|
|
"os"
|
|
|
"runtime"
|
|
|
+ "sync/atomic"
|
|
|
)
|
|
|
|
|
|
type Distro string
|
|
|
@@ -22,17 +23,25 @@ const (
|
|
|
Pfsense = Distro("pfsense")
|
|
|
OPNsense = Distro("opnsense")
|
|
|
TrueNAS = Distro("truenas")
|
|
|
+ Gokrazy = Distro("gokrazy")
|
|
|
)
|
|
|
|
|
|
+var distroAtomic atomic.Value // of Distro
|
|
|
+
|
|
|
// Get returns the current distro, or the empty string if unknown.
|
|
|
func Get() Distro {
|
|
|
- if runtime.GOOS == "linux" {
|
|
|
- return linuxDistro()
|
|
|
+ d, ok := distroAtomic.Load().(Distro)
|
|
|
+ if ok {
|
|
|
+ return d
|
|
|
}
|
|
|
- if runtime.GOOS == "freebsd" {
|
|
|
- return freebsdDistro()
|
|
|
+ switch runtime.GOOS {
|
|
|
+ case "linux":
|
|
|
+ d = linuxDistro()
|
|
|
+ case "freebsd":
|
|
|
+ d = freebsdDistro()
|
|
|
}
|
|
|
- return ""
|
|
|
+ distroAtomic.Store(d) // even if empty
|
|
|
+ return d
|
|
|
}
|
|
|
|
|
|
func have(file string) bool {
|
|
|
@@ -62,6 +71,8 @@ func linuxDistro() Distro {
|
|
|
return NixOS
|
|
|
case have("/etc/config/uLinux.conf"):
|
|
|
return QNAP
|
|
|
+ case haveDir("/gokrazy"):
|
|
|
+ return Gokrazy
|
|
|
}
|
|
|
return ""
|
|
|
}
|