2022-07-03 13:08:30 +03:00
|
|
|
// +build darwin
|
|
|
|
|
|
|
|
package xid
|
|
|
|
|
2024-09-02 14:08:54 +03:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
2022-07-03 13:08:30 +03:00
|
|
|
|
|
|
|
func readPlatformMachineID() (string, error) {
|
2024-09-02 14:08:54 +03:00
|
|
|
ioreg, err := exec.LookPath("ioreg")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := exec.Command(ioreg, "-rd1", "-c", "IOPlatformExpertDevice")
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, line := range strings.Split(string(out), "\n") {
|
|
|
|
if strings.Contains(line, "IOPlatformUUID") {
|
|
|
|
parts := strings.SplitAfter(line, `" = "`)
|
|
|
|
if len(parts) == 2 {
|
|
|
|
uuid := strings.TrimRight(parts[1], `"`)
|
|
|
|
return strings.ToLower(uuid), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", errors.New("cannot find host id")
|
2022-07-03 13:08:30 +03:00
|
|
|
}
|