mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-07 16:54:16 +01:00
c2e90a2a97
Configure via --hostname (or -n) flag in the `up` and `login` commands --------- Signed-off-by: Chinmay D. Pai <chinmay.pai@zerodha.com>
88 lines
2.0 KiB
Go
88 lines
2.0 KiB
Go
//go:build !android
|
|
// +build !android
|
|
|
|
package system
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/netbirdio/netbird/version"
|
|
)
|
|
|
|
// GetInfo retrieves and parses the system information
|
|
func GetInfo(ctx context.Context) *Info {
|
|
info := _getInfo()
|
|
for strings.Contains(info, "broken pipe") {
|
|
info = _getInfo()
|
|
time.Sleep(500 * time.Millisecond)
|
|
}
|
|
|
|
releaseInfo := _getReleaseInfo()
|
|
for strings.Contains(info, "broken pipe") {
|
|
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()}
|
|
systemHostname, _ := os.Hostname()
|
|
gio.Hostname = extractDeviceName(ctx, systemHostname)
|
|
gio.WiretrusteeVersion = version.NetbirdVersion()
|
|
gio.UIVersion = extractUserAgent(ctx)
|
|
|
|
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()
|
|
}
|