From 9b7feadca6058c72f4a2347b62b5d41cc1b0e6bc Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Thu, 9 Sep 2021 23:30:31 +0200 Subject: [PATCH] pmb.chroot.init_keys: split into own function (MR 2110) Move code to install Alpine and postmarketOS keys into its own function, so it can be called outside of pmb.chroot.init too (next patch). Describe why this is needed in the first place and, while at it, tweak the function to only copy the key if it does not exist in the target directory. --- pmb/chroot/init.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pmb/chroot/init.py b/pmb/chroot/init.py index f7fc6b08..5e128c31 100644 --- a/pmb/chroot/init.py +++ b/pmb/chroot/init.py @@ -57,6 +57,23 @@ def setup_qemu_emulation(args, suffix): create_folders=True) +def init_keys(args): + """ + All Alpine and postmarketOS repository keys are shipped with pmbootstrap. + Copy them into $WORK/config_apk_keys, which gets mounted inside the various + chroots as /etc/apk/keys. + + This is done before installing any package, so apk can verify APKINDEX + files of binary repositories even though alpine-keys/postmarketos-keys are + not installed yet. + """ + for key in glob.glob(f"{pmb.config.apk_keys_path}/*.pub"): + target = f"{args.work}/config_apk_keys/{os.path.basename(key)}" + if not os.path.exists(target): + # Copy as root, so the resulting files in chroots are owned by root + pmb.helpers.run.root(args, ["cp", key, target]) + + def init(args, suffix="native"): # When already initialized: just prepare the chroot chroot = f"{args.work}/chroot_{suffix}" @@ -82,9 +99,7 @@ def init(args, suffix="native"): f"{chroot}/etc/apk/cache"]) # Initialize /etc/apk/keys/, resolv.conf, repositories - for key in glob.glob(f"{pmb.config.apk_keys_path}/*.pub"): - pmb.helpers.run.root(args, ["cp", key, f"{args.work}" - "/config_apk_keys/"]) + init_keys(args) copy_resolv_conf(args, suffix) pmb.chroot.apk.update_repository_list(args, suffix)