v23.x.lib: add envutil to get machine's architecture.
I tried to use syscall.Uname, but it is not supported on Darwin..
Change-Id: I9ab5ca2ed568b50d8edf3eedf55cac0f647ee393
diff --git a/envutil/envutil.go b/envutil/envutil.go
new file mode 100644
index 0000000..7d1400a
--- /dev/null
+++ b/envutil/envutil.go
@@ -0,0 +1,28 @@
+package envutil
+
+import (
+ "fmt"
+ "os/exec"
+ "strings"
+)
+
+// Arch returns the architecture of the physical machine using
+// the "uname -m" command.
+func Arch() (string, error) {
+ out, err := exec.Command("uname", "-m").Output()
+ if err != nil {
+ return "", fmt.Errorf("'uname -m' command failed: %v", err)
+ }
+ machine := string(out)
+ arch := ""
+ if strings.Contains(machine, "x86_64") || strings.Contains(machine, "amd64") {
+ arch = "amd64"
+ } else if strings.HasSuffix(machine, "86") {
+ arch = "386"
+ } else if strings.Contains(machine, "arm") {
+ arch = "arm"
+ } else {
+ return "", fmt.Errorf("unknown architecture: %s", machine)
+ }
+ return arch, nil
+}