2023-12-09 19:25:29 +04:00
|
|
|
//go:build unix
|
|
|
|
// +build unix
|
|
|
|
|
2023-10-30 02:18:41 +04:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func OSVersion() (string, error) {
|
|
|
|
switch osName := runtime.GOOS; osName {
|
|
|
|
case "linux":
|
|
|
|
// Implemented just in case for future. Guess if it will ever be needed
|
|
|
|
// then a kernel version will be used to compare against.
|
|
|
|
osRelease, err := os.ReadFile("/proc/sys/kernel/osrelease")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
kVer := strings.Split(string(osRelease), "-")
|
|
|
|
if len(kVer) >= 1 {
|
|
|
|
return kVer[0], nil
|
|
|
|
}
|
|
|
|
return "", errors.New("malformed osrelease")
|
|
|
|
}
|
|
|
|
return "", errors.New("unknown OS")
|
|
|
|
}
|