Skip to content

Commit

Permalink
Add "pre-Catalina" support (#15)
Browse files Browse the repository at this point in the history
- fall back to regex to pull serial_number and platform_UUID output from system_profiler if -json option is not supported
- use macOS 11 runner to build for x86_64 to support macOS 10.14+ (and earlier?)
  • Loading branch information
jetfir3 authored Jan 9, 2024
1 parent eda742b commit 4655c24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
if-no-files-found: error

build-x86:
runs-on: macos-13
runs-on: macos-11

steps:
- uses: actions/checkout@v3
Expand Down
17 changes: 14 additions & 3 deletions versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"regexp"
"strings"

"github.com/tidwall/gjson"
Expand Down Expand Up @@ -36,10 +37,20 @@ func getSoftwareName() string {
func getSerialNumber() (serial, uuid string) {
data, err := exec.Command("system_profiler", "SPHardwareDataType", "-json").Output()
if err != nil {
panic(fmt.Errorf("error running system_profiler: %w", err))
out, err := exec.Command("system_profiler", "SPHardwareDataType", "-xml").Output()
if err != nil {
panic(fmt.Errorf("error running system_profiler: %w", err))
}
serialRegex := regexp.MustCompile(`<key>serial_number</key>\s*<string>([^<]*)</string>`)
uuidRegex := regexp.MustCompile(`<key>platform_UUID</key>\s*<string>([^<]*)</string>`)

serial = serialRegex.FindStringSubmatch(string(out))[1]
uuid = uuidRegex.FindStringSubmatch(string(out))[1]
} else {
serial = gjson.GetBytes(data, "SPHardwareDataType.0.serial_number").Str
uuid = gjson.GetBytes(data, "SPHardwareDataType.0.platform_UUID").Str
}
return gjson.GetBytes(data, "SPHardwareDataType.0.serial_number").Str,
gjson.GetBytes(data, "SPHardwareDataType.0.platform_UUID").Str
return serial, uuid
}

func getHostname() string {
Expand Down

0 comments on commit 4655c24

Please sign in to comment.