[elbe-devel] [PATCH v2 3/6] pbuilder: Handle mirror's options

Olivier Dion dion at linutronix.de
Tue Jul 21 18:59:20 CEST 2020


On Tue, 21 Jul 2020, Olivier Dion <dion at linutronix.de> wrote:
> This is still a big mess, but I think it's more readable now.
>
> get_apt_mirrors_and_keys() will return a tuple where the first element is a
> a list of mirrors to write to /etc/apt/sources.list and the second element is a
> list of GPG keys to import by apt.
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
> ---
>  elbepack/pbuilder.py | 100 +++++++++++++++++++++++++------------------
>  1 file changed, 59 insertions(+), 41 deletions(-)
>
> diff --git a/elbepack/pbuilder.py b/elbepack/pbuilder.py
> index fe90f3d1..3c0f1c1b 100644
> --- a/elbepack/pbuilder.py
> +++ b/elbepack/pbuilder.py
> @@ -154,50 +147,75 @@ def pbuilder_write_repo_hook(builddir, xml, cross):
>      with open(os.path.join(pbuilder_hook_dir, "H10elbe_apt_update"), "w") as f:
>          f.write("#!/bin/sh\napt update\n")
>  
> -    fp = open(os.path.join(pbuilder_hook_dir, "G10elbe_apt_sources"), "w")
> +    with open(os.path.join(pbuilder_hook_dir, "G10elbe_apt_sources"), "w") as f:
> +
> +        mirrors, keys = get_apt_mirrors_and_keys(builddir, xml, cross)
> +
> +        f.write("#!/bin/sh\n")
> +
> +        # cat reads from stdin (-) and redirect (>) to
> +        # /etc/apt/sources.list
> +        f.write("cat -> /etc/apt/sources.list <<EOF\n%s\nEOF\n" %
> +                '\n'.join(mirrors).replace("LOCALMACHINE", "10.0.2.2"))
> +
> +        for key in keys:
> +            f.write("cat << EOF | apt-key add -\n%s\nEOF\n" % key)
> +
> +        f.write("apt-get update\n")
> +
> +def get_apt_mirrors_and_keys(builddir, xml, _cross):
>  
>      if xml.prj is None:
> -        return "# No Project"
> +        return (["# No Project"], [])
>  
>      if not xml.prj.has("mirror") and not xml.prj.has("mirror/cdrom"):
> -        return "# no mirrors configured"
> +        return (["# No mirrors configured"], [])
>  
> -    mirror = "#!/bin/sh\n"
> +    suite = xml.prj.text("suite")
>  
> -    mirror += 'echo "deb http://127.0.0.1:8080' + builddir + '/repo ' + \
> -        xml.prj.text("suite") + ' main" > /etc/apt/sources.list\n'
> +    local_http = "deb http://127.0.0.1:8080%s/repo %s main" % (builddir, suite)
>  
> -    mirror = mirror_script_add_key_url(
> -        mirror,
> -        'http://127.0.0.1:8080' +
> -        builddir +
> -        '/repo/repo.pub')
> +    mirrors = [local_http]
> +    keys    = [Filesystem(builddir).read_file("repo/repo.pub")]
>  
>      if xml.prj.has("mirror/primary_host"):
> -        mirror += 'echo "deb ' + xml.get_primary_mirror(None) + ' ' + \
> -                  xml.prj.text("suite") + ' main" >> /etc/apt/sources.list\n'
> +
> +        if xml.prj.has("mirror/options"):
> +            poptions = "[ %s ]" % ' '.join([opt.et.text.strip(' \t\n')
> +                                            for opt
> +                                            in xml.prj.all("mirror/options/option")])
> +        else:
> +            poptions = ""
> +
> +        pmirror = xml.get_primary_mirror(None)
> +        suite   = xml.prj.text("suite")
> +
> +        mirrors.append("deb %s %s %s main" % (poptions, pmirror, suite))
>  
>          if xml.prj.has("mirror/url-list"):
> -            noauth = ""
> -            if xml.prj.has("noauth"):
> -                noauth = "[trusted=yes] "
> +
>              for url in xml.prj.node("mirror/url-list"):
> +
> +                if url.has("options"):
> +                    options = "[ %s ]" % ' '.join([opt.et.text.strip(' \t\n')
> +                                                   for opt
> +                                                   in url.all("options/option")])
> +                else:
> +                    options = ""
> +
>                  if url.has("binary"):
> -                    mirror += 'echo "deb ' + noauth + \
> -                              url.text("binary").strip() + \
> -                              '" >> /etc/apt/sources.list\n'
> -                if url.has("raw-key") and not xml.prj.has("noauth"):
> -                    key = "\n".join(line.strip(" \t") for line in url.text('raw-key').splitlines()[1:-1])
> -                    mirror = mirror_script_add_key_text(mirror, key)
> +                    bin_url = url.text("binary").strip()
> +                    mirrors.append("deb %s %s" % (options, bin_url))
>  
> -    if xml.prj.has("mirror/cdrom"):
> -        mirror += 'echo "deb copy:///cdrom/targetrepo %s main added" >> ' \
> -                  '/etc/apt/sources.list' % (xml.prj.text("suite"))
> +                if url.has("raw-key") and not "noauth" in options:

Note that this was changed to:
----------------------------------------------------------------------
+                if url.has("raw-key") and not "trusted=yes" in options:
----------------------------------------------------------------------
on my branch.

-- 
Olivier Dion
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen


More information about the elbe-devel mailing list