2013-06-27 23:26:29 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
2013-07-07 21:59:50 +02:00
|
|
|
from common.exceptions import TaskError
|
2014-02-23 22:03:13 +01:00
|
|
|
import host
|
2013-07-07 21:35:31 +02:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
2013-06-27 23:26:29 +02:00
|
|
|
|
|
|
|
|
2014-02-23 22:03:13 +01:00
|
|
|
class AddRequiredCommands(Task):
|
|
|
|
description = 'Adding commands required bootstrapping Debian'
|
|
|
|
phase = phases.preparation
|
|
|
|
successors = [host.CheckExternalCommands]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
info.host_dependencies['debootstrap'] = 'debootstrap'
|
|
|
|
|
|
|
|
|
2013-06-27 23:26:29 +02:00
|
|
|
def get_bootstrap_args(info):
|
2014-02-23 22:16:10 +01:00
|
|
|
executable = ['debootstrap']
|
2013-06-27 23:26:29 +02:00
|
|
|
options = ['--arch=' + info.manifest.system['architecture']]
|
2013-12-29 16:09:47 +01:00
|
|
|
if len(info.include_packages) > 0:
|
|
|
|
options.append('--include=' + ','.join(info.include_packages))
|
|
|
|
if len(info.exclude_packages) > 0:
|
|
|
|
options.append('--exclude=' + ','.join(info.exclude_packages))
|
2013-12-29 22:50:35 +01:00
|
|
|
mirror = info.manifest.bootstrapper.get('mirror', info.apt_mirror)
|
|
|
|
arguments = [info.manifest.system['release'], info.root, mirror]
|
2013-06-27 23:26:29 +02:00
|
|
|
return executable, options, arguments
|
|
|
|
|
|
|
|
|
|
|
|
class MakeTarball(Task):
|
|
|
|
description = 'Creating bootstrap tarball'
|
|
|
|
phase = phases.os_installation
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-06-27 23:26:29 +02:00
|
|
|
from hashlib import sha1
|
|
|
|
import os.path
|
|
|
|
executable, options, arguments = get_bootstrap_args(info)
|
2013-07-07 22:08:57 +02:00
|
|
|
# Filter info.root which points at /target/volume-id, we won't ever hit anything with that in there.
|
|
|
|
hash_args = [arg for arg in arguments if arg != info.root]
|
|
|
|
tarball_id = sha1(repr(frozenset(options + hash_args))).hexdigest()[0:8]
|
2013-06-27 23:26:29 +02:00
|
|
|
tarball_filename = 'debootstrap-{id}.tar'.format(id=tarball_id)
|
2013-09-15 16:59:56 +02:00
|
|
|
info.tarball = os.path.join(info.manifest.bootstrapper['workspace'], tarball_filename)
|
2013-07-07 21:35:31 +02:00
|
|
|
if os.path.isfile(info.tarball):
|
|
|
|
log.debug('Found matching tarball, skipping download')
|
|
|
|
else:
|
2013-07-07 21:59:50 +02:00
|
|
|
from common.tools import log_call
|
|
|
|
status, out, err = log_call(executable + options + ['--make-tarball=' + info.tarball] + arguments)
|
|
|
|
if status != 1:
|
|
|
|
msg = 'debootstrap exited with status {status}, it should exit with status 1'.format(status=status)
|
|
|
|
raise TaskError(msg)
|
2013-06-27 23:26:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Bootstrap(Task):
|
|
|
|
description = 'Installing Debian'
|
|
|
|
phase = phases.os_installation
|
2013-11-21 15:54:42 +01:00
|
|
|
predecessors = [MakeTarball]
|
2013-06-27 23:26:29 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-06-27 23:26:29 +02:00
|
|
|
executable, options, arguments = get_bootstrap_args(info)
|
|
|
|
if hasattr(info, 'tarball'):
|
|
|
|
options.extend(['--unpack-tarball=' + info.tarball])
|
2013-06-27 23:29:41 +02:00
|
|
|
|
2013-07-07 21:59:50 +02:00
|
|
|
from common.tools import log_check_call
|
2013-07-07 21:35:31 +02:00
|
|
|
log_check_call(executable + options + arguments)
|