From: Neil Williams Date: Sun, 10 Aug 2014 13:32:55 +0000 (+0100) Subject: Allow option to chown the image when complete. X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=12e25b3d3ecaf97d7b0648530ebf3e959302c8fd;p=forks%2Fvmdebootstrap.git Allow option to chown the image when complete. (Closes: #748477) Patch from Nick Daly --- diff --git a/vmdebootstrap b/vmdebootstrap index a9f9e9b..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']: @@ -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: @@ -501,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()