From e0dabce9cf244a8391f4727bedf87958fca9a031 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Sun, 10 Aug 2014 14:32:55 +0100 Subject: [PATCH] Allow option to chown the image when complete. (Closes: #748477) Patch from Nick Daly --- vmdebootstrap | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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() -- 2.39.5