+ if not script:
+ return
+ if not os.path.exists(script):
+ example = os.path.join("/usr/share/vmdebootstrap/examples/", script)
+ if not os.path.exists(example):
+ self.message("Unable to find %s" % script)
+ return
+ script = example
+ self.message('Running customize script %s' % script)
+ with open('/dev/tty', 'w') as tty:
+ cliapp.runcmd([script, rootdir], stdout=tty, stderr=tty)
+
+ def create_tarball(self, rootdir):
+ # Create a tarball of the disk's contents
+ # shell out to runcmd since it more easily handles rootdir
+ 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"]])
+
+ def list_installed_pkgs(self, rootdir):
+ # output the list of installed packages for sources identification
+ self.message("Creating a list of installed binary package names")
+ out = self.runcmd(['chroot', rootdir,
+ 'dpkg-query', '-W' "-f='${Package}.deb\n'"])
+ with open('dpkg.list', 'w') as dpkg:
+ dpkg.write(out)
+
+ def configure_apt(self, rootdir):
+ # use the distribution and mirror to create an apt source
+ self.message("Configuring apt to use distribution and mirror")
+ conf = os.path.join(rootdir, 'etc', 'apt', 'sources.list.d', 'base.list')
+ logging.debug('configure apt %s', conf)
+ mirror = self.settings['mirror']
+ if self.settings['apt-mirror']:
+ mirror = self.settings['apt-mirror']
+ self.message("Setting apt mirror to %s" % mirror)
+ os.unlink(os.path.join(rootdir, 'etc', 'apt', 'sources.list'))
+ f = open(conf, 'w')
+ f.write('''
+deb %(mirror)s %(distribution)s main
+#deb-src %(mirror)s %(distribution)s main
+''' % {
+ 'mirror': mirror,
+ 'distribution': self.settings['distribution']
+ })
+ f.close()