Skip to content

Instantly share code, notes, and snippets.

@sbz
Created March 25, 2021 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbz/3c23c52d6817246b3682922944a9c3ba to your computer and use it in GitHub Desktop.
Save sbz/3c23c52d6817246b3682922944a9c3ba to your computer and use it in GitHub Desktop.
crowdsec patch uuid for BSD systems
diff --git c/cmd/crowdsec-cli/machines.go w/cmd/crowdsec-cli/machines.go
index bbdf11c..33e87e9 100644
--- c/cmd/crowdsec-cli/machines.go
+++ w/cmd/crowdsec-cli/machines.go
@@ -7,6 +7,7 @@ import (
"io/ioutil"
"math/big"
"os"
+ "runtime"
"strings"
"time"
@@ -59,17 +60,37 @@ func generatePassword(length int) string {
return string(buf)
}
+func readUUID() (string, error) {
+ var uuidfile string
+
+ switch runtime.GOOS {
+ case "freebsd":
+ uuidfile = "/etc/hostid"
+ case "openbsd":
+ uuidfile = "/etc/machine-id"
+ // linux
+ default:
+ uuidfile = uuid
+ }
+
+ bID, err := ioutil.ReadFile(uuidfile)
+ if err != nil {
+ return "", err
+ }
+
+ return string(bID), nil
+}
+
func generateID() (string, error) {
id, err := machineid.ID()
if err != nil {
log.Debugf("failed to get machine-id with usual files : %s", err)
}
if id == "" || err != nil {
- bID, err := ioutil.ReadFile(uuid)
+ id, err = readUUID()
if err != nil {
return "", errors.Wrap(err, "generating machine id")
}
- id = string(bID)
}
id = strings.ReplaceAll(id, "-", "")[:32]
id = fmt.Sprintf("%s%s", id, generatePassword(16))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment