465
472
comment = comment[:-1]
467
474
marker = os.path.join(target, marker)
468
if not force and os.path.exists(marker):
475
# if marker exists, check if there are files that would make it obsolete
476
if os.path.exists(marker) and not force:
477
listfiles = [os.path.join(target, "/etc/apt/sources.list")]
478
listfiles += glob.glob(
479
os.path.join(target, "/etc/apt/sources.list.d/*.list"))
480
if len(find_newer(marker, listfiles)) == 0:
483
# we're not using 'run_apt_command' so we can use 'retries' to subp
471
484
apt_update = ['apt-get', 'update', '--quiet']
472
with RunInChroot(target) as inchroot:
485
with RunInChroot(target, allow_daemons=True) as inchroot:
473
486
inchroot(apt_update, env=env, retries=retries)
475
488
with open(marker, "w") as fp:
476
489
fp.write(comment + "\n")
479
def install_packages(pkglist, aptopts=None, target=None, env=None,
480
allow_daemons=False):
481
apt_inst_cmd = ['apt-get', 'install', '--quiet', '--assume-yes',
482
'--option=Dpkg::options::=--force-unsafe-io']
492
def run_apt_command(mode, args=None, aptopts=None, env=None, target=None,
493
execute=True, allow_daemons=False):
494
opts = ['--quiet', '--assume-yes',
495
'--option=Dpkg::options::=--force-unsafe-io',
496
'--option=Dpkg::Options::=--force-confold']
484
501
if aptopts is None:
486
apt_inst_cmd.extend(aptopts)
505
env = os.environ.copy()
506
env['DEBIAN_FRONTEND'] = 'noninteractive'
488
508
if which('eatmydata', target=target):
489
509
emd = ['eatmydata']
513
cmd = emd + ['apt-get'] + opts + aptopts + [mode] + args
517
apt_update(target, env=env, comment=' '.join(cmd))
518
ric = RunInChroot(target, allow_daemons=allow_daemons)
519
with ric as inchroot:
520
return inchroot(cmd, env=env)
523
def system_upgrade(aptopts=None, target=None, env=None, allow_daemons=False):
524
LOG.debug("Upgrading system in %s", target)
525
for mode in ('dist-upgrade', 'autoremove'):
526
ret = run_apt_command(
527
mode, aptopts=aptopts, target=target,
528
env=env, allow_daemons=allow_daemons)
532
def install_packages(pkglist, aptopts=None, target=None, env=None,
533
allow_daemons=False):
493
534
if isinstance(pkglist, str):
494
535
pkglist = [pkglist]
497
env = os.environ.copy()
498
env['DEBIAN_FRONTEND'] = 'noninteractive'
500
apt_update(target, comment=' '.join(pkglist))
501
ric = RunInChroot(target, allow_daemons=allow_daemons)
502
with ric as inchroot:
504
emd + apt_inst_cmd + list(pkglist), env=env)
536
return run_apt_command(
537
'install', args=pkglist,
538
aptopts=aptopts, target=target, env=env, allow_daemons=allow_daemons)
507
541
def is_uefi_bootable():