[elbe-devel] [PATCH 3/4] pbuilder: Handle mirror's options
Torben Hohn
torben.hohn at linutronix.de
Wed Jul 15 12:41:53 CEST 2020
On Tue, Jun 30, 2020 at 12:05:18PM -0400, Olivier Dion 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.
yeah. this direction is nice.
But please dont download from the localhost repo.
Just use the file. os.path.join(builddir, '
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
> ---
> elbepack/pbuilder.py | 96 +++++++++++++++++++++++++-------------------
> 1 file changed, 55 insertions(+), 41 deletions(-)
>
> diff --git a/elbepack/pbuilder.py b/elbepack/pbuilder.py
> index 6f266a93..21d952a3 100644
> --- a/elbepack/pbuilder.py
> +++ b/elbepack/pbuilder.py
> @@ -112,22 +112,13 @@ def pbuilder_write_apt_conf(builddir, xml):
> fp.write('Aptitude::CmdLine::Ignore-Trust-Violations "true";\n')
> fp.close()
>
> -
> -def mirror_script_add_key_text(mirror, key_text):
> - mirror += "cat << EOF | apt-key add -\n"
> - mirror += key_text + "\n"
> - mirror += "EOF\n"
> -
> - return mirror
> -
> -
> -def mirror_script_add_key_url(mirror, key_url):
> +def mirror_script_add_key_url(key_url):
> key_url = key_url.replace("LOCALMACHINE", "10.0.2.2")
> key_conn = urlopen(key_url, None, 10)
> key_text = key_conn.read()
> key_conn.close()
>
> - return mirror_script_add_key_text(mirror, key_text)
> + return key_text
>
>
> def pbuilder_write_repo_hook(builddir, xml, cross):
> @@ -140,50 +131,73 @@ 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")
> +
> + 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 = [mirror_script_add_key_url('http://127.0.0.1:8080%s/repo/repo.pub' % builddir)]
just use os.path.join(builddir, 'repo/repo.pub')
you can also use
elbepack.filesystem.Filesystem(builddir).read_file('repo/repo.pub') then.
>
> 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:
>
> - mirror += 'apt-get update\n'
> - mirror = mirror.replace("LOCALMACHINE", "10.0.2.2")
> + key = "\n".join(line.strip(" \t")
> + for line
> + in url.text('raw-key').splitlines()[1:-1])
>
> - fp.write(mirror)
> - fp.close()
> + keys.append(key)
> +
> + if xml.prj.has("mirror/cdrom"):
> + mirrors.append("deb copy:///cdrom/targetrepo %s main added" % suite)
>
> - return ""
> + return (mirrors, keys)
> --
> 2.27.0
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Hinweise zum Datenschutz finden Sie hier (Informations on data privacy
can be found here): https://linutronix.de/kontakt/Datenschutz.php
Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen |
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
More information about the elbe-devel
mailing list