From b90a80edcb9e8acce1a0c2298429c7ceffb312f5 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 4 Mar 2025 09:21:25 +0100 Subject: [PATCH] centos: Handle major/minor releases in derivatives properly While centos doesn't have major/minor releases, rocky, alma and rhel do, so let's make sure we handle those cases properly. Additionally, we also fix EPEL to use the proper major/minor release when we're doing EPEL 10, as since EPEL 10 there's major/minor releases for EPEL as well. --- mkosi/distributions/alma.py | 9 +++--- mkosi/distributions/centos.py | 56 ++++++++++++++++++++------------- mkosi/distributions/rhel.py | 10 +++--- mkosi/distributions/rhel_ubi.py | 8 ++--- mkosi/distributions/rocky.py | 9 +++--- 5 files changed, 51 insertions(+), 41 deletions(-) diff --git a/mkosi/distributions/alma.py b/mkosi/distributions/alma.py index 16345ebb7..2532b5c25 100644 --- a/mkosi/distributions/alma.py +++ b/mkosi/distributions/alma.py @@ -10,13 +10,14 @@ class Installer(centos.Installer): def pretty_name(cls) -> str: return "AlmaLinux" - @staticmethod - def gpgurls(context: Context) -> tuple[str, ...]: + @classmethod + def gpgurls(cls, context: Context) -> tuple[str, ...]: + major = cls.major_release(context.config) return ( find_rpm_gpgkey( context, - f"RPM-GPG-KEY-AlmaLinux-{context.config.release}", - f"https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-{context.config.release}", + f"RPM-GPG-KEY-AlmaLinux-{major}", + f"https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-{major}", ), ) diff --git a/mkosi/distributions/centos.py b/mkosi/distributions/centos.py index 3d4e54eb2..c57b8945c 100644 --- a/mkosi/distributions/centos.py +++ b/mkosi/distributions/centos.py @@ -40,6 +40,10 @@ class Installer(DistributionInstaller): def default_tools_tree_distribution(cls) -> Distribution: return Distribution.fedora + @classmethod + def major_release(cls, config: "Config") -> str: + return config.release.partition(".")[0] + @classmethod def package_manager(cls, config: "Config") -> type[PackageManager]: return Dnf @@ -68,7 +72,9 @@ class Installer(DistributionInstaller): setup_rpm(context, dbpath=cls.dbpath(context)) Dnf.setup(context, list(cls.repositories(context))) - (context.sandbox_tree / "etc/dnf/vars/stream").write_text(f"{context.config.release}-stream\n") + (context.sandbox_tree / "etc/dnf/vars/stream").write_text( + f"{cls.major_release(context.config)}-stream\n" + ) @classmethod def install(cls, context: Context) -> None: @@ -96,11 +102,11 @@ class Installer(DistributionInstaller): return a - @staticmethod - def gpgurls(context: Context) -> tuple[str, ...]: + @classmethod + def gpgurls(cls, context: Context) -> tuple[str, ...]: # First, start with the names of the appropriate keys in /etc/pki/rpm-gpg. - if context.config.release == "9": + if GenericVersion(context.config.release) == 9: rel = "RPM-GPG-KEY-centosofficial" else: rel = "RPM-GPG-KEY-centosofficial-SHA256" @@ -109,7 +115,7 @@ class Installer(DistributionInstaller): # Next, follow up with the names of the appropriate keys in /usr/share/distribution-gpg-keys. - if context.config.release == "9": + if GenericVersion(context.config.release) == 9: rel = "RPM-GPG-KEY-CentOS-Official" else: rel = "RPM-GPG-KEY-CentOS-Official-SHA256" @@ -215,11 +221,17 @@ class Installer(DistributionInstaller): @classmethod def epel_repositories(cls, context: Context) -> Iterable[RpmRepository]: + # Since EPEL 10, there's an associated minor release for every RHEL minor release. + if GenericVersion(context.config.release) >= 10: + release = context.config.release + else: + release = cls.major_release(context.config) + gpgurls = ( find_rpm_gpgkey( context, - f"RPM-GPG-KEY-EPEL-{context.config.release}", - f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{context.config.release}", + f"RPM-GPG-KEY-EPEL-{cls.major_release(context.config)}", + f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{cls.major_release(context.config)}", ), ) @@ -232,7 +244,7 @@ class Installer(DistributionInstaller): ("epel", "epel"), ("epel-testing", "epel/testing"), ] - if int(context.config.release) < 10: + if GenericVersion(context.config.release) < 10: repodirs += [ ("epel-next", "epel/next"), ("epel-next-testing", "epel/testing/next"), @@ -247,19 +259,19 @@ class Installer(DistributionInstaller): ) yield RpmRepository( repo, - f"baseurl={url}/{dir}/$releasever/Everything/$basearch", + f"baseurl={url}/{dir}/{release}/Everything/$basearch", gpgurls, enabled=False, ) yield RpmRepository( f"{repo}-debuginfo", - f"baseurl={url}/{dir}/$releasever/Everything/$basearch/debug", + f"baseurl={url}/{dir}/{release}/Everything/$basearch/debug", gpgurls, enabled=False, ) yield RpmRepository( f"{repo}-source", - f"baseurl={url}/{dir}/$releasever/Everything/source/tree", + f"baseurl={url}/{dir}/{release}/Everything/source/tree", gpgurls, enabled=False, ) @@ -268,65 +280,65 @@ class Installer(DistributionInstaller): # epel-next does not exist anymore since EPEL 10. repos = ["epel"] - if int(context.config.release) < 10: + if GenericVersion(context.config.release) < 10: repos += ["epel-next"] for repo in repos: yield RpmRepository( repo, - f"{url}&repo={repo}-$releasever", + f"{url}&repo={repo}-{release}", gpgurls, enabled=False, ) yield RpmRepository( f"{repo}-debuginfo", - f"{url}&repo={repo}-debug-$releasever", + f"{url}&repo={repo}-debug-{release}", gpgurls, enabled=False, ) yield RpmRepository( f"{repo}-source", - f"{url}&repo={repo}-source-$releasever", + f"{url}&repo={repo}-source-{release}", gpgurls, enabled=False, ) yield RpmRepository( "epel-testing", - f"{url}&repo=testing-epel$releasever", + f"{url}&repo=testing-epel{release}", gpgurls, enabled=False, ) yield RpmRepository( "epel-testing-debuginfo", - f"{url}&repo=testing-debug-epel$releasever", + f"{url}&repo=testing-debug-epel{release}", gpgurls, enabled=False, ) yield RpmRepository( "epel-testing-source", - f"{url}&repo=testing-source-epel$releasever", + f"{url}&repo=testing-source-epel{release}", gpgurls, enabled=False, ) # epel-next does not exist anymore since EPEL 10. - if int(context.config.release) < 10: + if GenericVersion(context.config.release) < 10: yield RpmRepository( "epel-next-testing", - f"{url}&repo=epel-testing-next-$releasever", + f"{url}&repo=epel-testing-next-{release}", gpgurls, enabled=False, ) yield RpmRepository( "epel-next-testing-debuginfo", - f"{url}&repo=epel-testing-next-debug-$releasever", + f"{url}&repo=epel-testing-next-debug-{release}", gpgurls, enabled=False, ) yield RpmRepository( "epel-next-testing-source", - f"{url}&repo=epel-testing-next-source-$releasever", + f"{url}&repo=epel-testing-next-source-{release}", gpgurls, enabled=False, ) diff --git a/mkosi/distributions/rhel.py b/mkosi/distributions/rhel.py index 81e45892a..186fbba46 100644 --- a/mkosi/distributions/rhel.py +++ b/mkosi/distributions/rhel.py @@ -15,14 +15,12 @@ class Installer(centos.Installer): def pretty_name(cls) -> str: return "RHEL" - @staticmethod - def gpgurls(context: Context) -> tuple[str, ...]: - major = int(float(context.config.release)) - + @classmethod + def gpgurls(cls, context: Context) -> tuple[str, ...]: return ( find_rpm_gpgkey( context, - f"RPM-GPG-KEY-redhat{major}-release", + f"RPM-GPG-KEY-redhat{cls.major_release(context.config)}-release", "https://access.redhat.com/security/data/fd431d51.txt", ), ) @@ -87,7 +85,7 @@ class Installer(centos.Installer): ) v = context.config.release - major = int(float(v)) + major = cls.major_release(context.config) yield RpmRepository( f"rhel-{v}-{repo}-rpms", f"baseurl={join_mirror(mirror, f'rhel{major}/{v}/$basearch/{repo}/os')}", diff --git a/mkosi/distributions/rhel_ubi.py b/mkosi/distributions/rhel_ubi.py index 34cbc72a6..afb9701a6 100644 --- a/mkosi/distributions/rhel_ubi.py +++ b/mkosi/distributions/rhel_ubi.py @@ -12,14 +12,12 @@ class Installer(centos.Installer): def pretty_name(cls) -> str: return "RHEL UBI" - @staticmethod - def gpgurls(context: Context) -> tuple[str, ...]: - major = int(float(context.config.release)) - + @classmethod + def gpgurls(cls, context: Context) -> tuple[str, ...]: return ( find_rpm_gpgkey( context, - f"RPM-GPG-KEY-redhat{major}-release", + f"RPM-GPG-KEY-redhat{cls.major_release(context.config)}-release", "https://access.redhat.com/security/data/fd431d51.txt", ), ) diff --git a/mkosi/distributions/rocky.py b/mkosi/distributions/rocky.py index 0a2cdfd08..007644df4 100644 --- a/mkosi/distributions/rocky.py +++ b/mkosi/distributions/rocky.py @@ -10,13 +10,14 @@ class Installer(centos.Installer): def pretty_name(cls) -> str: return "Rocky Linux" - @staticmethod - def gpgurls(context: Context) -> tuple[str, ...]: + @classmethod + def gpgurls(cls, context: Context) -> tuple[str, ...]: + major = cls.major_release(context.config) return ( find_rpm_gpgkey( context, - f"RPM-GPG-KEY-Rocky-{context.config.release}", - f"https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-{context.config.release}", + f"RPM-GPG-KEY-Rocky-{major}", + f"https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-{major}", ), ) -- 2.47.2