- if self.settings['arch'] == 'i386':
- kernel_arch = 'i686'
- else:
- kernel_arch = self.settings['arch']
- kernel_image = 'linux-image-2.6-%s' % kernel_arch
-
- include = [kernel_image]
-
- self.runcmd(['debootstrap',
- '--arch=%s' % self.settings['arch'],
- '--include=%s' % ','.join(include),
- self.settings['distribution'],
- rootdir,
- self.settings['mirror']])
+ necessary_packages = ['acpid']
+
+ include = self.settings['package']
+
+ if not self.settings['no-kernel']:
+ if self.settings['arch'] == 'i386':
+ kernel_arch = '486'
+ else:
+ kernel_arch = self.settings['arch']
+ kernel_image = 'linux-image-%s' % kernel_arch
+ include.append(kernel_image)
+
+ if self.settings['sudo'] and 'sudo' not in include:
+ include.append('sudo')
+
+ args = ['debootstrap', '--arch=%s' % self.settings['arch']]
+ args.append(
+ '--include=%s' % ','.join(necessary_packages + include))
+ args += [self.settings['distribution'],
+ rootdir, self.settings['mirror']]
+ self.runcmd(args)
+
+ def set_hostname(self, rootdir):
+ hostname = self.settings['hostname']
+ 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):
+ fstab = os.path.join(rootdir, 'etc', 'fstab')
+ with open(fstab, 'w') as f:
+ f.write('proc /proc proc defaults 0 0\n')
+ f.write('/dev/sda1 / ext4 errors=remount-ro 0 1\n')
+
+ 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)