Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add productPath as fallback #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions cmd/machineid/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
// Usage: machineid [options]
//
// Options:
// --appid <AppID> Protect machine id by hashing it together with an app id.
//
// --appid <AppID> Protect machine id by hashing it together with an app id.
//
// Try:
// machineid
// machineid --appid MyAppID
//
// machineid
// machineid --appid MyAppID
package main

import (
"flag"
"fmt"
"log"

"github.com/denisbrodbeck/machineid"
"github.com/iseki0/machineid"
)

const usageStr = `
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/denisbrodbeck/machineid"
"github.com/iseki0/machineid"
)

func Example() {
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/iseki0/machineid

go 1.18

require golang.org/x/sys v0.24.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2 changes: 1 addition & 1 deletion id.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Linux users can generate a new id with `dbus-uuidgen` and put the id into
// `/var/lib/dbus/machine-id` and `/etc/machine-id`.
// Windows users can use the `sysprep` toolchain to create images, which produce valid images ready for distribution.
package machineid // import "github.com/denisbrodbeck/machineid"
package machineid // import "github.com/iseki0/machineid"

import (
"fmt"
Expand Down
1 change: 1 addition & 0 deletions id_bsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build freebsd || netbsd || openbsd || dragonfly || solaris
// +build freebsd netbsd openbsd dragonfly solaris

package machineid
Expand Down
1 change: 1 addition & 0 deletions id_darwin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build darwin
// +build darwin

package machineid
Expand Down
1 change: 1 addition & 0 deletions id_darwin_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build darwin
// +build darwin

package machineid
Expand Down
9 changes: 9 additions & 0 deletions id_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package machineid
Expand All @@ -9,6 +10,10 @@ const (
// Some systems (like Fedora 20) only know this path.
// Sometimes it's the other way round.
dbusPathEtc = "/etc/machine-id"

// Some old release haven't above two paths.
// Workaround.
productPath = "/sys/class/dmi/id/product_uuid"
)

// machineID returns the uuid specified at `/var/lib/dbus/machine-id` or `/etc/machine-id`.
Expand All @@ -20,6 +25,10 @@ func machineID() (string, error) {
// try fallback path
id, err = readFile(dbusPathEtc)
}
if err != nil {
// try fallback path
id, err = readFile(productPath)
}
if err != nil {
return "", err
}
Expand Down
1 change: 1 addition & 0 deletions id_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package machineid
Expand Down