2023-03-17 10:37:27 +01:00
|
|
|
//go:build !android
|
|
|
|
// +build !android
|
|
|
|
|
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
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"time"
|
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
|
|
|
|
func GetInfo(ctx context.Context) *Info {
|
2021-08-27 11:34:38 +02:00
|
|
|
info := _getInfo()
|
2021-08-29 13:22:52 +02:00
|
|
|
for strings.Contains(info, "broken pipe") {
|
2021-08-27 11:34:38 +02:00
|
|
|
info = _getInfo()
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseInfo := _getReleaseInfo()
|
2021-08-29 13:22:52 +02:00
|
|
|
for strings.Contains(info, "broken pipe") {
|
2021-08-27 11:34:38 +02:00
|
|
|
releaseInfo = _getReleaseInfo()
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
osRelease := strings.Split(releaseInfo, "\n")
|
|
|
|
var osName string
|
|
|
|
var osVer string
|
|
|
|
for _, s := range osRelease {
|
|
|
|
if strings.HasPrefix(s, "NAME=") {
|
|
|
|
osName = strings.Split(s, "=")[1]
|
|
|
|
osName = strings.ReplaceAll(osName, "\"", "")
|
|
|
|
} else if strings.HasPrefix(s, "VERSION_ID=") {
|
|
|
|
osVer = strings.Split(s, "=")[1]
|
|
|
|
osVer = strings.ReplaceAll(osVer, "\"", "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
osStr := strings.Replace(info, "\n", "", -1)
|
|
|
|
osStr = strings.Replace(osStr, "\r\n", "", -1)
|
|
|
|
osInfo := strings.Split(osStr, " ")
|
|
|
|
if osName == "" {
|
|
|
|
osName = osInfo[3]
|
|
|
|
}
|
|
|
|
gio := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: osInfo[2], OS: osName, OSVersion: osVer, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
|
2023-04-20 16:00:22 +02:00
|
|
|
systemHostname, _ := os.Hostname()
|
|
|
|
gio.Hostname = extractDeviceName(ctx, systemHostname)
|
2023-03-15 07:54:51 +01:00
|
|
|
gio.WiretrusteeVersion = version.NetbirdVersion()
|
2022-05-25 23:25:02 +02:00
|
|
|
gio.UIVersion = extractUserAgent(ctx)
|
2022-02-03 18:35:54 +01:00
|
|
|
|
2021-08-27 11:34:38 +02:00
|
|
|
return gio
|
|
|
|
}
|
|
|
|
|
|
|
|
func _getInfo() string {
|
|
|
|
cmd := exec.Command("uname", "-srio")
|
|
|
|
cmd.Stdin = strings.NewReader("some")
|
|
|
|
var out bytes.Buffer
|
|
|
|
var stderr bytes.Buffer
|
|
|
|
cmd.Stdout = &out
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("getInfo:", err)
|
|
|
|
}
|
|
|
|
return out.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func _getReleaseInfo() string {
|
|
|
|
cmd := exec.Command("cat", "/etc/os-release")
|
|
|
|
cmd.Stdin = strings.NewReader("some")
|
|
|
|
var out bytes.Buffer
|
|
|
|
var stderr bytes.Buffer
|
|
|
|
cmd.Stdout = &out
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("getReleaseInfo:", err)
|
|
|
|
}
|
|
|
|
return out.String()
|
|
|
|
}
|