2013-12-15 17:25:57 +01:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
2013-12-29 16:09:47 +01:00
|
|
|
from common.tasks.packages import InstallRemotePackages
|
2013-12-15 17:25:57 +01:00
|
|
|
from common.exceptions import TaskError
|
|
|
|
|
|
|
|
|
|
|
|
class CheckGuestAdditionsPath(Task):
|
|
|
|
description = 'Checking whether the VirtualBox Guest Additions image exists'
|
|
|
|
phase = phases.preparation
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-15 17:25:57 +01:00
|
|
|
import os.path
|
|
|
|
guest_additions_path = info.manifest.bootstrapper['guest_additions']
|
|
|
|
if not os.path.exists(guest_additions_path):
|
|
|
|
msg = 'The file {file} does not exist.'.format(file=guest_additions_path)
|
|
|
|
raise TaskError(msg)
|
|
|
|
|
|
|
|
|
|
|
|
class AddGuestAdditionsPackages(Task):
|
|
|
|
description = 'Adding packages to support Guest Additions installation'
|
2013-12-29 18:17:44 +01:00
|
|
|
phase = phases.package_installation
|
|
|
|
successors = [InstallRemotePackages]
|
2013-12-15 17:25:57 +01:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 16:09:47 +01:00
|
|
|
info.packages.add('bzip2')
|
|
|
|
info.packages.add('build-essential')
|
|
|
|
info.packages.add('dkms')
|
2013-12-29 18:17:44 +01:00
|
|
|
|
|
|
|
from common.tools import log_check_call
|
|
|
|
[kernel_version] = log_check_call(['/usr/sbin/chroot', info.root,
|
|
|
|
'/bin/uname', '-r'])
|
|
|
|
kernel_headers_pkg = 'linux-headers-{version}'.format(version=kernel_version)
|
|
|
|
info.packages.add(kernel_headers_pkg)
|
2013-12-15 17:25:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
class InstallGuestAdditions(Task):
|
|
|
|
description = 'Installing the VirtualBox Guest Additions'
|
2013-12-29 18:17:44 +01:00
|
|
|
phase = phases.package_installation
|
|
|
|
predecessors = [InstallRemotePackages]
|
2013-12-15 17:25:57 +01:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-15 17:25:57 +01:00
|
|
|
import os
|
|
|
|
guest_additions_path = info.manifest.bootstrapper['guest_additions']
|
|
|
|
mount_dir = 'mnt/guest_additions'
|
|
|
|
mount_path = os.path.join(info.root, mount_dir)
|
|
|
|
os.mkdir(mount_path)
|
|
|
|
root = info.volume.partition_map.root
|
|
|
|
root.add_mount(guest_additions_path, mount_path, ['-o', 'loop'])
|
|
|
|
|
|
|
|
install_script = os.path.join('/', mount_dir, 'VBoxLinuxAdditions.run')
|
2013-12-29 20:52:32 +01:00
|
|
|
from common.tools import log_call
|
|
|
|
status, out, err = log_call(['/usr/sbin/chroot', info.root,
|
|
|
|
install_script, '--nox11'])
|
2013-12-15 17:25:57 +01:00
|
|
|
# Install will exit with $?=1 because X11 isn't installed
|
2013-12-29 20:52:32 +01:00
|
|
|
if status != 1:
|
|
|
|
msg = ('VBoxLinuxAdditions.run exited with status {status}, '
|
|
|
|
'it should exit with status 1').format(status=status)
|
|
|
|
raise TaskError(msg)
|
2013-12-15 17:25:57 +01:00
|
|
|
|
|
|
|
root.remove_mount(mount_path)
|
|
|
|
os.rmdir(mount_path)
|