-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharchmap.go
54 lines (44 loc) · 1.09 KB
/
archmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// rootfsbuilder - A simple tool to build Debian/Ubuntu rootfs tarballs
// Copyright (C) 2023 Hugo Melder
//
// SPDX-License-Identifier: MIT
//
package main
import (
"bytes"
"fmt"
"os/exec"
"strings"
)
var (
// Maps debian architecture names to qemu static
// architecture names.
QemuArchMap = map[string]string{
"amd64": "x86_64",
"i386": "i386",
"arm64": "aarch64",
"armel": "arm",
"armhf": "arm",
"mips": "mips",
"mipsel": "mipsel",
"mips64el": "mips64el",
"ppc64el": "ppc64le",
"s390x": "s390x",
}
)
func DebToQemuArch(debArch string) (string, error) {
arch, ok := QemuArchMap[debArch]
if !ok {
return "", fmt.Errorf("architecture '%s' not found in debian architecture to qemu static translation table", debArch)
}
return arch, nil
}
func HostToDebArch() (string, error) {
buf := bytes.Buffer{}
cmd := exec.Command("dpkg", "--print-architecture")
cmd.Stdout = &buf
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("error while running dpkg to determine host architecture: %w", err)
}
return strings.TrimSpace(buf.String()), nil
}