# SPDX-License-Identifier: LGPL-2.1+
-import logging
import os
import shutil
from collections.abc import Iterable, Mapping, Sequence
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):
@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
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:
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
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)
"--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}",
# 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:
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))