1
# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
from __future__ import print_function
15
from lpbuildd.target.operation import Operation
18
logger = logging.getLogger(__name__)
21
class OverrideSourcesList(Operation):
23
description = "Override sources.list in the target environment."
26
def add_arguments(cls, parser):
27
super(OverrideSourcesList, cls).add_arguments(parser)
29
"--apt-proxy-url", metavar="URL", help="APT proxy URL")
31
"archives", metavar="ARCHIVE", nargs="+",
32
help="sources.list lines")
35
logger.info("Overriding sources.list in build-%s", self.args.build_id)
36
with tempfile.NamedTemporaryFile() as sources_list:
37
for archive in self.args.archives:
38
print(archive, file=sources_list)
40
os.fchmod(sources_list.fileno(), 0o644)
41
self.backend.copy_in(sources_list.name, "/etc/apt/sources.list")
42
if self.args.apt_proxy_url is not None:
43
with tempfile.NamedTemporaryFile() as apt_proxy_conf:
45
'Acquire::http::Proxy "{}";'.format(
46
self.args.apt_proxy_url),
48
apt_proxy_conf.flush()
49
os.fchmod(apt_proxy_conf.fileno(), 0o644)
51
apt_proxy_conf.name, "/etc/apt/apt.conf.d/99proxy")
55
class AddTrustedKeys(Operation):
57
description = "Write out new trusted keys."
59
def __init__(self, args, parser):
60
super(AddTrustedKeys, self).__init__(args, parser)
61
self.input_file = sys.stdin
64
"""Add trusted keys from an input file."""
65
logger.info("Adding trusted keys to build-%s", self.args.build_id)
66
self.backend.run(["apt-key", "add", "-"], stdin=self.input_file)
67
self.backend.run(["apt-key", "list"])
71
class Update(Operation):
73
description = "Update the target environment."
76
logger.info("Updating target for build %s", self.args.build_id)
77
with open("/dev/null", "r") as devnull:
80
"DEBIAN_FRONTEND": "noninteractive",
83
apt_get = "/usr/bin/apt-get"
84
update_args = [apt_get, "-uy", "update"]
86
self.backend.run(update_args, env=env, stdin=devnull)
87
except subprocess.CalledProcessError:
88
logger.warning("Waiting 15 seconds and trying again ...")
90
self.backend.run(update_args, env=env, stdin=devnull)
92
apt_get, "-o", "DPkg::Options::=--force-confold", "-uy",
93
"--purge", "dist-upgrade",
95
self.backend.run(upgrade_args, env=env, stdin=devnull)