2024-06-13 13:24:24 +02:00
|
|
|
//go:build freebsd
|
|
|
|
|
2021-08-27 11:34:38 +02:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-05-25 23:25:02 +02:00
|
|
|
"context"
|
2021-08-27 11:34:38 +02:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2023-03-15 07:54:51 +01:00
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2024-02-20 11:53:11 +01:00
|
|
|
"github.com/netbirdio/netbird/client/system/detect_cloud"
|
|
|
|
"github.com/netbirdio/netbird/client/system/detect_platform"
|
2023-03-15 07:54:51 +01:00
|
|
|
"github.com/netbirdio/netbird/version"
|
2021-08-27 11:34:38 +02:00
|
|
|
)
|
|
|
|
|
2022-05-25 23:25:02 +02:00
|
|
|
// GetInfo retrieves and parses the system information
|
2024-11-29 00:04:36 +01:00
|
|
|
func GetInfo(ctx context.Context, staticInfo *StaticInfo) *Info {
|
2021-08-27 11:34:38 +02:00
|
|
|
out := _getInfo()
|
2021-08-29 13:34:17 +02:00
|
|
|
for strings.Contains(out, "broken pipe") {
|
2021-08-27 11:34:38 +02:00
|
|
|
out = _getInfo()
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
2024-06-13 13:24:24 +02:00
|
|
|
osStr := strings.ReplaceAll(out, "\n", "")
|
|
|
|
osStr = strings.ReplaceAll(osStr, "\r\n", "")
|
2021-08-27 11:34:38 +02:00
|
|
|
osInfo := strings.Split(osStr, " ")
|
2024-02-20 11:53:11 +01:00
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
osName, osVersion := readOsReleaseFile()
|
2024-02-20 11:53:11 +01:00
|
|
|
|
2023-04-20 16:00:22 +02:00
|
|
|
systemHostname, _ := os.Hostname()
|
2022-05-25 23:25:02 +02:00
|
|
|
|
2024-11-29 00:04:36 +01:00
|
|
|
info := &Info{
|
2024-06-13 13:24:24 +02:00
|
|
|
GoOS: runtime.GOOS,
|
|
|
|
Kernel: osInfo[0],
|
|
|
|
Platform: runtime.GOARCH,
|
|
|
|
OS: osName,
|
|
|
|
OSVersion: osVersion,
|
|
|
|
Hostname: extractDeviceName(ctx, systemHostname),
|
|
|
|
CPUs: runtime.NumCPU(),
|
|
|
|
WiretrusteeVersion: version.NetbirdVersion(),
|
|
|
|
UIVersion: extractUserAgent(ctx),
|
|
|
|
KernelVersion: osInfo[1],
|
2024-11-29 00:04:36 +01:00
|
|
|
}
|
|
|
|
if staticInfo != nil {
|
|
|
|
info.SystemSerialNumber = staticInfo.SystemSerialNumber
|
|
|
|
info.SystemProductName = staticInfo.SystemProductName
|
|
|
|
info.SystemManufacturer = staticInfo.SystemManufacturer
|
|
|
|
info.Environment = staticInfo.Environment
|
|
|
|
}
|
|
|
|
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStaticInfo(ctx context.Context) *StaticInfo {
|
|
|
|
env := Environment{
|
|
|
|
Cloud: detect_cloud.Detect(ctx),
|
|
|
|
Platform: detect_platform.Detect(ctx),
|
|
|
|
}
|
|
|
|
|
|
|
|
return &StaticInfo{
|
|
|
|
Environment: env,
|
2024-06-13 13:24:24 +02:00
|
|
|
}
|
2021-08-27 11:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func _getInfo() string {
|
|
|
|
cmd := exec.Command("uname", "-sri")
|
|
|
|
cmd.Stdin = strings.NewReader("some input")
|
|
|
|
var out bytes.Buffer
|
|
|
|
var stderr bytes.Buffer
|
|
|
|
cmd.Stdout = &out
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
2024-06-13 13:24:24 +02:00
|
|
|
log.Warnf("getInfo: %s", err)
|
2021-08-27 11:34:38 +02:00
|
|
|
}
|
2024-06-13 13:24:24 +02:00
|
|
|
|
2021-08-27 11:34:38 +02:00
|
|
|
return out.String()
|
|
|
|
}
|