deps: update images to v0.54.0
Update images dependency and adjust import paths for distro package changes. Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
This commit is contained in:
parent
356a222b83
commit
809f2544ad
81 changed files with 6722 additions and 5341 deletions
41
vendor/github.com/osbuild/images/pkg/distro/host.go
generated
vendored
41
vendor/github.com/osbuild/images/pkg/distro/host.go
generated
vendored
|
|
@ -3,22 +3,29 @@ package distro
|
|||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// variable so that it can be overridden in tests
|
||||
var getHostDistroNameTree = "/"
|
||||
|
||||
// GetHostDistroName returns the name of the host distribution, such as
|
||||
// "fedora-32" or "rhel-8.2". It does so by reading the /etc/os-release file.
|
||||
func GetHostDistroName() (string, error) {
|
||||
f, err := os.Open("/etc/os-release")
|
||||
osrelease, err := ReadOSReleaseFromTree(getHostDistroNameTree)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", fmt.Errorf("cannot get the host distro name: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
osrelease, err := readOSRelease(f)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
if _, ok := osrelease["ID"]; !ok {
|
||||
return "", errors.New("cannot get the host distro name: missing ID field in os-release")
|
||||
}
|
||||
if _, ok := osrelease["VERSION_ID"]; !ok {
|
||||
return "", errors.New("cannot get the host distro name: missing VERSION_ID field in os-release")
|
||||
}
|
||||
|
||||
name := osrelease["ID"] + "-" + osrelease["VERSION_ID"]
|
||||
|
|
@ -48,3 +55,25 @@ func readOSRelease(r io.Reader) (map[string]string, error) {
|
|||
|
||||
return osrelease, nil
|
||||
}
|
||||
|
||||
// ReadOSReleaseFromTree reads the os-release file from the given root directory.
|
||||
//
|
||||
// According to os-release(5), the os-release file should be located in either /etc/os-release or /usr/lib/os-release,
|
||||
// so both locations are tried, with the former taking precedence.
|
||||
func ReadOSReleaseFromTree(root string) (map[string]string, error) {
|
||||
locations := []string{
|
||||
"etc/os-release",
|
||||
"usr/lib/os-release",
|
||||
}
|
||||
var errs []string
|
||||
for _, location := range locations {
|
||||
f, err := os.Open(path.Join(root, location))
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
return readOSRelease(f)
|
||||
}
|
||||
errs = append(errs, fmt.Sprintf("cannot read %s: %v", location, err))
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("failed to read os-release:\n%s", strings.Join(errs, "\n"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue