From 33e2fa5155b145e6c335f7ec055e262b9767ebf3 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 16 Jan 2023 13:45:55 +0100 Subject: [PATCH] centos: Modernize repo URLs Let's use DNF variables where we can. We also modify releasever to be only the release version without "-stream" and use $stream when we need the releasever with "-stream". This matches the upstream usages of these variables. --- mkosi/distributions/alma.py | 9 +++--- mkosi/distributions/centos.py | 56 +++++++++++++++++------------------ mkosi/distributions/fedora.py | 2 +- mkosi/distributions/rocky.py | 7 ++--- 4 files changed, 35 insertions(+), 39 deletions(-) diff --git a/mkosi/distributions/alma.py b/mkosi/distributions/alma.py index 59c39af1d..4c54de895 100644 --- a/mkosi/distributions/alma.py +++ b/mkosi/distributions/alma.py @@ -2,7 +2,6 @@ from pathlib import Path -from mkosi.backend import MkosiConfig from mkosi.distributions.centos import CentosInstaller @@ -10,8 +9,8 @@ class AlmaInstaller(CentosInstaller): @staticmethod def _gpg_locations(epel_release: int) -> tuple[Path, str]: return ( - Path(f"/etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux-{epel_release}"), - f"https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-{epel_release}", + Path("/etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux-$releasever"), + "https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-$releasever", ) @classmethod @@ -19,5 +18,5 @@ class AlmaInstaller(CentosInstaller): return "almalinux" @classmethod - def _mirror_repo_url(cls, config: MkosiConfig, repo: str) -> str: - return f"https://mirrors.almalinux.org/mirrorlist/{config.release}/{repo.lower()}" + def _mirror_repo_url(cls, repo: str) -> str: + return f"https://mirrors.almalinux.org/mirrorlist/$releasever/{repo.lower()}" diff --git a/mkosi/distributions/centos.py b/mkosi/distributions/centos.py index 0c1928cee..f55e86122 100644 --- a/mkosi/distributions/centos.py +++ b/mkosi/distributions/centos.py @@ -105,10 +105,10 @@ class CentosInstaller(DistributionInstaller): ) @staticmethod - def _epel_gpg_locations(epel_release: int) -> tuple[Path, str]: + def _epel_gpg_locations() -> tuple[Path, str]: return ( - Path(f"/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{epel_release}"), - f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{epel_release}", + Path("/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever"), + "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-$releasever", ) @classmethod @@ -116,8 +116,8 @@ class CentosInstaller(DistributionInstaller): return "centos" @classmethod - def _mirror_repo_url(cls, config: MkosiConfig, repo: str) -> str: - return f"http://mirrorlist.centos.org/?release={config.release}&arch=$basearch&repo={repo}" + def _mirror_repo_url(cls, repo: str) -> str: + return f"http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo={repo}" @classmethod def _variant_repos(cls, config: MkosiConfig, epel_release: int) -> list[Repo]: @@ -125,33 +125,33 @@ class CentosInstaller(DistributionInstaller): directory = cls._mirror_directory() gpgpath, gpgurl = cls._gpg_locations(epel_release) - epel_gpgpath, epel_gpgurl = cls._epel_gpg_locations(epel_release) + epel_gpgpath, epel_gpgurl = cls._epel_gpg_locations() if config.local_mirror: appstream_url = f"baseurl={config.local_mirror}" baseos_url = extras_url = powertools_url = crb_url = epel_url = None elif config.mirror: - appstream_url = f"baseurl={config.mirror}/{directory}/{config.release}/AppStream/$basearch/os" - baseos_url = f"baseurl={config.mirror}/{directory}/{config.release}/BaseOS/$basearch/os" - extras_url = f"baseurl={config.mirror}/{directory}/{config.release}/extras/$basearch/os" + appstream_url = f"baseurl={config.mirror}/{directory}/$stream/AppStream/$basearch/os" + baseos_url = f"baseurl={config.mirror}/{directory}/$stream/BaseOS/$basearch/os" + extras_url = f"baseurl={config.mirror}/{directory}/$stream/extras/$basearch/os" if epel_release >= 9: - crb_url = f"baseurl={config.mirror}/{directory}/{config.release}/CRB/$basearch/os" + crb_url = f"baseurl={config.mirror}/{directory}/$stream/CRB/$basearch/os" powertools_url = None else: crb_url = None - powertools_url = f"baseurl={config.mirror}/{directory}/{config.release}/PowerTools/$basearch/os" - epel_url = f"baseurl={config.mirror}/epel/{epel_release}/Everything/$basearch" + powertools_url = f"baseurl={config.mirror}/{directory}/$stream/PowerTools/$basearch/os" + epel_url = f"baseurl={config.mirror}/epel/$releasever/Everything/$basearch" else: - appstream_url = f"mirrorlist={cls._mirror_repo_url(config, 'AppStream')}" - baseos_url = f"mirrorlist={cls._mirror_repo_url(config, 'BaseOS')}" - extras_url = f"mirrorlist={cls._mirror_repo_url(config, 'extras')}" + appstream_url = f"mirrorlist={cls._mirror_repo_url('AppStream')}" + baseos_url = f"mirrorlist={cls._mirror_repo_url('BaseOS')}" + extras_url = f"mirrorlist={cls._mirror_repo_url('extras')}" if epel_release >= 9: - crb_url = f"mirrorlist={cls._mirror_repo_url(config, 'CRB')}" + crb_url = f"mirrorlist={cls._mirror_repo_url('CRB')}" powertools_url = None else: crb_url = None - powertools_url = f"mirrorlist={cls._mirror_repo_url(config, 'PowerTools')}" - epel_url = f"mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-{epel_release}&arch=$basearch" + powertools_url = f"mirrorlist={cls._mirror_repo_url('PowerTools')}" + epel_url = "mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-$releasever&arch=$basearch" repos = [Repo("appstream", appstream_url, gpgpath, gpgurl)] if baseos_url is not None: @@ -172,23 +172,21 @@ class CentosInstaller(DistributionInstaller): # Repos for CentOS Stream 9 and later gpgpath, gpgurl = cls._gpg_locations(epel_release) - epel_gpgpath, epel_gpgurl = cls._epel_gpg_locations(epel_release) - - release = f"{epel_release}-stream" + epel_gpgpath, epel_gpgurl = cls._epel_gpg_locations() if config.local_mirror: appstream_url = f"baseurl={config.local_mirror}" baseos_url = crb_url = epel_url = None elif config.mirror: - appstream_url = f"baseurl={config.mirror}/centos-stream/{release}/AppStream/$basearch/os" - baseos_url = f"baseurl={config.mirror}/centos-stream/{release}/BaseOS/$basearch/os" - crb_url = f"baseurl={config.mirror}/centos-stream/{release}/CRB/$basearch/os" - epel_url = f"baseurl={config.mirror}/epel/{epel_release}/Everything/$basearch" + appstream_url = f"baseurl={config.mirror}/centos-stream/$stream/AppStream/$basearch/os" + baseos_url = f"baseurl={config.mirror}/centos-stream/$stream/BaseOS/$basearch/os" + crb_url = f"baseurl={config.mirror}/centos-stream/$stream/CRB/$basearch/os" + epel_url = f"baseurl={config.mirror}/epel/$stream/Everything/$basearch" else: - appstream_url = f"metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-{release}&arch=$basearch" - baseos_url = f"metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-{release}&arch=$basearch" - crb_url = f"metalink=https://mirrors.centos.org/metalink?repo=centos-crb-{release}&arch=$basearch" - epel_url = f"mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-{epel_release}&arch=$basearch" + appstream_url = "metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-$stream&arch=$basearch&protocol=https,http" + baseos_url = "metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-$stream&arch=$basearch&protocol=https,http" + crb_url = "metalink=https://mirrors.centos.org/metalink?repo=centos-crb-$stream&arch=$basearch&protocol=https,http" + epel_url = "mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-$releasever&arch=$basearch&protocol=https,http" repos = [Repo("appstream", appstream_url, gpgpath, gpgurl)] if baseos_url is not None: diff --git a/mkosi/distributions/fedora.py b/mkosi/distributions/fedora.py index 32049d14e..999348d91 100644 --- a/mkosi/distributions/fedora.py +++ b/mkosi/distributions/fedora.py @@ -197,7 +197,7 @@ def invoke_dnf(state: MkosiState, command: str, packages: Iterable[str]) -> None if state.config.distribution == Distribution.fedora: release, _ = parse_fedora_release(state.config.release) else: - release = state.config.release + release = state.config.release.strip("-stream") config_file = state.workspace / "dnf.conf" diff --git a/mkosi/distributions/rocky.py b/mkosi/distributions/rocky.py index b62b672b2..fba7c4700 100644 --- a/mkosi/distributions/rocky.py +++ b/mkosi/distributions/rocky.py @@ -2,14 +2,13 @@ from pathlib import Path -from mkosi.backend import MkosiConfig from mkosi.distributions.centos import CentosInstaller class RockyInstaller(CentosInstaller): @staticmethod def _gpg_locations(epel_release: int) -> tuple[Path, str]: - keyname = f"Rocky-{epel_release}" if epel_release >= 9 else "rockyofficial" + keyname = "Rocky-$releasever" if epel_release >= 9 else "rockyofficial" return ( Path(f"/etc/pki/rpm-gpg/RPM-GPG-KEY-{keyname}"), f"https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-{keyname}" @@ -20,5 +19,5 @@ class RockyInstaller(CentosInstaller): return "rocky" @classmethod - def _mirror_repo_url(cls, config: MkosiConfig, repo: str) -> str: - return f"https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo={repo}-{config.release}" + def _mirror_repo_url(cls, repo: str) -> str: + return f"https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo={repo}-$releasever" -- 2.47.2