+ with open(os.path.join(rootdir, 'etc', 'hostname'), 'w') as f:
+ 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)
+
+ def create_fstab(self, rootdir, rootdev, roottype, bootdev, boottype):
+ def fsuuid(device):
+ out = self.runcmd(['blkid', '-c', '/dev/null', '-o', 'value',
+ '-s', 'UUID', device])
+ return out.splitlines()[0].strip()
+
+ if rootdev:
+ rootdevstr = 'UUID=%s' % fsuuid(rootdev)
+ else:
+ rootdevstr = '/dev/sda1'
+
+ if bootdev:
+ bootdevstr = 'UUID=%s' % fsuuid(bootdev)
+ else:
+ bootdevstr = None
+
+ fstab = os.path.join(rootdir, 'etc', 'fstab')
+ with open(fstab, 'w') as f:
+ f.write('proc /proc proc defaults 0 0\n')
+ f.write('%s / %s errors=remount-ro 0 1\n' % (rootdevstr, roottype))
+ if bootdevstr:
+ f.write('%s /boot %s errors=remount-ro 0 2\n' % (bootdevstr, boottype))
+
+ def install_debs(self, rootdir):
+ if not self.settings['custom-package']:
+ return
+ self.message('Installing custom packages')
+ tmp = os.path.join(rootdir, 'tmp', 'install_debs')
+ os.mkdir(tmp)
+ for deb in self.settings['custom-package']:
+ shutil.copy(deb, tmp)
+ filenames = [os.path.join('/tmp/install_debs', os.path.basename(deb))
+ for deb in self.settings['custom-package']]
+ out, err, exit = \
+ self.runcmd_unchecked(['chroot', rootdir, 'dpkg', '-i'] + filenames)
+ logging.debug('stdout:\n%s' % out)
+ logging.debug('stderr:\n%s' % err)
+ out = self.runcmd(['chroot', rootdir,
+ 'apt-get', '-f', '--no-remove', 'install'])
+ logging.debug('stdout:\n%s' % out)
+ shutil.rmtree(tmp)
+
+ def cleanup_apt_cache(self, rootdir):
+ out = self.runcmd(['chroot', rootdir, 'apt-get', 'clean'])
+ logging.debug('stdout:\n%s' % out)