X-Git-Url: https://git.siccegge.de//index.cgi?p=forks%2Fvmdebootstrap.git;a=blobdiff_plain;f=vmdebootstrap;h=2ffe6634bb58303aa13241f9f9736e0bb600d149;hp=295bdc74f7017ef4e551c431a1f16baf6d030610;hb=1f23b06cbc7c3e20284ed7d1b0a66a5665ecf1e2;hpb=8eae76bc2cbb5ca1ff197c0568afd91c2b74473a diff --git a/vmdebootstrap b/vmdebootstrap index 295bdc7..2ffe663 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -1,5 +1,6 @@ #!/usr/bin/python -# Copyright 2011 Lars Wirzenius +# Copyright 2011, 2012 Lars Wirzenius +# Copyright 2012 Codethink Limited # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -52,9 +53,12 @@ class VmDebootstrap(cliapp.Application): 'install package in DEB file onto system ' '(not from mirror)', metavar='DEB') + self.settings.boolean(['no-kernel'], 'do not install a linux package') self.settings.boolean(['enable-dhcp'], 'enable DHCP on eth0') self.settings.string(['root-password'], 'set root password', metavar='PASSWORD') + self.settings.boolean(['lock-root-password'], + 'lock root account so they cannot login?') self.settings.string(['customize'], 'run SCRIPT after setting up system', metavar='SCRIPT') @@ -95,16 +99,17 @@ class VmDebootstrap(cliapp.Application): self.create_users(rootdir) self.remove_udev_persistent_rules(rootdir) self.setup_networking(rootdir) - self.install_extlinux(rootdev, rootdir) self.customize(rootdir) + self.install_extlinux(rootdev, rootdir) except BaseException, e: self.message('EEEK! Something bad happened...') - self.cleanup() + self.cleanup_system() raise else: - self.cleanup() + self.cleanup_system() def message(self, msg): + logging.info(msg) if self.settings['verbose']: print msg @@ -170,13 +175,16 @@ class VmDebootstrap(cliapp.Application): def debootstrap(self, rootdir): self.message('Debootstrapping') - if self.settings['arch'] == 'i386': - kernel_arch = '686' - else: - kernel_arch = self.settings['arch'] - kernel_image = 'linux-image-2.6-%s' % kernel_arch + include = self.settings['package'] + + if not self.settings['no-kernel']: + if self.settings['arch'] == 'i386': + kernel_arch = '686' + else: + kernel_arch = self.settings['arch'] + kernel_image = 'linux-image-2.6-%s' % kernel_arch + include.append(kernel_image) - include = [kernel_image] + self.settings['package'] if self.settings['sudo'] and 'sudo' not in include: include.append('sudo') @@ -230,9 +238,12 @@ class VmDebootstrap(cliapp.Application): if self.settings['root-password']: self.message('Setting root password') self.set_password(rootdir, 'root', self.settings['root-password']) - else: + elif self.settings['lock-root-password']: self.message('Locking root password') self.runcmd(['chroot', rootdir, 'passwd', '-l', 'root']) + else: + self.message('Give root an empty password') + self.delete_password(rootdir, 'root') def create_users(self, rootdir): def create_user(user): @@ -248,11 +259,15 @@ class VmDebootstrap(cliapp.Application): self.set_password(rootdir, user, password) else: create_user(userpass) + self.delete_password(rootdir, userpass) def set_password(self, rootdir, user, password): encrypted = crypt.crypt(password, '..') self.runcmd(['chroot', rootdir, 'usermod', '-p', encrypted, user]) + def delete_password(self, rootdir, user): + self.runcmd(['chroot', rootdir, 'passwd', '-d', user]) + 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']: @@ -327,7 +342,7 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro quiet %(kserial)s self.runcmd(['sync']) import time; time.sleep(2) - def cleanup(self): + def cleanup_system(self): # Clean up after any errors. self.message('Cleaning up') @@ -344,7 +359,8 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro quiet %(kserial)s script = self.settings['customize'] if script: self.message('Running customize script %s' % script) - self.runcmd([script, rootdir]) + with open('/dev/tty', 'w') as tty: + cliapp.runcmd([script, rootdir], stdout=tty, stderr=tty) if __name__ == '__main__':