def _postprocess_rootfs(self, rootfs, key_data): if key_data: key_cmd = get_chroot_cmd(rootfs) key_cmd.append("apt-key") key_cmd.append("add") key_cmd.append("-") run(key_cmd, input=key_data, sudo=True) clean_cmd = get_chroot_cmd(rootfs) clean_cmd.append("apt-get") clean_cmd.append("clean") run(clean_cmd, sudo=True) apt_list_cmd = get_chroot_cmd(rootfs) apt_list_cmd.append("rm") apt_list_cmd.append("-rf") apt_list_cmd.append("/var/lib/apt/lists/") run(apt_list_cmd, sudo=True) # after a cross debootstrap /etc/apt/sources.list points # to the wrong repository sources_list = os.path.join(rootfs, 'etc', 'apt', 'sources.list') with open(sources_list, mode='w', encoding='utf-8') as f: f.write(('# edi bootstrap repository\n{}\n').format( self.config.get_bootstrap_repository()))
def _run_debootstrap(self, tempdir, keyring_file, qemu_executable): # Ansible uses python on the target system # sudo is needed for privilege escalation additional_packages = ( "python,sudo,netbase,net-tools,iputils-ping,ifupdown,isc-dhcp-client," "resolvconf,systemd,systemd-sysv,gnupg") rootfs = os.path.join(tempdir, "rootfs") bootstrap_source = SourceEntry(self.config.get_bootstrap_repository()) components = ",".join(bootstrap_source.comps) cmd = [] cmd.append("debootstrap") cmd.append("--arch={0}".format( self.config.get_bootstrap_architecture())) if qemu_executable: cmd.append("--foreign") cmd.append("--variant=minbase") cmd.append("--include={0}".format(additional_packages)) cmd.append("--components={0}".format(components)) if keyring_file: cmd.append("--force-check-gpg") cmd.append("--keyring={0}".format(keyring_file)) cmd.append(bootstrap_source.dist) cmd.append(rootfs) cmd.append(bootstrap_source.uri) run(cmd, sudo=True) if qemu_executable: qemu_target_path = os.path.join(rootfs, "usr", "bin") shutil.copy(qemu_executable, qemu_target_path) second_stage_cmd = get_chroot_cmd(rootfs) second_stage_cmd.append("/debootstrap/debootstrap") second_stage_cmd.append("--second-stage") run(second_stage_cmd, sudo=True) return rootfs
def _run_debootstrap(self, tempdir, keyring_file, qemu_executable): additional_packages = ','.join( self.config.get_bootstrap_additional_packages()) rootfs = os.path.join(tempdir, "rootfs") bootstrap_source = SourceEntry(self.config.get_bootstrap_repository()) components = ",".join(bootstrap_source.comps) cmd = list() cmd.append("debootstrap") cmd.append("--arch={0}".format( self.config.get_bootstrap_architecture())) if qemu_executable: cmd.append("--foreign") cmd.append("--variant=minbase") cmd.append("--include={0}".format(additional_packages)) cmd.append("--components={0}".format(components)) if keyring_file: cmd.append("--force-check-gpg") cmd.append("--keyring={0}".format(keyring_file)) cmd.append(bootstrap_source.dist) cmd.append(rootfs) cmd.append(bootstrap_source.uri) run(cmd, sudo=True, log_threshold=logging.INFO, env=ProxySetup().get_environment()) if qemu_executable: qemu_target_path = os.path.join(rootfs, "usr", "bin") shutil.copy(qemu_executable, qemu_target_path) second_stage_cmd = get_chroot_cmd(rootfs) second_stage_cmd.append("/debootstrap/debootstrap") second_stage_cmd.append("--second-stage") run(second_stage_cmd, sudo=True, log_threshold=logging.INFO) return rootfs