def _run(self): if os.path.isfile(self._result()): logging.info( ("{0} is already there. " "Delete it to regenerate it.").format(self._result())) return self._result() self._require_sudo() qemu_executable = Fetch().run(self.config.get_base_config_file()) print("Going to bootstrap initial image - be patient.") if self.config.get_bootstrap_tool() != "debootstrap": raise FatalError(("At the moment only debootstrap " "is supported for bootstrapping!")) workdir = get_workdir() with tempfile.TemporaryDirectory(dir=workdir) as tempdir: chown_to_user(tempdir) key_data = fetch_repository_key( self.config.get_bootstrap_repository_key()) keyring_file = build_keyring(tempdir, "temp_keyring.gpg", key_data) rootfs = self._run_debootstrap(tempdir, keyring_file, qemu_executable) self._postprocess_rootfs(rootfs, key_data) archive = self._pack_image(tempdir, rootfs) chown_to_user(archive) create_artifact_dir() shutil.move(archive, self._result()) print_success("Bootstrapped initial image {}.".format(self._result())) return self._result()
def download(self, package_name=None, dest='/tmp'): if not package_name: raise FatalError('Missing argument package_name!') with tempfile.TemporaryDirectory() as tempdir: inrelease_data = self._try_fetch_archive_element( self._get_release_file_url('InRelease')) release_file = os.path.join(tempdir, 'InRelease') signature_file = None if inrelease_data: with open(release_file, mode='wb') as f: f.write(inrelease_data) else: release_file = os.path.join(tempdir, 'Release') signature_file = os.path.join(tempdir, 'Release.gpg') release_data = self._fetch_archive_element( self._get_release_file_url('Release')) with open(release_file, mode='wb') as f: f.write(release_data) if self._repository_key: signature_data = self._fetch_archive_element( self._get_release_file_url('Release.gpg')) with open(signature_file, mode='wb') as f: f.write(signature_data) if self._repository_key: key_data = fetch_repository_key(self._repository_key) keyring = build_keyring(tempdir, 'trusted.gpg', key_data) self._verify_signature(tempdir, keyring, release_file, signature_file) else: logging.warning( 'Package {} will get downloaded without verification!'. format(package_name)) package_files = self._parse_release_file(release_file) requested_package = self._find_package_in_package_files( package_name, package_files) if not requested_package: raise FatalError( ("Package '{}' not found in repository '{}'.").format( package_name, self._source.uri)) else: result = self._download_package(requested_package, dest) return result