2013-07-01 22:51:28 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
|
|
|
from common.tools import log_check_call
|
2013-08-11 23:46:22 +02:00
|
|
|
import locale
|
2013-07-01 22:51:28 +02:00
|
|
|
import os
|
2013-07-01 22:52:54 +02:00
|
|
|
|
|
|
|
|
2013-12-29 18:11:48 +01:00
|
|
|
class AddDefaultSources(Task):
|
|
|
|
description = 'Adding default release sources'
|
|
|
|
phase = phases.preparation
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 18:11:48 +01:00
|
|
|
if info.source_lists.target_exists('{system.release}'):
|
|
|
|
import logging
|
|
|
|
msg = ('{system.release} target already exists').format(**info.manifest_vars)
|
|
|
|
logging.getLogger(__name__).info(msg)
|
|
|
|
else:
|
|
|
|
info.source_lists.add('main', 'deb {apt_mirror} {system.release} main')
|
|
|
|
info.source_lists.add('main', 'deb-src {apt_mirror} {system.release} main')
|
|
|
|
info.source_lists.add('main', 'deb {apt_mirror} {system.release}-updates main')
|
|
|
|
info.source_lists.add('main', 'deb-src {apt_mirror} {system.release}-updates main')
|
|
|
|
|
|
|
|
|
2013-12-29 16:09:47 +01:00
|
|
|
class WriteSources(Task):
|
|
|
|
description = 'Writing aptitude sources to disk'
|
|
|
|
phase = phases.package_installation
|
2013-07-01 22:52:54 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 16:09:47 +01:00
|
|
|
for name, sources in info.source_lists.sources.iteritems():
|
|
|
|
if name == 'main':
|
|
|
|
list_path = os.path.join(info.root, 'etc/apt/sources.list')
|
|
|
|
else:
|
|
|
|
list_path = os.path.join(info.root, 'etc/apt/sources.list.d/', name + '.list')
|
|
|
|
with open(list_path, 'w') as source_list:
|
|
|
|
for source in sources:
|
|
|
|
source_list.write('{line}\n'.format(line=str(source)))
|
2013-07-01 22:51:28 +02:00
|
|
|
|
|
|
|
|
2013-07-07 17:33:19 +02:00
|
|
|
class DisableDaemonAutostart(Task):
|
|
|
|
description = 'Disabling daemon autostart'
|
2013-12-29 16:09:47 +01:00
|
|
|
phase = phases.package_installation
|
2013-07-01 22:51:28 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-07-01 22:51:28 +02:00
|
|
|
rc_policy_path = os.path.join(info.root, 'usr/sbin/policy-rc.d')
|
|
|
|
with open(rc_policy_path, 'w') as rc_policy:
|
2013-07-07 17:06:44 +02:00
|
|
|
rc_policy.write(('#!/bin/sh\n'
|
|
|
|
'exit 101'))
|
2013-07-01 22:51:28 +02:00
|
|
|
import stat
|
|
|
|
os.chmod(rc_policy_path,
|
|
|
|
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
|
|
|
|
stat.S_IRGRP | stat.S_IXGRP |
|
|
|
|
stat.S_IROTH | stat.S_IXOTH)
|
2013-07-07 17:33:19 +02:00
|
|
|
|
|
|
|
|
2013-11-30 22:37:51 +01:00
|
|
|
class AptUpdate(Task):
|
|
|
|
description = 'Updating the package cache'
|
2013-12-29 16:09:47 +01:00
|
|
|
phase = phases.package_installation
|
|
|
|
predecessors = [locale.GenerateLocale, WriteSources]
|
2013-11-30 22:37:51 +01:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 20:53:38 +01:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root,
|
|
|
|
'/usr/bin/apt-get', 'update'])
|
2013-11-30 22:37:51 +01:00
|
|
|
|
|
|
|
|
2013-07-07 17:33:19 +02:00
|
|
|
class AptUpgrade(Task):
|
|
|
|
description = 'Upgrading packages and fixing broken dependencies'
|
2013-12-29 16:09:47 +01:00
|
|
|
phase = phases.package_installation
|
2013-11-30 22:37:51 +01:00
|
|
|
predecessors = [AptUpdate, DisableDaemonAutostart]
|
2013-07-07 17:33:19 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 23:02:36 +01:00
|
|
|
from subprocess import CalledProcessError
|
|
|
|
try:
|
|
|
|
log_check_call(['/usr/sbin/chroot', info.root,
|
|
|
|
'/usr/bin/apt-get', 'install',
|
|
|
|
'--fix-broken',
|
|
|
|
'--no-install-recommends',
|
|
|
|
'--assume-yes'])
|
|
|
|
log_check_call(['/usr/sbin/chroot', info.root,
|
|
|
|
'/usr/bin/apt-get', 'upgrade',
|
|
|
|
'--no-install-recommends',
|
|
|
|
'--assume-yes'])
|
|
|
|
except CalledProcessError as e:
|
|
|
|
if e.returncode == 100:
|
|
|
|
import logging
|
|
|
|
msg = ('apt exited with status code 100. '
|
|
|
|
'This can sometimes occur when package retrieval times out or a package extraction failed. '
|
|
|
|
'apt might succeed if you try bootstrapping again.')
|
|
|
|
logging.getLogger(__name__).warn(msg)
|
|
|
|
raise e
|
2013-07-07 18:03:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PurgeUnusedPackages(Task):
|
|
|
|
description = 'Removing unused packages'
|
|
|
|
phase = phases.system_cleaning
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 20:53:38 +01:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root,
|
|
|
|
'/usr/bin/apt-get', 'autoremove',
|
|
|
|
'--purge'])
|
2013-07-07 18:03:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AptClean(Task):
|
|
|
|
description = 'Clearing the aptitude cache'
|
|
|
|
phase = phases.system_cleaning
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 20:53:38 +01:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root,
|
|
|
|
'/usr/bin/apt-get', 'clean'])
|
2013-07-07 18:03:49 +02:00
|
|
|
|
2013-07-07 18:07:15 +02:00
|
|
|
lists = os.path.join(info.root, 'var/lib/apt/lists')
|
|
|
|
for list_file in [os.path.join(lists, f) for f in os.listdir(lists)]:
|
2013-07-07 18:03:49 +02:00
|
|
|
if os.path.isfile(list_file):
|
|
|
|
os.remove(list_file)
|
|
|
|
|
|
|
|
|
|
|
|
class EnableDaemonAutostart(Task):
|
|
|
|
description = 'Re-enabling daemon autostart after installation'
|
|
|
|
phase = phases.system_cleaning
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-07-07 18:03:49 +02:00
|
|
|
os.remove(os.path.join(info.root, 'usr/sbin/policy-rc.d'))
|