def mount_cache(state: MkosiState) -> Iterator[None]:
if state.installer is not None:
cache_paths = state.installer.cache_path()
- elif is_centos_variant(state.config.distribution):
- # We mount both the YUM and the DNF cache in this case, as YUM might
- # just be redirected to DNF even if we invoke the former
- cache_paths = ["var/cache/yum", "var/cache/dnf"]
else:
cache_paths = []
)
-
-
-def centos_variant_gpg_locations(distribution: Distribution, epel_release: int) -> Tuple[Path, str]:
- if distribution in (Distribution.centos, Distribution.centos_epel):
- return (
- Path("/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial"),
- "https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official"
- )
- elif distribution in (Distribution.alma, Distribution.alma_epel):
- return (
- Path("/etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux"),
- "https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux"
- )
- elif distribution in (Distribution.rocky, Distribution.rocky_epel):
- if epel_release >= 9:
- keyname = f"Rocky-{epel_release}"
- else:
- keyname = "rockyofficial"
-
- return (
- Path(f"/etc/pki/rpm-gpg/RPM-GPG-KEY-{keyname}"),
- f"https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-{keyname}"
- )
- else:
- die(f"{distribution} is not a CentOS variant")
-
-
-def epel_gpg_locations(epel_release: int) -> 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}",
- )
-
-
-def centos_variant_mirror_directory(distribution: Distribution) -> str:
- if distribution in (Distribution.centos, Distribution.centos_epel):
- return "centos"
- elif distribution in (Distribution.alma, Distribution.alma_epel):
- return "almalinux"
- elif distribution in (Distribution.rocky, Distribution.rocky_epel):
- return "rocky"
- else:
- die(f"{distribution} is not a CentOS variant")
-
-
-def centos_variant_mirror_repo_url(config: MkosiConfig, repo: str) -> str:
- if config.distribution in (Distribution.centos, Distribution.centos_epel):
- return f"http://mirrorlist.centos.org/?release={config.release}&arch=$basearch&repo={repo}"
- elif config.distribution in (Distribution.alma, Distribution.alma_epel):
- return f"https://mirrors.almalinux.org/mirrorlist/{config.release}/{repo.lower()}"
- elif config.distribution in (Distribution.rocky, Distribution.rocky_epel):
- return f"https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo={repo}-{config.release}"
- else:
- die(f"{config.distribution} is not a CentOS variant")
-
-
-def centos_variant_repos(config: MkosiConfig, epel_release: int) -> List[Repo]:
- # Repos for CentOS Linux 8, CentOS Stream 8 and CentOS variants
-
- directory = centos_variant_mirror_directory(config.distribution)
- gpgpath, gpgurl = centos_variant_gpg_locations(config.distribution, epel_release)
- epel_gpgpath, epel_gpgurl = epel_gpg_locations(epel_release)
-
- if config.local_mirror:
- appstream_url = f"baseurl={config.local_mirror}"
- baseos_url = extras_url = powertools_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"
- powertools_url = f"baseurl={config.mirror}/{directory}/{config.release}/PowerTools/$basearch/os"
- epel_url = f"baseurl={config.mirror}/epel/{epel_release}/Everything/$basearch"
- else:
- appstream_url = f"mirrorlist={centos_variant_mirror_repo_url(config, 'AppStream')}"
- baseos_url = f"mirrorlist={centos_variant_mirror_repo_url(config, 'BaseOS')}"
- extras_url = f"mirrorlist={centos_variant_mirror_repo_url(config, 'extras')}"
- powertools_url = f"mirrorlist={centos_variant_mirror_repo_url(config, 'PowerTools')}"
- epel_url = f"mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-{epel_release}&arch=$basearch"
-
- repos = [Repo("AppStream", appstream_url, gpgpath, gpgurl)]
- if baseos_url is not None:
- repos += [Repo("BaseOS", baseos_url, gpgpath, gpgurl)]
- if extras_url is not None:
- repos += [Repo("extras", extras_url, gpgpath, gpgurl)]
- if powertools_url is not None:
- repos += [Repo("PowerTools", powertools_url, gpgpath, gpgurl)]
- if epel_url is not None and is_epel_variant(config.distribution):
- repos += [Repo("epel", epel_url, epel_gpgpath, epel_gpgurl)]
-
- return repos
-
-
-def centos_stream_repos(config: MkosiConfig, epel_release: int) -> List[Repo]:
- # Repos for CentOS Stream 9 and later
-
- gpgpath, gpgurl = centos_variant_gpg_locations(config.distribution, epel_release)
- epel_gpgpath, epel_gpgurl = epel_gpg_locations(epel_release)
-
- release = f"{epel_release}-stream"
-
- 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"
- 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"
-
- repos = [Repo("AppStream", appstream_url, gpgpath, gpgurl)]
- if baseos_url is not None:
- repos += [Repo("BaseOS", baseos_url, gpgpath, gpgurl)]
- if crb_url is not None:
- repos += [Repo("CRB", crb_url, gpgpath, gpgurl)]
- if epel_url is not None and is_epel_variant(config.distribution):
- repos += [Repo("epel", epel_url, epel_gpgpath, epel_gpgurl)]
-
- return repos
-
-
def parse_epel_release(release: str) -> int:
fields = release.split(".")
if fields[0].endswith("-stream"):
return int(epel_release)
-@complete_step("Installing CentOS…")
-def install_centos_variant(state: MkosiState) -> None:
- epel_release = parse_epel_release(state.config.release)
-
- if epel_release <= 7:
- die("CentOS 7 or earlier variants are not supported")
- elif epel_release <= 8 or not "-stream" in state.config.release:
- repos = centos_variant_repos(state.config, epel_release)
- else:
- repos = centos_stream_repos(state.config, epel_release)
-
- setup_dnf(state, repos)
-
- if "-stream" in state.config.release:
- state.workspace.joinpath("vars/stream").write_text(state.config.release)
-
- packages = {*state.config.packages}
- add_packages(state.config, packages, "systemd", "dnf")
- if not state.do_run_build_script and state.config.bootable:
- add_packages(state.config, packages, "kernel", "dracut")
- add_packages(state.config, packages, "systemd-udev", conditional="systemd")
-
- if state.do_run_build_script:
- packages.update(state.config.build_packages)
-
- if state.do_run_build_script:
- packages.update(state.config.build_packages)
-
- if not state.do_run_build_script and is_epel_variant(state.config.distribution):
- if state.config.netdev:
- add_packages(state.config, packages, "systemd-networkd", conditional="systemd")
- if epel_release >= 9:
- add_packages(state.config, packages, "systemd-boot", conditional="systemd")
-
- install_packages_dnf(state, packages)
-
- # Centos Stream 8 and below can't write to the sqlite db backend used by
- # default in newer RPM releases so let's rebuild the DB to use the old bdb
- # backend instead. Because newer RPM releases have dropped support for the
- # bdb backend completely, we check if rpm is installed and use
- # run_workspace_command() to rebuild the rpm db.
- if epel_release <= 8 and state.root.joinpath("usr/bin/rpm").exists():
- cmdline = ["rpm", "--rebuilddb", "--define", "_db_backend bdb"]
- run_workspace_command(state, cmdline)
-
-
def install_distribution(state: MkosiState, cached: bool) -> None:
if cached:
return
if state.installer is not None:
install = state.installer.install
- elif is_centos_variant(state.config.distribution):
- install = install_centos_variant
else:
die("No Installer")
if state.installer is not None:
remove = lambda p: state.installer.remove_packages(state, p) # type: ignore
- elif (state.config.distribution.package_type == PackageType.rpm):
- remove = lambda p: invoke_dnf(state, 'remove', p)
else:
die(f"Removing packages is not supported for {state.config.distribution}")
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1+
+
+from mkosi.distributions.centos import CentosInstaller
+
+
+class AlmaInstaller(CentosInstaller):
+ pass
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1+
+
+from mkosi.distributions.alma import AlmaInstaller
+
+
+class AlmaEpelInstaller(AlmaInstaller):
+ pass
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1+
+
+from pathlib import Path
+from typing import List, Tuple
+
+from mkosi.backend import (
+ Distribution,
+ MkosiConfig,
+ MkosiState,
+ add_packages,
+ complete_step,
+ die,
+ is_epel_variant,
+ run_workspace_command,
+)
+from mkosi.distributions import DistributionInstaller
+from mkosi.distributions.fedora import Repo, install_packages_dnf, invoke_dnf, setup_dnf
+
+
+class CentosInstaller(DistributionInstaller):
+ @classmethod
+ def cache_path(cls) -> List[str]:
+ return ["var/cache/yum", "var/cache/dnf"]
+
+ @classmethod
+ def install(cls, state: "MkosiState") -> None:
+ return install_centos_variant(state)
+
+ @classmethod
+ def remove_packages(cls, state: MkosiState, remove: List[str]) -> None:
+ invoke_dnf(state, 'remove', remove)
+
+
+def centos_variant_gpg_locations(distribution: Distribution, epel_release: int) -> Tuple[Path, str]:
+ if distribution in (Distribution.centos, Distribution.centos_epel):
+ return (
+ Path("/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial"),
+ "https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official"
+ )
+ elif distribution in (Distribution.alma, Distribution.alma_epel):
+ return (
+ Path("/etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux"),
+ "https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux"
+ )
+ elif distribution in (Distribution.rocky, Distribution.rocky_epel):
+ if epel_release >= 9:
+ keyname = f"Rocky-{epel_release}"
+ else:
+ keyname = "rockyofficial"
+
+ return (
+ Path(f"/etc/pki/rpm-gpg/RPM-GPG-KEY-{keyname}"),
+ f"https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-{keyname}"
+ )
+ else:
+ die(f"{distribution} is not a CentOS variant")
+
+
+def epel_gpg_locations(epel_release: int) -> 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}",
+ )
+
+
+def centos_variant_mirror_directory(distribution: Distribution) -> str:
+ if distribution in (Distribution.centos, Distribution.centos_epel):
+ return "centos"
+ elif distribution in (Distribution.alma, Distribution.alma_epel):
+ return "almalinux"
+ elif distribution in (Distribution.rocky, Distribution.rocky_epel):
+ return "rocky"
+ else:
+ die(f"{distribution} is not a CentOS variant")
+
+
+def centos_variant_mirror_repo_url(config: MkosiConfig, repo: str) -> str:
+ if config.distribution in (Distribution.centos, Distribution.centos_epel):
+ return f"http://mirrorlist.centos.org/?release={config.release}&arch=$basearch&repo={repo}"
+ elif config.distribution in (Distribution.alma, Distribution.alma_epel):
+ return f"https://mirrors.almalinux.org/mirrorlist/{config.release}/{repo.lower()}"
+ elif config.distribution in (Distribution.rocky, Distribution.rocky_epel):
+ return f"https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo={repo}-{config.release}"
+ else:
+ die(f"{config.distribution} is not a CentOS variant")
+
+
+def centos_variant_repos(config: MkosiConfig, epel_release: int) -> List[Repo]:
+ # Repos for CentOS Linux 8, CentOS Stream 8 and CentOS variants
+
+ directory = centos_variant_mirror_directory(config.distribution)
+ gpgpath, gpgurl = centos_variant_gpg_locations(config.distribution, epel_release)
+ epel_gpgpath, epel_gpgurl = epel_gpg_locations(epel_release)
+
+ if config.local_mirror:
+ appstream_url = f"baseurl={config.local_mirror}"
+ baseos_url = extras_url = powertools_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"
+ powertools_url = f"baseurl={config.mirror}/{directory}/{config.release}/PowerTools/$basearch/os"
+ epel_url = f"baseurl={config.mirror}/epel/{epel_release}/Everything/$basearch"
+ else:
+ appstream_url = f"mirrorlist={centos_variant_mirror_repo_url(config, 'AppStream')}"
+ baseos_url = f"mirrorlist={centos_variant_mirror_repo_url(config, 'BaseOS')}"
+ extras_url = f"mirrorlist={centos_variant_mirror_repo_url(config, 'extras')}"
+ powertools_url = f"mirrorlist={centos_variant_mirror_repo_url(config, 'PowerTools')}"
+ epel_url = f"mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-{epel_release}&arch=$basearch"
+
+ repos = [Repo("AppStream", appstream_url, gpgpath, gpgurl)]
+ if baseos_url is not None:
+ repos += [Repo("BaseOS", baseos_url, gpgpath, gpgurl)]
+ if extras_url is not None:
+ repos += [Repo("extras", extras_url, gpgpath, gpgurl)]
+ if powertools_url is not None:
+ repos += [Repo("PowerTools", powertools_url, gpgpath, gpgurl)]
+ if epel_url is not None and is_epel_variant(config.distribution):
+ repos += [Repo("epel", epel_url, epel_gpgpath, epel_gpgurl)]
+
+ return repos
+
+
+def centos_stream_repos(config: MkosiConfig, epel_release: int) -> List[Repo]:
+ # Repos for CentOS Stream 9 and later
+
+ gpgpath, gpgurl = centos_variant_gpg_locations(config.distribution, epel_release)
+ epel_gpgpath, epel_gpgurl = epel_gpg_locations(epel_release)
+
+ release = f"{epel_release}-stream"
+
+ 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"
+ 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"
+
+ repos = [Repo("AppStream", appstream_url, gpgpath, gpgurl)]
+ if baseos_url is not None:
+ repos += [Repo("BaseOS", baseos_url, gpgpath, gpgurl)]
+ if crb_url is not None:
+ repos += [Repo("CRB", crb_url, gpgpath, gpgurl)]
+ if epel_url is not None and is_epel_variant(config.distribution):
+ repos += [Repo("epel", epel_url, epel_gpgpath, epel_gpgurl)]
+
+ return repos
+
+
+def parse_epel_release(release: str) -> int:
+ fields = release.split(".")
+ if fields[0].endswith("-stream"):
+ epel_release = fields[0].split("-")[0]
+ else:
+ epel_release = fields[0]
+
+ return int(epel_release)
+
+
+@complete_step("Installing CentOS…")
+def install_centos_variant(state: MkosiState) -> None:
+ epel_release = parse_epel_release(state.config.release)
+
+ if epel_release <= 7:
+ die("CentOS 7 or earlier variants are not supported")
+ elif epel_release <= 8 or not "-stream" in state.config.release:
+ repos = centos_variant_repos(state.config, epel_release)
+ else:
+ repos = centos_stream_repos(state.config, epel_release)
+
+ setup_dnf(state, repos)
+
+ if "-stream" in state.config.release:
+ state.workspace.joinpath("vars/stream").write_text(state.config.release)
+
+ packages = {*state.config.packages}
+ add_packages(state.config, packages, "systemd", "dnf")
+ if not state.do_run_build_script and state.config.bootable:
+ add_packages(state.config, packages, "kernel", "dracut")
+ add_packages(state.config, packages, "systemd-udev", conditional="systemd")
+
+ if state.do_run_build_script:
+ packages.update(state.config.build_packages)
+
+ if state.do_run_build_script:
+ packages.update(state.config.build_packages)
+
+ if not state.do_run_build_script and is_epel_variant(state.config.distribution):
+ if state.config.netdev:
+ add_packages(state.config, packages, "systemd-networkd", conditional="systemd")
+ if epel_release >= 9:
+ add_packages(state.config, packages, "systemd-boot", conditional="systemd")
+
+ install_packages_dnf(state, packages)
+
+ # Centos Stream 8 and below can't write to the sqlite db backend used by
+ # default in newer RPM releases so let's rebuild the DB to use the old bdb
+ # backend instead. Because newer RPM releases have dropped support for the
+ # bdb backend completely, we check if rpm is installed and use
+ # run_workspace_command() to rebuild the rpm db.
+ if epel_release <= 8 and state.root.joinpath("usr/bin/rpm").exists():
+ cmdline = ["rpm", "--rebuilddb", "--define", "_db_backend bdb"]
+ run_workspace_command(state, cmdline)
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1+
+
+from mkosi.distributions.centos import CentosInstaller
+
+
+class CentosEpelInstaller(CentosInstaller):
+ pass
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1+
+
+from mkosi.distributions.centos import CentosInstaller
+
+
+class RockyInstaller(CentosInstaller):
+ pass
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1+
+
+from mkosi.distributions.rocky import RockyInstaller
+
+
+class RockyEpelInstaller(RockyInstaller):
+ pass