]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
centos: Modernize repo URLs 1308/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 16 Jan 2023 12:45:55 +0000 (13:45 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 16 Jan 2023 15:09:58 +0000 (16:09 +0100)
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
mkosi/distributions/centos.py
mkosi/distributions/fedora.py
mkosi/distributions/rocky.py

index 59c39af1d721d6ef73e3d7f61a9a0b04bd45e007..4c54de8951850a93e90c13c64115fddb930a901a 100644 (file)
@@ -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()}"
index 0c1928ceefd3ece73edd79d9f59ce4473975744b..f55e8612219dae89adab7e6367567500a4e11980 100644 (file)
@@ -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:
index 32049d14ea845f7d2d29494421b3b271d1bb617f..999348d91ed7ddafddd2ee67cf0b4081728c2f4c 100644 (file)
@@ -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"
 
index b62b672b25112c5dbca7f0a27dc28539f4b2d772..fba7c4700637c4d28059cde671a8cf6fea8dcad8 100644 (file)
@@ -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"