]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
Add --enable-dhcp option.
[forks/vmdebootstrap.git] / vmdebootstrap
index be3169b7e9276adfd8ad366c4db3d55d5c6d6edc..ce163b4f47a474112e4087e8b68d5f2adf18c05c 100755 (executable)
@@ -41,6 +41,7 @@ class VmDebootstrap(cliapp.Application):
         self.settings.add_string_setting(['mirror'],
                                          'use MIRROR as package source '
                                             '(%default)',
+                                         metavar='URL',
                                      default='http://cdn.debian.net/debian/')
         self.settings.add_string_setting(['arch'],
                                          'architecture to use '
@@ -51,6 +52,10 @@ class VmDebootstrap(cliapp.Application):
                                          'release to use (%default)',
                                          metavar='NAME',
                                          default='stable')
+        self.settings.add_string_list_setting(['package'],
+                                              'install PACKAGE onto system')
+        self.settings.add_boolean_setting(['enable-dhcp'],
+                                          'enable DHCP on eth0')
 
     def process_args(self, args):
         if not self.settings['image']:
@@ -70,6 +75,8 @@ class VmDebootstrap(cliapp.Application):
             rootdir = self.mount(rootdev)
             self.debootstrap(rootdir)
             self.set_root_password(rootdir)
+            self.remove_udev_persistent_rules(rootdir)
+            self.setup_networking(rootdir)
             self.install_extlinux(rootdev, rootdir)
         except:
             self.cleanup()
@@ -88,7 +95,7 @@ class VmDebootstrap(cliapp.Application):
                              **kwargs)
         out, err = p.communicate(stdin)
         if p.returncode != 0:
-            msg = 'command failed: %s\n%s' % (argv, err)
+            msg = 'command failed: %s\n%s\n%s' % (argv, out, err)
             logging.error(msg)
             if not ignore_fail:
                 raise cliapp.AppException(msg)
@@ -149,7 +156,7 @@ class VmDebootstrap(cliapp.Application):
             kernel_arch = self.settings['arch']
         kernel_image = 'linux-image-2.6-%s' % kernel_arch
 
-        include = [kernel_image]
+        include = [kernel_image] + self.settings['package']
 
         self.runcmd(['debootstrap', 
                      '--arch=%s' % self.settings['arch'],
@@ -161,6 +168,30 @@ class VmDebootstrap(cliapp.Application):
     def set_root_password(self, rootdir):
         self.message('Removing root password')
         self.runcmd(['chroot', rootdir, 'passwd', '-d', 'root'])
+        
+    def remove_udev_persistent_rules(self, rootdir):
+        self.message('Removing udev persistent cd and net rules')
+        for x in ['70-persistent-cd.rules', '70-persistent-net.rules']:
+            pathname = os.path.join(rootdir, 'etc', 'udev', 'rules.d', x)
+            if os.path.exists(pathname):
+                logging.debug('rm %s' % pathname)
+                os.remove(pathname)
+            else:
+                logging.debug('not removing non-existent %s' % pathname)
+
+    def setup_networking(self, rootdir):
+        self.message('Setting up networking')
+        
+        f = open(os.path.join(rootdir, 'etc', 'network', 'interfaces'), 'w')
+        f.write('auto lo\n')
+        f.write('iface lo inet loopback\n')
+        
+        if self.settings['enable-dhcp']:
+            f.write('\n')
+            f.write('allow-hotplug eth0\n')
+            f.write('iface eth0 inet dhcp\n')
+            
+        f.close()
 
     def install_extlinux(self, rootdev, rootdir):
         self.message('Installing extlinux')
@@ -190,7 +221,7 @@ timeout 1
 
 label linux
 kernel %(kernel)s
-append initrd=%(initrd)s root=UUID=%(uuid)s ro
+append initrd=%(initrd)s root=UUID=%(uuid)s ro quiet
 ''' % {
     'kernel': kernel_image,
     'initrd': initrd_image,