27 lines
577 B
Go
27 lines
577 B
Go
|
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")
|
||
|
}
|