]> git.siccegge.de Git - forks/vmdebootstrap.git/commitdiff
Merge branch 'no-kernel-option' into tar-no-kernel
authorRichard Maw <richard.maw@codethink.co.uk>
Thu, 11 Oct 2012 09:54:26 +0000 (10:54 +0100)
committerRichard Maw <richard.maw@codethink.co.uk>
Thu, 11 Oct 2012 09:54:26 +0000 (10:54 +0100)
Conflicts:
vmdebootstrap

1  2 
vmdebootstrap

diff --combined vmdebootstrap
index 5b4c62bf4b5360f557a08f54b1dfbb3b2bbdea34,37b1b78972117d4f90eafed3dc750c0ac9b20ed8..eb7d1b1297e61d05300f66e403bb106d472f91bd
@@@ -37,8 -37,6 +37,8 @@@ class VmDebootstrap(cliapp.Application)
                                 'create a disk image of size SIZE (%default)',
                                 metavar='SIZE',
                                 default='1G')
 +        self.settings.string(['tarball'], "tar up the disk's contents in FILE",
 +                             metavar='FILE')
          self.settings.string(['mirror'],
                               'use MIRROR as package source (%default)',
                               metavar='URL',
                                  'to sudo group')
  
      def process_args(self, args):
 -        if not self.settings['image']:
 -            raise cliapp.AppException('You must give image filename.')
 -        if not self.settings['size']:
 -            raise cliapp.AppException('You must give image size.')
 +        if not self.settings['image'] and not self.settings['tarball']:
 +            raise cliapp.AppException('You must give disk image filename, '
 +                                      'or tarball filename')
 +        if self.settings['image'] and not self.settings['size']:
 +            raise cliapp.AppException('If disk image is specified, '
 +                                      'You must give image size.')
  
          self.remove_dirs = []
          self.mount_points = []
  
          try:
 -            self.create_empty_image()
 -            self.partition_image()
 -            self.install_mbr()
 -            rootdev = self.setup_kpartx()
 -            self.mkfs(rootdev)
 -            rootdir = self.mount(rootdev)
 +            if self.settings['image']:
 +                self.create_empty_image()
 +                self.partition_image()
 +                self.install_mbr()
 +                rootdev = self.setup_kpartx()
 +                self.mkfs(rootdev)
 +                rootdir = self.mount(rootdev)
 +            else:
 +                rootdir = self.mkdtemp()
              self.debootstrap(rootdir)
              self.set_hostname(rootdir)
              self.create_fstab(rootdir)
              self.create_users(rootdir)
              self.remove_udev_persistent_rules(rootdir)
              self.setup_networking(rootdir)
 -            self.install_extlinux(rootdev, rootdir)
+             self.customize(rootdir)
-             self.customize(rootdir)
 +            if self.settings['image']:
 +                self.install_extlinux(rootdev, rootdir)
 +            if self.settings['tarball']:
 +                self.create_tarball(rootdir)
          except BaseException, e:
              self.message('EEEK! Something bad happened...')
              self.cleanup_system()
          if self.settings['sudo'] and 'sudo' not in include:
              include.append('sudo')
  
-         self.runcmd(['debootstrap', 
-                      '--arch=%s' % self.settings['arch'],
-                      '--include=%s' % ','.join(include),
-                      self.settings['distribution'],
-                      rootdir, 
-                      self.settings['mirror']])
+         args = ['debootstrap', '--arch=%s' % self.settings['arch']]
+         if include: args.append('--include=%s' % ','.join(include))
+         args += [self.settings['distribution'],
+                  rootdir, self.settings['mirror']]
+         self.runcmd(args)
  
      def set_hostname(self, rootdir):
          hostname = self.settings['hostname']
@@@ -357,11 -346,10 +356,11 @@@ append initrd=%(initrd)s root=UUID=%(uu
  
          self.message('Cleaning up')
  
 -        for mount_point in self.mount_points:
 -            self.runcmd(['umount', mount_point], ignore_fail=True)
 +        if self.settings['image']:
 +            for mount_point in self.mount_points:
 +                self.runcmd(['umount', mount_point], ignore_fail=True)
  
 -        self.runcmd(['kpartx', '-d', self.settings['image']], ignore_fail=True)
 +            self.runcmd(['kpartx', '-d', self.settings['image']], ignore_fail=True)
          
          for dirname in self.remove_dirs:
              shutil.rmtree(dirname)
              with open('/dev/tty', 'w') as tty:
                  cliapp.runcmd([script, rootdir], stdout=tty, stderr=tty)
  
 +    def create_tarball(self, rootdir):
 +        # Create a tarball of the disk's contents
 +        # shell out to runcmd since it more easily handles rootdir
 +        self.message('Creating tarball of disk contents')
 +        self.runcmd(['tar', '-cf', self.settings['tarball'], '-C', rootdir, '.'])
 +
  
  if __name__ == '__main__':
      VmDebootstrap().run()