]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
fedora: Remove distribution specific checks
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 21 Jul 2023 07:33:30 +0000 (09:33 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 21 Jul 2023 07:33:30 +0000 (09:33 +0200)
This also drops support for specifying rawhide-f37, etc.

mkosi/distributions/fedora.py

index 9dab7e6905a30f2504d3c4f898a15b86b8555ba8..39c49d534fb7d5bb70ed3bee096379610f0d92f4 100644 (file)
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
-import logging
 import os
 import shutil
 from collections.abc import Iterable, Mapping, Sequence
@@ -14,7 +13,7 @@ from mkosi.log import die
 from mkosi.remove import unlink_try_hard
 from mkosi.run import bwrap
 from mkosi.state import MkosiState
-from mkosi.util import Distribution, detect_distribution, sort_packages
+from mkosi.util import sort_packages
 
 
 class FedoraInstaller(DistributionInstaller):
@@ -28,29 +27,28 @@ class FedoraInstaller(DistributionInstaller):
 
     @classmethod
     def install_packages(cls, state: MkosiState, packages: Sequence[str], apivfs: bool = True) -> None:
-        release = parse_fedora_release(state.config.release)
         release_url = updates_url = appstream_url = baseos_url = extras_url = crb_url = None
 
         if state.config.local_mirror:
             release_url = f"baseurl={state.config.local_mirror}"
-        elif release == "eln":
+        elif state.config.release == "eln":
             assert state.config.mirror
             appstream_url = f"baseurl={state.config.mirror}/AppStream/$basearch/os"
             baseos_url = f"baseurl={state.config.mirror}/BaseOS/$basearch/os"
             extras_url = f"baseurl={state.config.mirror}/Extras/$basearch/os"
             crb_url = f"baseurl={state.config.mirror}/CRB/$basearch/os"
         elif state.config.mirror:
-            directory = "development" if release == "rawhide" else "releases"
+            directory = "development" if state.config.release == "rawhide" else "releases"
             release_url = f"baseurl={state.config.mirror}/{directory}/$releasever/Everything/$basearch/os/"
             updates_url = f"baseurl={state.config.mirror}/updates/$releasever/Everything/$basearch/"
         else:
-            release_url = f"metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-{release}&arch=$basearch"
+            release_url = f"metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-{state.config.release}&arch=$basearch"
             updates_url = (
                 "metalink=https://mirrors.fedoraproject.org/metalink?"
-                f"repo=updates-released-f{release}&arch=$basearch"
+                f"repo=updates-released-f{state.config.release}&arch=$basearch"
             )
 
-        if release == "rawhide":
+        if state.config.release == "rawhide":
             # On rawhide, the "updates" repo is the same as the "fedora" repo.
             # In other versions, the "fedora" repo is frozen at release, and "updates" provides any new packages.
             updates_url = None
@@ -69,7 +67,8 @@ class FedoraInstaller(DistributionInstaller):
                 repos += [Repo(name, url, [gpgurl])]
 
         setup_dnf(state, repos)
-        invoke_dnf(state, "install", packages, apivfs=apivfs)
+        invoke_dnf(state, "install", packages, apivfs=apivfs,
+                   filelists=fedora_release_at_least(state.config.release, "38"))
 
     @classmethod
     def remove_packages(cls, state: MkosiState, packages: Sequence[str]) -> None:
@@ -95,15 +94,6 @@ class FedoraInstaller(DistributionInstaller):
         return a
 
 
-def parse_fedora_release(release: str) -> str:
-    # The release can be specified as 'rawhide-<version>'. We don't make use
-    # of the second part right now, but we allow it for compatibility.
-    if release.startswith("rawhide-"):
-        release, releasever = release.split("-")
-        logging.info(f"Fedora rawhide — release version: {releasever}")
-    return release
-
-
 def fedora_release_at_least(release: str, threshold: str) -> bool:
     if release in ("rawhide", "eln"):
         return True
@@ -161,13 +151,9 @@ def invoke_dnf(
     command: str,
     packages: Iterable[str],
     env: Mapping[str, Any] = {},
+    filelists: bool = True,
     apivfs: bool = True
 ) -> None:
-    if state.config.distribution == Distribution.fedora:
-        release = parse_fedora_release(state.config.release)
-    else:
-        release = state.config.release
-
     state.pkgmngr.joinpath("etc/dnf/vars").mkdir(exist_ok=True, parents=True)
     state.pkgmngr.joinpath("etc/yum.repos.d").mkdir(exist_ok=True, parents=True)
     state.pkgmngr.joinpath("var/lib/dnf").mkdir(exist_ok=True, parents=True)
@@ -181,7 +167,7 @@ def invoke_dnf(
         "--assumeyes",
         f"--config={state.pkgmngr / 'etc/dnf/dnf.conf'}",
         "--best",
-        f"--releasever={release}",
+        f"--releasever={state.config.release}",
         f"--installroot={state.root}",
         "--setopt=keepcache=1",
         f"--setopt=cachedir={state.cache_dir}",
@@ -194,9 +180,7 @@ def invoke_dnf(
 
     # Make sure we download filelists so all dependencies can be resolved.
     # See https://bugzilla.redhat.com/show_bug.cgi?id=2180842
-    if (dnf.endswith("dnf5") and
-        not (state.config.distribution == Distribution.fedora
-             and fedora_release_at_least(release, '38'))):
+    if dnf.endswith("dnf5") and filelists:
         cmdline += ["--setopt=optional_metadata_types=filelists"]
 
     if not state.config.repository_key_check:
@@ -232,20 +216,17 @@ def invoke_dnf(
 
 
 def fixup_rpmdb_location(root: Path) -> None:
-    distribution, _ = detect_distribution()
-    if distribution not in (Distribution.debian, Distribution.ubuntu):
-        return
-
     # On Debian, rpm/dnf ship with a patch to store the rpmdb under ~/ so it needs to be copied back in the
     # right location, otherwise the rpmdb will be broken. See: https://bugs.debian.org/1004863. We also
     # replace it with a symlink so that any further rpm operations immediately use the correct location.
-
     rpmdb_home = root / "root/.rpmdb"
-    if rpmdb_home.exists() and not rpmdb_home.is_symlink():
-        # Take into account the new location in F36
-        rpmdb = root / "usr/lib/sysimage/rpm"
-        if not rpmdb.exists():
-            rpmdb = root / "var/lib/rpm"
-        unlink_try_hard(rpmdb)
-        shutil.move(rpmdb_home, rpmdb)
-        rpmdb_home.symlink_to(os.path.relpath(rpmdb, start=rpmdb_home.parent))
+    if not rpmdb_home.exists() or rpmdb_home.is_symlink():
+        return
+
+    # Take into account the new location in F36
+    rpmdb = root / "usr/lib/sysimage/rpm"
+    if not rpmdb.exists():
+        rpmdb = root / "var/lib/rpm"
+    unlink_try_hard(rpmdb)
+    shutil.move(rpmdb_home, rpmdb)
+    rpmdb_home.symlink_to(os.path.relpath(rpmdb, start=rpmdb_home.parent))