]> git.siccegge.de Git - forks/vmdebootstrap.git/commitdiff
Add distro-info support for kernel names
authorNeil Williams <codehelp@debian.org>
Sun, 28 Jun 2015 10:59:16 +0000 (11:59 +0100)
committerNeil Williams <codehelp@debian.org>
Sun, 28 Jun 2015 10:59:16 +0000 (11:59 +0100)
Add a check on the distribution name and
support checking for the kernel package name
based on the suite specified. Add a kernel-package
option for other situations.

vmdebootstrap
vmdebootstrap.8.in

index 49c21c89bcc28e9350b478ff41654106377f11e1..add3d44165bfd3b1ea14a8a52fb79709b787f8c9 100755 (executable)
@@ -22,14 +22,16 @@ import logging
 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
@@ -38,6 +40,8 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
         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(
@@ -120,6 +124,10 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
         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')
@@ -184,7 +192,11 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
         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
@@ -410,6 +422,26 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
         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))
@@ -423,13 +455,20 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
             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:
index 80df9bc0340973345118fa65e958cb20df961f2e..aecc792454670b7d9dfcef5aa1bd0e5cbdcd713a 100644 (file)
@@ -23,7 +23,7 @@ vmdebootstrap \- install basic Debian system into virtual disk image
 .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]
@@ -155,13 +155,19 @@ architecture to use (amd64) - if using an architecture which the
 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