import os
import re
import shutil
+import datetime
import subprocess
import tempfile
import time
+from distro_info import DebianDistroInfo, UbuntuDistroInfo
-__version__ = '0.7'
+__version__ = '0.8'
-# pylint: disable=invalid-name
+# pylint: disable=invalid-name,line-too-long,missing-docstring,too-many-branches
class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-methods
super(VmDebootstrap, self).__init__(progname, version, description, epilog)
self.remove_dirs = []
self.mount_points = []
+ self.debian_info = DebianDistroInfo()
+ self.ubuntu_info = UbuntuDistroInfo()
def add_settings(self):
default_arch = subprocess.check_output(
self.settings.boolean(
['no-kernel'],
'do not install a linux package')
+ self.settings.string(
+ ['kernel-package'],
+ 'install PACKAGE instead of the default kernel package',
+ metavar='PACKAGE')
self.settings.boolean(
['enable-dhcp'],
'enable DHCP on eth0')
if self.settings['image'] and not self.settings['size']:
raise cliapp.AppException(
'If disk image is specified, you must give image size.')
-
+ if not self.debian_info.valid(self.settings['distribution']):
+ if not self.ubuntu_info.valid(self.settings['distribution']):
+ raise cliapp.AppException(
+ '%s is not a valid Debian or Ubuntu suite or codename.'
+ % self.settings['distribution'])
rootdir = None
try:
rootdev = None
self.message('Creating filesystem %s' % fstype)
self.runcmd(['mkfs', '-t', fstype, device])
+ def suite_to_codename(self, distro):
+ suite = self.debian_info.codename(distro, datetime.date.today())
+ if not suite:
+ return distro
+ return suite
+
+ def was_oldstable(self, limit):
+ suite = self.suite_to_codename(self.settings['distribution'])
+ # this check is only for debian
+ if not self.debian_info.valid(suite):
+ return False
+ return suite == self.debian_info.old(limit)
+
+ def was_stable(self, limit):
+ suite = self.suite_to_codename(self.settings['distribution'])
+ # this check is only for debian
+ if not self.debian_info.valid(suite):
+ return False
+ return suite == self.debian_info.stable(limit)
+
def debootstrap(self, rootdir):
msg = "(%s)" % self.settings['variant'] if self.settings['variant'] else ''
self.message('Debootstrapping %s %s' % (self.settings['distribution'], msg))
include.append('grub-pc')
if not self.settings['no-kernel']:
- if self.settings['arch'] == 'i386':
- kernel_arch = '486'
- elif self.settings['arch'] == 'armhf':
- kernel_arch = 'armmp'
+ if self.settings['kernel-package']:
+ kernel_image = self.settings['kernel-package']
else:
- kernel_arch = self.settings['arch']
- kernel_image = 'linux-image-%s' % kernel_arch
+ if self.settings['arch'] == 'i386':
+ # wheezy (which became oldstable on 04/25/2015) used '486'
+ if self.was_oldstable(datetime.date(2015, 4, 26)):
+ kernel_arch = '486'
+ else:
+ kernel_arch = '586'
+ elif self.settings['arch'] == 'armhf':
+ kernel_arch = 'armmp'
+ else:
+ kernel_arch = self.settings['arch']
+ kernel_image = 'linux-image-%s' % kernel_arch
include.append(kernel_image)
if self.settings['sudo'] and 'sudo' not in include:
.B vmdebootstrap
[\-\-output=FILE] [\-\-verbose |\-\-no-verbose] \-\-image=FILE \-\-size=SIZE
[\-\-tarball=FILE] [\-\-mirror=URL] [\-\-arch=ARCH] [\-\-distribution=NAME]
-[\-\-package=PACKAGE] [\-\-custom-package=DEB] [\-\-no-kernel]
+[\-\-package=PACKAGE] [\-\-custom-package=DEB] [\-\-no-kernel] [\-\-kernel-package]
[\-\-enable-dhcp | \-\-no-enable-dhcp] [\-\-root-password=PASSWORD]
[\-\-customize=SCRIPT] [\-\-hostname=HOSTNAME] [\-\-user=USER/PASSWORD]
[\-\-serial-console | \-\-no-serial-console] [\-\-sudo |\-\-no-sudo] [\-\-owner=OWNER]
host system cannot execute, ensure the \-\-foreign option is also
used.
.IP \-\-distribution=NAME
-release to use (stable)
+release to use (defaults to stable). The release needs to be a valid
+Debian or Ubuntu release name or codename.
.IP \-\-package=PACKAGE
install PACKAGE onto system
.IP \-\-custom-package=DEB
install package in DEB file onto system (not from mirror)
.IP \-\-no-kernel
do not install a linux package
+.IP \-\-kernel-package
+If \-\-no-kernel is not used and the auto-selection of the
+.B linux-image\$arch
+package is not suitable, the kernel package can be specified
+explicitly.
.IP \-\-enable-dhcp
enable DHCP on eth0
.IP \-\-root-password=PASSWORD