Properly update /etc/apk/repositories when the mirrors change
This is important for the binary repository scripts, so it's feasible to test the binary package build and challenge process locally without setting up a new chroot whenever changing the repo URLs. Also it behaves a bit more intuitively, because it really uses the repo URL specified on the commandline, even when the chroot is already set up.
This commit is contained in:
parent
34622368d9
commit
4f4588405f
|
@ -18,6 +18,8 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
import os
|
||||
import logging
|
||||
import shlex
|
||||
|
||||
import pmb.chroot
|
||||
import pmb.config
|
||||
import pmb.parse.apkindex
|
||||
|
@ -25,6 +27,53 @@ import pmb.parse.arch
|
|||
import pmb.parse.depends
|
||||
|
||||
|
||||
def update_repository_list(args, suffix="native", check=False):
|
||||
"""
|
||||
Update /etc/apk/repositories, if it is outdated (when the user changed the
|
||||
--mirror-alpine or --mirror-pmOS parameters).
|
||||
|
||||
: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
|
||||
True.
|
||||
"""
|
||||
# Skip if we already did this
|
||||
if suffix in args.cache["apk_repository_list_updated"]:
|
||||
return
|
||||
|
||||
# Read old entries or create folder structure
|
||||
path = args.work + "/chroot_" + suffix + "/etc/apk/repositories"
|
||||
lines_old = []
|
||||
if os.path.exists(path):
|
||||
# Read all old lines
|
||||
lines_old = []
|
||||
with open(path) as handle:
|
||||
for line in handle:
|
||||
lines_old.append(line[:-1])
|
||||
else:
|
||||
pmb.helpers.run.root(args, ["mkdir", "-p", os.path.dirname(path)],
|
||||
suffix)
|
||||
|
||||
# Up to date: Save cache, return
|
||||
lines_new = pmb.helpers.repo.urls(args)
|
||||
if lines_old == lines_new:
|
||||
args.cache["apk_repository_list_updated"].append(suffix)
|
||||
return
|
||||
|
||||
# Check phase: raise error when still outdated
|
||||
if check:
|
||||
raise RuntimeError("Failed to update: " + path)
|
||||
|
||||
# Update the file
|
||||
logging.debug("(" + suffix + ") update /etc/apk/repositories")
|
||||
if os.path.exists(path):
|
||||
pmb.helpers.run.root(args, ["rm", path])
|
||||
for line in lines_new:
|
||||
pmb.helpers.run.root(args, ["sh", "-c", "echo " +
|
||||
shlex.quote(line) + " >> " + path])
|
||||
update_repository_list(args, suffix, True)
|
||||
|
||||
|
||||
def check_min_version(args, suffix="native"):
|
||||
"""
|
||||
Check the minimum apk version, before running it the first time in the
|
||||
|
|
|
@ -18,7 +18,6 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
import logging
|
||||
import os
|
||||
import shlex
|
||||
import glob
|
||||
import filecmp
|
||||
|
||||
|
@ -51,6 +50,7 @@ def init(args, suffix="native"):
|
|||
if suffix != "native":
|
||||
pmb.chroot.binfmt.register(args, arch)
|
||||
copy_resolv_conf(args, suffix)
|
||||
pmb.chroot.apk.update_repository_list(args, suffix)
|
||||
return
|
||||
|
||||
# Require apk-tools-static
|
||||
|
@ -69,19 +69,13 @@ def init(args, suffix="native"):
|
|||
pmb.helpers.run.root(args, ["ln", "-s", "/var/cache/apk", chroot +
|
||||
"/etc/apk/cache"])
|
||||
|
||||
# Copy /etc/apk/keys/ and resolv.conf
|
||||
# Initialize /etc/apk/keys/, resolv.conf, repositories
|
||||
logging.debug(pmb.config.apk_keys_path)
|
||||
for key in glob.glob(pmb.config.apk_keys_path + "/*.pub"):
|
||||
pmb.helpers.run.root(args, ["cp", key, args.work +
|
||||
"/config_apk_keys/"])
|
||||
copy_resolv_conf(args, suffix)
|
||||
|
||||
# Write /etc/apk/repositories
|
||||
repos_path = chroot + "/etc/apk/repositories"
|
||||
if not os.path.exists(repos_path):
|
||||
for line in pmb.helpers.repo.urls(args):
|
||||
pmb.helpers.run.root(args, ["sh", "-c",
|
||||
"echo " + shlex.quote(line) + " >> " + repos_path])
|
||||
pmb.chroot.apk.update_repository_list(args, suffix)
|
||||
|
||||
# Install alpine-base (no clean exit for non-native chroot!)
|
||||
pmb.chroot.apk_static.run(args, ["-U", "--root", chroot,
|
||||
|
|
|
@ -225,6 +225,7 @@ def arguments():
|
|||
"apkindex_files": {},
|
||||
"apkbuild": {},
|
||||
"apk_min_version_checked": [],
|
||||
"apk_repository_list_updated": [],
|
||||
"aports_files_out_of_sync_with_git": None,
|
||||
"find_aport": {}})
|
||||
|
||||
|
|
Loading…
Reference in New Issue