github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/lib/buildinfo/osversion.go (about)

     1  //go:build !windows
     2  
     3  package buildinfo
     4  
     5  import (
     6  	"strings"
     7  
     8  	"github.com/shirou/gopsutil/v3/host"
     9  )
    10  
    11  // GetOSVersion returns OS version, kernel and bitness
    12  func GetOSVersion() (osVersion, osKernel string) {
    13  	if platform, _, version, err := host.PlatformInformation(); err == nil && platform != "" {
    14  		osVersion = platform
    15  		if version != "" {
    16  			osVersion += " " + version
    17  		}
    18  	}
    19  
    20  	if version, err := host.KernelVersion(); err == nil && version != "" {
    21  		osKernel = version
    22  	}
    23  
    24  	if arch, err := host.KernelArch(); err == nil && arch != "" {
    25  		if strings.HasSuffix(arch, "64") && osVersion != "" {
    26  			osVersion += " (64 bit)"
    27  		}
    28  		if osKernel != "" {
    29  			osKernel += " (" + arch + ")"
    30  		}
    31  	}
    32  
    33  	return
    34  }