forked from Mirror/pmbootstrap
repo_bootstrap: simplify custom mirrors (MR 2252)
We now have support for having mirrors per-aports repo, drop the mirrors_postmarketos arg from chroot.init and instead have repo_bootstrap call apk.update_repository_list() explicitly to exclude the mirrors for the repository we're going to update. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
807424ee2b
commit
15ffc2f370
4 changed files with 16 additions and 14 deletions
|
@ -24,14 +24,14 @@ from pmb.core import Chroot, get_context
|
|||
from pmb.types import PathString
|
||||
|
||||
|
||||
@Cache("chroot")
|
||||
def update_repository_list(chroot: Chroot, postmarketos_mirror=True,
|
||||
@Cache("chroot", mirrors_exclude=[])
|
||||
def update_repository_list(chroot: Chroot, mirrors_exclude: List[str]=[],
|
||||
check=False):
|
||||
"""
|
||||
Update /etc/apk/repositories, if it is outdated (when the user changed the
|
||||
--mirror-alpine or --mirror-pmOS parameters).
|
||||
|
||||
:param postmarketos_mirror: add postmarketos mirror URLs
|
||||
:param mirrors_exclude: mirrors to exclude from the repository list
|
||||
:param check: This function calls it self after updating the
|
||||
/etc/apk/repositories file, to check if it was successful.
|
||||
Only for this purpose, the "check" parameter should be set to
|
||||
|
@ -50,8 +50,7 @@ def update_repository_list(chroot: Chroot, postmarketos_mirror=True,
|
|||
pmb.helpers.run.root(["mkdir", "-p", path.parent])
|
||||
|
||||
# Up to date: Save cache, return
|
||||
exclude = ["pmaports"] if not postmarketos_mirror else []
|
||||
lines_new = pmb.helpers.repo.urls(mirrors_exclude=exclude)
|
||||
lines_new = pmb.helpers.repo.urls(mirrors_exclude=mirrors_exclude)
|
||||
if lines_old == lines_new:
|
||||
return
|
||||
|
||||
|
@ -66,7 +65,7 @@ def update_repository_list(chroot: Chroot, postmarketos_mirror=True,
|
|||
for line in lines_new:
|
||||
pmb.helpers.run.root(["sh", "-c", "echo "
|
||||
f"{shlex.quote(line)} >> {path}"])
|
||||
update_repository_list(chroot, postmarketos_mirror, True)
|
||||
update_repository_list(chroot, mirrors_exclude, True)
|
||||
|
||||
|
||||
@Cache("chroot")
|
||||
|
|
|
@ -9,6 +9,7 @@ import os
|
|||
|
||||
import pmb.chroot
|
||||
import pmb.chroot.binfmt
|
||||
import pmb.chroot.apk
|
||||
import pmb.chroot.apk_static
|
||||
import pmb.config
|
||||
import pmb.config.workdir
|
||||
|
@ -97,8 +98,7 @@ def warn_if_chroot_is_outdated(chroot: Chroot):
|
|||
|
||||
|
||||
@Cache("chroot")
|
||||
def init(chroot: Chroot, usr_merge=UsrMerge.AUTO,
|
||||
postmarketos_mirror=True):
|
||||
def init(chroot: Chroot, usr_merge=UsrMerge.AUTO):
|
||||
"""
|
||||
Initialize a chroot by copying the resolv.conf and updating
|
||||
/etc/apk/repositories. If /bin/sh is missing, create the chroot from
|
||||
|
@ -107,7 +107,6 @@ def init(chroot: Chroot, usr_merge=UsrMerge.AUTO,
|
|||
:param usr_merge: set to ON to force having a merged /usr. With AUTO it is
|
||||
only done if the user chose to install systemd in
|
||||
pmbootstrap init.
|
||||
:param postmarketos_mirror: add postmarketos mirror URLs
|
||||
"""
|
||||
# When already initialized: just prepare the chroot
|
||||
arch = chroot.arch
|
||||
|
@ -119,14 +118,14 @@ def init(chroot: Chroot, usr_merge=UsrMerge.AUTO,
|
|||
if (chroot / "bin/sh").is_symlink():
|
||||
pmb.config.workdir.chroot_check_channel(chroot)
|
||||
copy_resolv_conf(chroot)
|
||||
pmb.chroot.apk.update_repository_list(chroot, postmarketos_mirror)
|
||||
pmb.chroot.apk.update_repository_list(chroot)
|
||||
warn_if_chroot_is_outdated(chroot)
|
||||
return
|
||||
|
||||
# Require apk-tools-static
|
||||
pmb.chroot.apk_static.init()
|
||||
|
||||
logging.info(f"({chroot}) install alpine-base")
|
||||
logging.info(f"({chroot}) Creating chroot")
|
||||
|
||||
# Initialize cache
|
||||
apk_cache = config.work / f"cache_apk_{arch}"
|
||||
|
@ -136,7 +135,7 @@ def init(chroot: Chroot, usr_merge=UsrMerge.AUTO,
|
|||
# Initialize /etc/apk/keys/, resolv.conf, repositories
|
||||
init_keys()
|
||||
copy_resolv_conf(chroot)
|
||||
pmb.chroot.apk.update_repository_list(chroot, postmarketos_mirror)
|
||||
pmb.chroot.apk.update_repository_list(chroot)
|
||||
|
||||
pmb.config.workdir.chroot_save_init(chroot)
|
||||
|
||||
|
|
|
@ -79,6 +79,8 @@ def zap(confirm=True, dry=False, pkgs_local=False, http=False,
|
|||
|
||||
# Chroots were zapped, so no repo lists exist anymore
|
||||
Cache.clear_cache(pmb.chroot.apk.update_repository_list)
|
||||
# Let chroot.init be called again
|
||||
Cache.clear_cache(pmb.chroot.init)
|
||||
|
||||
# Print amount of cleaned up space
|
||||
if dry:
|
||||
|
|
|
@ -10,8 +10,9 @@ import glob
|
|||
import pmb.config.pmaports
|
||||
import pmb.helpers.repo
|
||||
import pmb.build
|
||||
import pmb.chroot
|
||||
import pmb.chroot.apk
|
||||
from pmb.build import BuildQueueItem
|
||||
from pmb.core import Config
|
||||
from pmb.core import get_context
|
||||
|
||||
from pmb import commands
|
||||
|
@ -111,7 +112,8 @@ class RepoBootstrap(commands.Command):
|
|||
|
||||
self.log_progress(f"initializing {chroot} chroot (merge /usr: {usr_merge.name})")
|
||||
# Initialize without pmOS binary package repo
|
||||
pmb.chroot.init(chroot, usr_merge, postmarketos_mirror=False)
|
||||
pmb.chroot.apk.update_repository_list(chroot, mirrors_exclude=[self.repo])
|
||||
pmb.chroot.init(chroot, usr_merge)
|
||||
|
||||
bootstrap_stage = int(step.split("bootstrap_", 1)[1])
|
||||
def log_wrapper(pkg: BuildQueueItem):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue