90
89
info.get('perms', "0644")))
93
def apt_config(cfg, target):
96
proxy_cfg_path = os.path.sep.join(
97
[target, '/etc/apt/apt.conf.d/90curtin-aptproxy'])
98
if cfg.get('apt_proxy'):
101
content='Acquire::HTTP::Proxy "%s";\n' % cfg['apt_proxy'])
92
def do_apt_config(cfg, target):
93
cfg = apt_config.translate_old_apt_features(cfg)
94
apt_cfg = cfg.get("apt")
95
if apt_cfg is not None:
96
LOG.info("curthooks handling apt to target %s with config %s",
98
apt_config.handle_apt(apt_cfg, target)
103
if os.path.isfile(proxy_cfg_path):
104
os.unlink(proxy_cfg_path)
108
# ubuntu_archive: http://local.archive/ubuntu
109
# ubuntu_security: http://local.archive/ubuntu
110
sources_list = os.path.sep.join([target, '/etc/apt/sources.list'])
111
if (isinstance(cfg.get('apt_mirrors'), dict) and
112
os.path.isfile(sources_list)):
114
('ubuntu_archive', r'http://\S*[.]*archive.ubuntu.com/\S*'),
115
('ubuntu_security', r'http://security.ubuntu.com/\S*'),
118
for name, regex in repls:
119
mirror = cfg['apt_mirrors'].get(name)
124
with open(sources_list) as fp:
126
util.write_file(sources_list + ".dist", content)
128
content = re.sub(regex, mirror + " ", content)
130
if content is not None:
131
util.write_file(sources_list, content)
100
LOG.info("No apt config provided, skipping")
134
103
def disable_overlayroot(cfg, target):
250
210
mapping = copy.deepcopy(KERNEL_MAPPING)
251
211
config.merge_config(mapping, kernel_cfg.get('mapping', {}))
253
with util.RunInChroot(target) as in_chroot:
256
util.install_packages([kernel_package], target=target)
259
# uname[2] is kernel name (ie: 3.16.0-7-generic)
260
# version gets X.Y.Z, flavor gets anything after second '-'.
261
kernel = os.uname()[2]
262
codename, err = in_chroot(['lsb_release', '--codename', '--short'],
264
codename = codename.strip()
265
version, abi, flavor = kernel.split('-', 2)
268
map_suffix = mapping[codename][version]
270
LOG.warn("Couldn't detect kernel package to install for %s."
272
if kernel_fallback is not None:
273
util.install_packages([kernel_fallback], target=target)
276
package = "linux-{flavor}{map_suffix}".format(
277
flavor=flavor, map_suffix=map_suffix)
279
if util.has_pkg_available(package, target):
280
if util.has_pkg_installed(package, target):
281
LOG.debug("Kernel package '%s' already installed", package)
283
LOG.debug("installing kernel package '%s'", package)
284
util.install_packages([package], target=target)
286
if kernel_fallback is not None:
287
LOG.info("Kernel package '%s' not available. "
288
"Installing fallback package '%s'.",
289
package, kernel_fallback)
290
util.install_packages([kernel_fallback], target=target)
292
LOG.warn("Kernel package '%s' not available and no fallback."
293
" System may not boot.", package)
296
def apply_debconf_selections(cfg, target):
297
# debconf_selections:
299
# cloud-init cloud-init/datasources multiselect MAAS
300
# set2: pkg pkg/value string bar
301
selsets = cfg.get('debconf_selections')
303
LOG.debug("debconf_selections was not set in config")
306
# for each entry in selections, chroot and apply them.
307
# keep a running total of packages we've seen.
309
for key, content in selsets.items():
310
LOG.debug("setting for %s, %s" % (key, content))
311
util.subp(['chroot', target, 'debconf-set-selections'],
312
data=content.encode())
313
for line in content.splitlines():
314
if line.startswith("#"):
316
pkg = re.sub(r"[:\s].*", "", line)
319
pkgs_installed = get_installed_packages(target)
321
LOG.debug("pkgs_cfgd: %s" % pkgs_cfgd)
322
LOG.debug("pkgs_installed: %s" % pkgs_installed)
323
need_reconfig = pkgs_cfgd.intersection(pkgs_installed)
325
if len(need_reconfig) == 0:
326
LOG.debug("no need for reconfig")
329
# For any packages that are already installed, but have preseed data
330
# we populate the debconf database, but the filesystem configuration
331
# would be preferred on a subsequent dpkg-reconfigure.
332
# so, what we have to do is "know" information about certain packages
333
# to unconfigure them.
336
for pkg in need_reconfig:
337
if pkg in CONFIG_CLEANERS:
338
LOG.debug("unconfiguring %s" % pkg)
339
CONFIG_CLEANERS[pkg](target)
340
to_config.append(pkg)
342
unhandled.append(pkg)
345
LOG.warn("The following packages were installed and preseeded, "
346
"but cannot be unconfigured: %s", unhandled)
348
util.subp(['chroot', target, 'dpkg-reconfigure',
349
'--frontend=noninteractive'] +
350
list(to_config), data=None)
353
def get_installed_packages(target=None):
355
if target is not None:
356
cmd = ['chroot', target]
357
cmd.extend(['dpkg-query', '--list'])
359
(out, _err) = util.subp(cmd, capture=True)
360
if isinstance(out, bytes):
364
for line in out.splitlines():
366
(state, pkg, other) = line.split(None, 2)
369
if state.startswith("hi") or state.startswith("ii"):
370
pkgs_inst.add(re.sub(":.*", "", pkg))
214
util.install_packages([kernel_package], target=target)
217
# uname[2] is kernel name (ie: 3.16.0-7-generic)
218
# version gets X.Y.Z, flavor gets anything after second '-'.
219
kernel = os.uname()[2]
220
codename, _ = util.subp(['lsb_release', '--codename', '--short'],
221
capture=True, target=target)
222
codename = codename.strip()
223
version, abi, flavor = kernel.split('-', 2)
226
map_suffix = mapping[codename][version]
228
LOG.warn("Couldn't detect kernel package to install for %s."
230
if kernel_fallback is not None:
231
util.install_packages([kernel_fallback], target=target)
234
package = "linux-{flavor}{map_suffix}".format(
235
flavor=flavor, map_suffix=map_suffix)
237
if util.has_pkg_available(package, target):
238
if util.has_pkg_installed(package, target):
239
LOG.debug("Kernel package '%s' already installed", package)
241
LOG.debug("installing kernel package '%s'", package)
242
util.install_packages([package], target=target)
244
if kernel_fallback is not None:
245
LOG.info("Kernel package '%s' not available. "
246
"Installing fallback package '%s'.",
247
package, kernel_fallback)
248
util.install_packages([kernel_fallback], target=target)
250
LOG.warn("Kernel package '%s' not available and no fallback."
251
" System may not boot.", package)
375
254
def setup_grub(cfg, target):