X-Git-Url: https://git.siccegge.de//index.cgi?a=blobdiff_plain;f=vmdebootstrap;h=64614ad8c5f91442a5e71b7579b38ee8e97d3a9b;hb=969da62d6ad1dbd96683645067acef035a79207e;hp=77da850c1b2a627ca06d7bd1bbf4970dfa515d8e;hpb=1849ae0fe739dac0f4ba992be6a76e3d7843dcbc;p=forks%2Fvmdebootstrap.git diff --git a/vmdebootstrap b/vmdebootstrap index 77da850..64614ad 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -26,7 +26,7 @@ import tempfile import time -__version__ = '0.2' +__version__ = '0.3' class VmDebootstrap(cliapp.Application): @@ -100,6 +100,9 @@ class VmDebootstrap(cliapp.Application): self.settings.boolean(['sudo'], 'install sudo, and if user is created, add them ' 'to sudo group') + self.settings.string(['owner'], + 'the user who will own the image when the build ' + 'is complete.') def process_args(self, args): if not self.settings['image'] and not self.settings['tarball']: @@ -146,7 +149,7 @@ class VmDebootstrap(cliapp.Application): self.setup_networking(rootdir) self.customize(rootdir) if self.settings['image']: - if not self.settings['no-extlinux']: + if self.settings['extlinux']: self.install_extlinux(rootdev, rootdir) self.optimize_image(rootdir) @@ -156,8 +159,12 @@ class VmDebootstrap(cliapp.Application): if self.settings['tarball']: self.create_tarball(rootdir) + + if self.settings['owner']: + self.chown(rootdir) except BaseException, e: self.message('EEEK! Something bad happened...') + self.message(e) self.cleanup_system() raise else: @@ -292,13 +299,16 @@ class VmDebootstrap(cliapp.Application): f.write('%s\n' % hostname) etc_hosts = os.path.join(rootdir, 'etc', 'hosts') - with open(etc_hosts, 'r') as f: - data = f.read() - with open(etc_hosts, 'w') as f: - for line in data.splitlines(): - if line.startswith('127.0.0.1'): - line += ' %s' % hostname - f.write('%s\n' % line) + try: + with open(etc_hosts, 'r') as f: + data = f.read() + with open(etc_hosts, 'w') as f: + for line in data.splitlines(): + if line.startswith('127.0.0.1'): + line += ' %s' % hostname + f.write('%s\n' % line) + except IOError, e: + pass def create_fstab(self, rootdir, rootdev, roottype, bootdev, boottype): def fsuuid(device): @@ -498,6 +508,13 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s self.message('Creating tarball of disk contents') self.runcmd(['tar', '-cf', self.settings['tarball'], '-C', rootdir, '.']) + def chown(self, rootdir): + # Change image owner after completed build + self.message("Changing owner to %s" % self.settings["owner"]) + subprocess.call(["chown", + self.settings["owner"], + self.settings["image"]]) + if __name__ == '__main__': VmDebootstrap(version=__version__).run()