# SPDX-License-Identifier: LGPL-2.1+
-from pathlib import Path
-
from mkosi.distributions import centos
-from mkosi.installer.dnf import Repo
+from mkosi.installer.dnf import Repo, find_rpm_gpgkey
from mkosi.state import MkosiState
@staticmethod
def gpgurls(state: MkosiState) -> tuple[str, ...]:
- gpgpath = Path(f"/usr/share/distribution-gpg-keys/alma/RPM-GPG-KEY-AlmaLinux-{state.config.release}")
- if gpgpath.exists():
- return (f"file://{gpgpath}",)
- else:
- return ("https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-$releasever",)
+ return (
+ find_rpm_gpgkey(
+ state,
+ f"RPM-GPG-KEY-AlmaLinux-{state.config.release}",
+ f"https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-{state.config.release}",
+ ),
+ )
@classmethod
def repository_variants(cls, state: MkosiState, repo: str) -> list[Repo]:
from mkosi.architecture import Architecture
from mkosi.distributions import Distribution, DistributionInstaller, PackageType
-from mkosi.installer.dnf import Repo, invoke_dnf, setup_dnf
+from mkosi.installer.dnf import Repo, find_rpm_gpgkey, invoke_dnf, setup_dnf
from mkosi.log import complete_step, die
from mkosi.state import MkosiState
from mkosi.tree import rmtree
@staticmethod
def gpgurls(state: MkosiState) -> tuple[str, ...]:
- gpgurls = []
-
- for key in ("CentOS-Official", "CentOS-SIG-Extras"):
- gpgpath = Path(f"/usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-{key}")
- if gpgpath.exists():
- gpgurls += [f"file://{gpgpath}"]
- else:
- gpgurls += [f"https://www.centos.org/keys/RPM-GPG-KEY-{key}"]
-
- return tuple(gpgurls)
+ keys = ("RPM-GPG-KEY-CentOS-Official", "RPM-GPG-KEY-CentOS-SIG-Extras")
+ return tuple(find_rpm_gpgkey(state, key, f"https://www.centos.org/keys/{key}") for key in keys)
@classmethod
def repository_variants(cls, state: MkosiState, repo: str) -> Iterable[Repo]:
@classmethod
def epel_repositories(cls, state: MkosiState) -> Iterable[Repo]:
- gpgpath = Path(f"/usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-EPEL-{state.config.release}")
- if gpgpath.exists():
- gpgurls = (f"file://{gpgpath}",)
- else:
- gpgurls = (f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{state.config.release}",)
+ gpgurls = (
+ find_rpm_gpgkey(
+ state,
+ f"RPM-GPG-KEY-EPEL-{state.config.release}",
+ f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{state.config.release}",
+ ),
+ )
if state.config.local_mirror:
return
(
"hyperscale",
(f"packages-{c}" for c in ("main", "experimental", "facebook", "hotfixes", "spin", "intel")),
- ("CentOS-SIG-HyperScale",),
+ ("RPM-GPG-KEY-CentOS-SIG-HyperScale",),
),
)
for sig, components, keys in sigs:
- gpgurls = []
- for key in keys:
- gpgpath = Path(f"/usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-{key}")
- if gpgpath.exists():
- gpgurls += [f"file://{gpgpath}"]
- else:
- gpgurls += [f"https://www.centos.org/keys/RPM-GPG-KEY-{key}"]
-
- gpgurls = tuple(gpgurls)
+ gpgurls = tuple(find_rpm_gpgkey(state, key, f"https://www.centos.org/keys/{key}") for key in keys)
for c in components:
if state.config.mirror:
import urllib.parse
from collections.abc import Sequence
-from pathlib import Path
from mkosi.architecture import Architecture
from mkosi.distributions import Distribution, DistributionInstaller, PackageType
-from mkosi.installer.dnf import Repo, invoke_dnf, setup_dnf
+from mkosi.installer.dnf import Repo, find_rpm_gpgkey, invoke_dnf, setup_dnf
from mkosi.log import die
from mkosi.state import MkosiState
@classmethod
def setup(cls, state: MkosiState) -> None:
- gpgpath = Path(f"/usr/share/distribution-gpg-keys/fedora/RPM-GPG-KEY-fedora-{state.config.release}-primary")
- if gpgpath.exists():
- gpgurls = (f"file://{gpgpath}",)
- else:
- # See: https://fedoraproject.org/security/
- gpgurls = ("https://fedoraproject.org/fedora.gpg",)
+ gpgurls = (
+ find_rpm_gpgkey(
+ state,
+ key=f"RPM-GPG-KEY-fedora-{state.config.release}-primary",
+ url="https://fedoraproject.org/fedora.gpg",
+ ),
+ )
+
repos = []
if state.config.local_mirror:
from typing import Any, Optional
from mkosi.distributions import centos
-from mkosi.installer.dnf import Repo
+from mkosi.installer.dnf import Repo, find_rpm_gpgkey
from mkosi.log import die
from mkosi.state import MkosiState
@staticmethod
def gpgurls(state: MkosiState) -> tuple[str, ...]:
- return ("https://access.redhat.com/security/data/fd431d51.txt",)
+ major = int(float(state.config.release))
+
+ return (
+ find_rpm_gpgkey(
+ state,
+ f"RPM-GPG-KEY-redhat{major}-release",
+ "https://access.redhat.com/security/data/fd431d51.txt",
+ ),
+ )
@staticmethod
def sslcacert(state: MkosiState) -> Optional[Path]:
from collections.abc import Iterable
from mkosi.distributions import centos
-from mkosi.installer.dnf import Repo
+from mkosi.installer.dnf import Repo, find_rpm_gpgkey
from mkosi.state import MkosiState
@staticmethod
def gpgurls(state: MkosiState) -> tuple[str, ...]:
- return ("https://access.redhat.com/security/data/fd431d51.txt",)
+ major = int(float(state.config.release))
+
+ return (
+ find_rpm_gpgkey(
+ state,
+ f"RPM-GPG-KEY-redhat{major}-release",
+ "https://access.redhat.com/security/data/fd431d51.txt",
+ ),
+ )
@classmethod
def repository_variants(cls, state: MkosiState, repo: str) -> Iterable[Repo]:
# SPDX-License-Identifier: LGPL-2.1+
-from pathlib import Path
-
from mkosi.distributions import centos
-from mkosi.installer.dnf import Repo
+from mkosi.installer.dnf import Repo, find_rpm_gpgkey
from mkosi.state import MkosiState
@staticmethod
def gpgurls(state: MkosiState) -> tuple[str, ...]:
- gpgpath = Path(f"/usr/share/distribution-gpg-keys/rocky/RPM-GPG-KEY-Rocky-{state.config.release}")
- if gpgpath.exists():
- return (f"file://{gpgpath}",)
- else:
- return ("https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-$releasever",)
+ return (
+ find_rpm_gpgkey(
+ state,
+ f"RPM-GPG-KEY-Rocky-{state.config.release}",
+ f"https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-{state.config.release}",
+ ),
+ )
@classmethod
def repository_variants(cls, state: MkosiState, repo: str) -> list[Repo]:
sslclientcert: Optional[Path] = None
+def find_rpm_gpgkey(state: MkosiState, key: str, url: str) -> str:
+ for gpgdir in ("usr/share/distribution-gpg-keys", "etc/pki/rpm-gpg"):
+ for root in (state.pkgmngr, state.root, Path("/")):
+ gpgpath = next((root / Path(gpgdir)).rglob(key), None)
+ if gpgpath:
+ return f"file://{gpgpath}"
+
+ return url
+
+
def dnf_executable(state: MkosiState) -> str:
# dnf5 does not support building for foreign architectures yet (missing --forcearch)
dnf = shutil.which("dnf5") if state.config.architecture.is_native() else None