2022-07-03 10:08:30 +00:00
|
|
|
// +build darwin
|
|
|
|
|
|
|
|
package xid
|
|
|
|
|
2024-09-02 11:08:54 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
2022-07-03 10:08:30 +00:00
|
|
|
|
|
|
|
func readPlatformMachineID() (string, error) {
|
2024-09-02 11:08:54 +00: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 10:08:30 +00:00
|
|
|
}
|