Includes tag v0.129.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.129.0 ---------------- * Update osbuild dependency commit ID to latest (osbuild/images#1347) * Author: SchutzBot, Reviewers: Achilleas Koutsou, Ondřej Budai * distro: move fedora partition tables into YAML (osbuild/images#1362) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * osbuild: create .mount and .swap units in /etc/systemd (osbuild/images#1366) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Simon de Vlieger — Somewhere on the Internet, 2025-03-28 --- tag v0.130.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.130.0 ---------------- * Imageconfig no osbuild (osbuild/images#1350) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * osbuild: add insights-client config stage (HMS-5670) (osbuild/images#1274) * Author: rverdile, Reviewers: Achilleas Koutsou, Simon de Vlieger — Somewhere on the Internet, 2025-04-01 --- tag v0.131.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.131.0 ---------------- * Update snapshots to 20250401 (osbuild/images#1374) * Author: SchutzBot, Reviewers: Achilleas Koutsou, Simon de Vlieger * disk: add missing json/yaml keys for disk structs (osbuild/images#1378) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * distro/fedora: move defaultImageConfig into YAML (osbuild/images#1337) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * distro: add `ImageType.BasePartitionTable()` (osbuild/images#1376) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * gen-manifests: show depsolve config in mock depsolve (osbuild/images#1379) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Simon de Vlieger * tools: make gen-manifests-diff run against the merge base (osbuild/images#1356) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Tomáš Hozza — Somewhere on the Internet, 2025-04-03 --- tag v0.132.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.132.0 ---------------- * Manifest checksums: detect manifest changes in PRs (osbuild/images#1380) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Simon de Vlieger * manifest,image: stop embedding `OSCustomizations` in `manifest.OS` (osbuild/images#1386) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Tomáš Hozza * manifest: addInlineDataAndStages() helper method for the OS and OSTreeDeployment pipelines (osbuild/images#1353) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Simon de Vlieger * osbuild: add new stage org.osbuild.hmac (HMS-5924) (osbuild/images#1369) * Author: Achilleas Koutsou, Reviewers: Brian C. Lane, Tomáš Hozza * rhel{7,10}: move partition table into yaml (osbuild/images#1367) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger — Somewhere on the Internet, 2025-04-07 --- tag v0.133.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.133.0 ---------------- * Update snapshots to 20250404 (osbuild/images#1389) * Author: SchutzBot, Reviewers: Simon de Vlieger, Tomáš Hozza * dnfjson: provide details if subscription cannot be found (osbuild/images#1393) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Lukáš Zapletal, Simon de Vlieger * manifestgen: extra io.Writer for depsolver (osbuild/images#1384) * Author: Simon de Vlieger, Reviewers: Michael Vogt, Tomáš Hozza — Somewhere on the Internet, 2025-04-08 --- tag v0.134.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.134.0 ---------------- * Distro/el10/ec2/modprobe: blacklist 'i2c_piix4' (RHEL-71926) (osbuild/images#1395) * Author: Tomáš Hozza, Reviewers: Achilleas Koutsou, Michael Vogt * Update osbuild dependency commit ID to latest (osbuild/images#1391) * Author: SchutzBot, Reviewers: Achilleas Koutsou, Tomáš Hozza * distro/rhel9/azure: blacklist more modules on 9.6+ (RHEL-79065) (osbuild/images#1394) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Simon de Vlieger * distro/rhel9/azure: exclude microcode_ctl on 9.6+ (RHEL-79065) (osbuild/images#1405) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Tomáš Hozza * test: add configs for Azure that match official builds (osbuild/images#1411) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Tomáš Hozza * test: fix description of `build-image` (osbuild/images#1420) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * tools/gen-manifest-checksums: sort by image name (osbuild/images#1406) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Simon de Vlieger — Somewhere on the Internet, 2025-04-14 --- commit a1ca7f34c770ac869387213923fa64ec36180084 Changes with a1ca7f34c770ac869387213923fa64ec36180084 ---------------- * RHEL 9.6+/Azure: systemd service and script for dataloss warning on temporary resource disk (osbuild/images#1434) * Author: Achilleas Koutsou, Reviewers: Tomáš Hozza * Set refclock in chrony config for Azure images on RHEL 9.6+ (RHEL-79065) (osbuild/images#1400) * Author: Achilleas Koutsou, Reviewers: Tomáš Hozza * Update snapshots to 20250415 (osbuild/images#1431) * Author: SchutzBot, Reviewers: Achilleas Koutsou * WSL: add packages for podman and proc utilities (COMPOSER-2455) (osbuild/images#1425) * Author: Sanne Raymaekers, Reviewers: Tomáš Hozza * [RHEL-9.6+/Azure]: update waagent.conf and add nvme_core.io_timeout kernel arg (osbuild/images#1430) * Author: Achilleas Koutsou, Reviewers: Ondřej Budai, Sanne Raymaekers * [RHEL/Azure RHUI] Disable `auto_enable_yum_plugins` in the RHSM config as a BP customization (osbuild/images#1415) * Author: Tomáš Hozza, Reviewers: Achilleas Koutsou * ci: dependency updater gobump golang fix (osbuild/images#1441) * Author: Lukáš Zapletal, Reviewers: Ondřej Budai * ci: dependency updater gobump typo (osbuild/images#1439) * Author: Lukáš Zapletal, Reviewers: Achilleas Koutsou * ci: dependency updater via gobump (osbuild/images#1385) * Author: Lukáš Zapletal, Reviewers: Achilleas Koutsou * distro: almalinux and almalinux_kitten (osbuild/images#1375) * Author: Simon de Vlieger, Reviewers: Neal Gompa (ニール・ゴンパ), Ondřej Budai * fedora: bump branched and rawhide (osbuild/images#1440) * Author: Simon de Vlieger, Reviewers: Achilleas Koutsou, Ondřej Budai * github: don't run manifest checksum validation on main (osbuild/images#1437) * Author: Achilleas Koutsou, Reviewers: Ondřej Budai, Simon de Vlieger * manifesttest: add helper to find stages in a pipeline (osbuild/images#1418) * Author: Michael Vogt, Reviewers: Lukáš Zapletal, Simon de Vlieger * rhsm: support for podman secrets (osbuild/images#1414) * Author: Lukáš Zapletal, Reviewers: Simon de Vlieger ---
113 lines
3.3 KiB
Go
113 lines
3.3 KiB
Go
package distro
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path"
|
|
"strconv"
|
|
"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) {
|
|
osrelease, err := ReadOSReleaseFromTree(getHostDistroNameTree)
|
|
if err != nil {
|
|
return "", fmt.Errorf("cannot get the host distro name: %w", 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")
|
|
}
|
|
|
|
// In some cases (Alma Linux Kitten) `ID + VERSION_ID` is not the correct
|
|
// approach to determine the distribution. For Kitten the `/etc/os-release`
|
|
// file contains a `VERSION_ID` without a minor. We need to special case this:
|
|
if osrelease["ID"] == "almalinux" {
|
|
versionParts := strings.Split(osrelease["VERSION_ID"], ".")
|
|
|
|
if len(versionParts) > 2 {
|
|
return "", errors.New("failed to parse version from os-release, too many dotted parts")
|
|
}
|
|
|
|
majorVersion, err := strconv.Atoi(versionParts[0])
|
|
if err != nil {
|
|
return "", errors.New("failed to parse major version from os-release")
|
|
}
|
|
|
|
minorVersion := -1
|
|
if len(versionParts) > 1 {
|
|
minorVersion, err = strconv.Atoi(versionParts[1])
|
|
if err != nil {
|
|
return "", errors.New("failed to parse minor version from os-release")
|
|
}
|
|
}
|
|
|
|
// If `/etc/os-release` is `almalinux-10` then we select
|
|
// `almalinux_kitten` as our host distro. Note that it might be possible to
|
|
// not verify the major version but it's not guaranteed that with an eventual
|
|
// version 11 we will need to do this swap as well.
|
|
if majorVersion == 10 && minorVersion == -1 {
|
|
osrelease["ID"] = "almalinux_kitten"
|
|
}
|
|
}
|
|
|
|
name := osrelease["ID"] + "-" + osrelease["VERSION_ID"]
|
|
|
|
return name, nil
|
|
}
|
|
|
|
func readOSRelease(r io.Reader) (map[string]string, error) {
|
|
osrelease := make(map[string]string)
|
|
scanner := bufio.NewScanner(r)
|
|
for scanner.Scan() {
|
|
line := strings.TrimSpace(scanner.Text())
|
|
if len(line) == 0 {
|
|
continue
|
|
}
|
|
|
|
parts := strings.SplitN(line, "=", 2)
|
|
if len(parts) != 2 {
|
|
return nil, errors.New("readOSRelease: invalid input")
|
|
}
|
|
|
|
key := strings.TrimSpace(parts[0])
|
|
// drop all surrounding whitespace and double-quotes
|
|
value := strings.Trim(strings.TrimSpace(parts[1]), "\"")
|
|
osrelease[key] = value
|
|
}
|
|
|
|
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"))
|
|
}
|