def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" assert firewall_type(system_context) == "iptables" location.set_description("Enable firewall") to_enable: typing.List[str] = [] if os.path.exists( system_context.file_name( "/usr/lib/systemd/system/iptables.service")): to_enable.append("iptables.service") if os.path.exists( system_context.file_name( "/usr/lib/systemd/system/ip6tables.service")): to_enable.append("ip6tables.service") if os.path.exists( system_context.file_name( "/usr/lib/systemd/system/iptables-restore.service")): to_enable.append("iptables-restore.service") self._execute( location, system_context, "systemd_enable", *to_enable, )
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" name = args[0] assert name directory = args[1] assert directory[0] == "/" full_directory = system_context.file_name(directory) usr_dir = f"/usr/lib/persistent{directory}" full_usr_dir = system_context.file_name(usr_dir) if not os.path.isdir(full_directory): return os.makedirs(dirname(full_usr_dir), exist_ok=True) if os.path.isdir(full_directory): shutil.move(full_directory, full_usr_dir) else: os.makedirs(full_usr_dir) os.symlink(usr_dir, full_directory) self._execute( location, system_context, "create", f"/usr/lib/tmpfiles.d/{name}.conf", f"L {directory} - - - - {usr_dir}\n", mode=0o644, )
def _install_debug_support( system_context: SystemContext, tmp: str, ): _install_shadow_file(tmp, system_context), for cmd in [ "/usr/bin/journalctl", "/usr/lib/systemd/systemd-sulogin-shell" "/usr/lib/systemd/system/rescue.target", "/usr/lib/systemd/system/rescue.service", ]: assert cmd[0] == "/" if os.path.isfile(system_context.file_name(cmd)): os.makedirs(os.path.join(tmp, os.path.dirname(cmd)), exist_ok=True) dest = os.path.join(tmp, cmd[1:]) if os.path.exists(dest): os.remove(dest) shutil.copy2( system_context.file_name(cmd), dest, follow_symlinks=False, )
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any ) -> None: """Execute command.""" work_directory = kwargs.get("work_directory", "/") source = system_context.file_name(os.path.join(work_directory, args[0])) to_outside = kwargs.get("to_outside", False) target = ( args[1] if to_outside else system_context.file_name(os.path.join(work_directory, args[1])) ) assert os.path.isabs(target) arguments = ["-cz"] if kwargs.get("compress", False) else ["-c"] run( self._binary(Binaries.TAR), *arguments, "-f", target, source, work_directory=work_directory )
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" if not os.path.exists( system_context.file_name( "/usr/lib/systemd/system/fontconfig-trigger.service") ) or not os.path.isfile(system_context.file_name("/usr/bin/fc-cache")): return run( "/usr/bin/fc-cache", chroot_helper=self._binary(Binaries.SYSTEMD_NSPAWN), chroot=system_context.fs_directory, ) self._execute( location, system_context, "persist_on_usr", "fontconfig-trigger", "/var/cache/fontconfig", ) os.remove( system_context.file_name( "/usr/lib/systemd/system/fontconfig-trigger.service")) os.remove( system_context.file_name( "/usr/lib/systemd/system/update-triggers.target.wants/fontconfig-trigger.service" ))
def _install_volatile_support( staging_area: str, system_context: SystemContext) -> typing.List[str]: shutil.copyfile( system_context.file_name( "/usr/lib/systemd/system/systemd-volatile-root.service"), os.path.join(staging_area, "usr/lib/systemd/system/systemd-volatile-root.service"), ) trace("Installed systemd-volatile-root.service") symlink( os.path.join( staging_area, "usr/lib/systemd/system/initrd.target.wants/systemd-volatile-root.service", ), "../systemd-volatile-root.service", ) # Installing binaries is not a good idea in general, as dependencies are not handled! # These binaries are probably safe: systemd binaries tend to have few dependencies and those # that are included are most likely already in the image due to other systemd binaries! shutil.copyfile( system_context.file_name("/usr/lib/systemd/systemd-volatile-root"), os.path.join(staging_area, "usr/lib/systemd/systemd-volatile-root"), ) os.chmod( os.path.join(staging_area, "usr/lib/systemd/systemd-volatile-root"), 0o755) trace("Installed systemd-volatile-root binary.") return []
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" old_base = system_context.file_name("/etc/systemd/system") + "/" new_base = system_context.file_name("/usr/lib/systemd/system") + "/" trace("walking:", old_base) for root, _dirs, files in os.walk(old_base): for f in files: full_path = os.path.join(root, f) trace("Checking", full_path) if os.path.islink(full_path): trace("Moving link", full_path) _move_symlink(location, system_context, old_base, new_base, full_path) else: trace("Moving file", full_path) _move_file(location, old_base, new_base, full_path) self._execute( location.next_line(), system_context, "remove", "/etc/systemd/system/*", recursive=True, force=True, )
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" ## validate package type: if system_context.substitution("CLRM_PACKAGE_TYPE", ""): raise GenerateError( "Trying to run swupd_init on a system that already has a CLRM_PACKAGE_TYPE defined." ) system_context.set_substitution("CLRM_PACKAGE_TYPE", "swupd") run( self._binary(Binaries.SWUPD), "autoupdate", f"--path={system_context.fs_directory}", "--disable", "--no-progress", returncode=28, ) # Setup update-helper so that swupd os-install will actually work: os.makedirs(system_context.file_name("/usr/bin")) with open(system_context.file_name("/usr/bin/update-helper"), "wb") as fd: fd.write( dedent( """\ #!/usr/bin/sh exit 0 """ ).encode("utf-8") ) os.chmod(system_context.file_name("/usr/bin/update-helper"), 0o755) run( self._binary(Binaries.SWUPD), "os-install", f"--path={system_context.fs_directory}", "--skip-optional", "--no-progress", ) location.set_description("Move systemd files into /usr") self._add_hook(location, system_context, "_teardown", "systemd_cleanup") with open(system_context.file_name("/usr/lib/os-release"), "r") as osr: for l in osr: l = l.strip() if l.startswith("BUILD_ID="): build_id = l[9:] verbose(f"Installed {build_id}.") system_context.set_substitution("DISTRO_VERSION_ID", build_id) system_context.set_substitution("DISTRO_VERSION", build_id) self._execute(location.next_line(), system_context, "create_os_release")
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" if not os.path.isfile( system_context.file_name( "/usr/lib/systemd/system/locale-archive-trigger.service" )) or not os.path.isfile( system_context.file_name("/usr/bin/localedef")): return run( "/usr/bin/localedef", "-i", "en_US", "-c", "-f", "UTF-8", "en_US.UTF-8", chroot_helper=self._binary(Binaries.SYSTEMD_NSPAWN), chroot=system_context.fs_directory, ) if os.path.isfile( system_context.file_name("/usr/lib/tmpfiles.d/var.conf")): self._execute( location, system_context, "sed", "/\\/var\\/cache\\/locale/ d", "/usr/lib/tmpfiles.d/var.conf", ) self._execute( location, system_context, "sed", "/\\/var\\/cache\\/locale/ d", "/usr/lib/tmpfiles.d/filesystem.conf", ) self._execute( location, system_context, "persist_on_usr", "locale-archive-trigger", "/var/cache/locale", ) os.remove( system_context.file_name( "/usr/lib/systemd/system/locale-archive-trigger.service"))
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" if system_context.substitution("ROOT_DEVICE") is None: GenerateError("ROOT_DEVICE must be set when creating EFI kernel.", location=location) output = args[0] kernel = kwargs.get("kernel", "") initrd_directory = kwargs.get( "initrd", os.path.join(system_context.boot_directory, "initrd-parts")) initrd_files = _get_initrd_parts(location, initrd_directory) cmdline_input = kwargs.get("commandline", "") osrelease_file = system_context.file_name("/usr/lib/os-release") efistub = system_context.file_name("/usr/lib/systemd/boot/efi/" "linuxx64.efi.stub") debug("{}: Kernel : {}.".format(self.name, kernel)) debug("{}: Initrd : {}.".format(self.name, ", ".join(initrd_files))) debug("{}: cmdline : {}.".format(self.name, cmdline_input)) debug("{}: osrelease: {}.".format(self.name, osrelease_file)) debug("{}: efistub : {}.".format(self.name, efistub)) self._validate_files(kernel, *initrd_files, osrelease_file, efistub) with tempfile.TemporaryDirectory() as tmp: initrd = _create_initrd(tmp, *initrd_files) cmdline = _create_cmdline_file(tmp, cmdline_input) run( self._binary(Binaries.OBJCOPY), "--add-section", ".osrel={}".format(osrelease_file), "--change-section-vma", ".osrel=0x20000", "--add-section", ".cmdline={}".format(cmdline), "--change-section-vma", ".cmdline=0x30000", "--add-section", ".linux={}".format(kernel), "--change-section-vma", ".linux=0x40000", "--add-section", ".initrd={}".format(initrd), "--change-section-vma", ".initrd=0x3000000", efistub, output, ) os.remove(initrd) os.remove(cmdline)
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" output = args[0] kernel = kwargs.get("kernel", "") initrd_directory = kwargs.get( "initrd", os.path.join(system_context.boot_directory, "initrd-parts") ) initrd_files = _get_initrd_parts(location, initrd_directory) cmdline_input = kwargs.get("commandline", "") osrelease_file = system_context.file_name("/usr/lib/os-release") efistub = system_context.file_name( "/usr/lib/systemd/boot/efi/" "linuxx64.efi.stub" ) debug(f"{self.name}: Kernel : {kernel}.") debug(f"{self.name}: Initrd : {initrd_files}.") debug(f"{self.name}: cmdline : {cmdline_input}.") debug(f"{self.name}: osrelease: {osrelease_file}.") debug(f"{self.name}: efistub : {efistub}.") self._validate_files(location, kernel, *initrd_files, osrelease_file, efistub) initrd = _create_initrd(system_context.boot_directory, *initrd_files) cmdline = _create_cmdline_file(system_context.boot_directory, cmdline_input) run( self._binary(Binaries.OBJCOPY), "--add-section", f".osrel={osrelease_file}", "--change-section-vma", ".osrel=0x20000", "--add-section", f".cmdline={cmdline}", "--change-section-vma", ".cmdline=0x30000", "--add-section", f".linux={kernel}", "--change-section-vma", ".linux=0x40000", "--add-section", f".initrd={initrd}", "--change-section-vma", ".initrd=0x3000000", efistub, output, )
def move_kernel(system_context: SystemContext, variant: str) -> str: vmlinuz = os.path.join(system_context.boot_directory, "vmlinuz") default_file = system_context.file_name( f"/usr/lib/kernel/default-{variant}") installed_kernel = os.path.join("/usr/lib/kernel", os.readlink(default_file)) os.remove(default_file) prefix = f"org.clearlinux.{variant}." version = os.path.basename(installed_kernel)[len(prefix):] shutil.copyfile(system_context.file_name(installed_kernel), vmlinuz) return version
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" charmap = kwargs.get("charmap", "UTF-8") locales_dir = system_context.file_name("/usr/share/locale") locales = [] for a in args: if not os.path.isdir(os.path.join( locales_dir, a)) and not os.path.isdir( os.path.join(locales_dir, a[0:2])): raise ParseError( f'Locale "{a}" not found in /usr/share/locale.', location=location, ) locales.append(f"{a}.{charmap} {charmap}\n") self._execute( location, system_context, "append", "/etc/locale.gen", "".join(locales), force=True, ) self._setup_hooks(location, system_context, locales)
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" modules = system_context.file_name("/usr/lib/modules") if not os.path.isdir(modules): return # No kernel installed, nothing to do. kernel_version = system_context.substitution_expanded( "KERNEL_VERSION", "") assert kernel_version location.set_description( f"Run depmod for kernel version {kernel_version}...") self._execute( location, system_context, "run", self._binary(Binaries.DEPMOD), "-a", "-b", system_context.fs_directory, kernel_version, )
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" location.set_description('Strip development files') self._add_hook(location, system_context, 'export', 'remove', '/usr/include/*', '/usr/src/*', '/usr/share/pkgconfig/*', '/usr/lib/pkgconfig/*', '/usr/share/aclocal/*', '/usr/lib/cmake/*', '/usr/share/gir-1.0/*', recursive=True, force=True) # Remove .so symlinks: directory = system_context.file_name('/usr/lib') for f in os.listdir(directory): fullname = os.path.join(directory, f) if fullname.endswith('/libnss_files.so'): continue if fullname.endswith('.a') \ or (fullname.endswith('.so') and os.path.islink(fullname)): os.unlink(fullname)
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" assert os.path.exists(system_context.file_name("/usr/bin/ldconfig")) location.set_description("Run ldconfig") self._add_hook( location, system_context, "export", "run", "/usr/bin/ldconfig", "-X", inside=True, ) location.set_description("Remove ldconfig data") # self._add_hook(location, system_context, # 'export', 'remove', '/usr/bin/ldconfig') location.set_description("Remove ldconfig related services") self._add_hook( location, system_context, "export", "remove", "/usr/lib/systemd/system/*/ldconfig.service", "/usr/lib/systemd/system/ldconfig.service", force=True, )
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" assert os.path.exists( system_context.file_name("/usr/bin/systemd-hwdb")) location.set_description("Update HWDB") self._add_hook( location, system_context, "export", "run", "/usr/bin/systemd-hwdb", "--usr", "update", inside=True, ) location.set_description("Remove HWDB data") self._add_hook(location, system_context, "export", "remove", "/usr/bin/systemd-hwdb") location.set_description("Remove HWDB related services") self._add_hook( location, system_context, "export", "remove", "/usr/lib/systemd/system/*/systemd-hwdb-update.service", "/usr/lib/systemd/system/systemd-hwdb-update.service", force=True, )
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" modules = system_context.file_name("/usr/lib/modules") if not os.path.isdir(modules): return # No kernel installed, nothing to do. for kver in [ f for f in os.listdir(modules) if os.path.isdir(os.path.join(modules, f)) ]: location.set_description( f"Run depmod for kernel version {kver}...") self._execute( location, system_context, "run", self._binary(Binaries.DEPMOD), "-a", "-b", system_context.fs_directory, kver, )
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" assert os.path.exists( system_context.file_name('/usr/bin/systemd-hwdb')) location.set_description('Update HWDB') self._add_hook(location, system_context, 'export', 'run', '/usr/bin/systemd-hwdb', '--usr', 'update', inside=True) location.set_description('Remove HWDB data') self._add_hook(location, system_context, 'export', 'remove', '/usr/bin/systemd-hwdb') location.set_description('Remove HWDB related services') self._add_hook(location, system_context, 'export', 'remove', '/usr/lib/systemd/system/*/' 'systemd-hwdb-update.service', '/usr/lib/systemd/system/' 'systemd-hwdb-update.service', force=True)
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" to_sign = args[0] keep_unsigned = kwargs.get("keep_unsigned", False) if not kwargs.get("outside", False): to_sign = system_context.file_name(to_sign) systems_directory = system_context.systems_definition_directory key = os.path.join(systems_directory, kwargs.get("key", "config/efi/sign.key")) cert = os.path.join(systems_directory, kwargs.get("cert", "config/efi/sign.crt")) info("Signing EFI binary {} using key {} and cert {}.".format( input, key, cert)) output = to_sign + ".signed" assert os.path.isfile(key) assert os.path.isfile(cert) assert os.path.isfile(to_sign) assert not os.path.exists(output) run( self._binary(Binaries.SBSIGN), "--key", key, "--cert", cert, "--output", output, to_sign, ) if not keep_unsigned: os.remove(to_sign) shutil.move(output, to_sign)
def move_initrds(system_context: SystemContext): initrd_parts = os.path.join(system_context.boot_directory, "initrd-parts") os.makedirs(initrd_parts, exist_ok=True) i915 = os.path.join(initrd_parts, "05-i915.cpio.xz") shutil.move( system_context.file_name("/usr/lib/initrd.d/00-intel-ucode.cpio"), os.path.join(initrd_parts, "00-intel-ucode.cpio"), ) shutil.move( system_context.file_name("/usr/lib/initrd.d/i915-firmware.cpio.xz"), i915) run("/usr/bin/xz", "-d", i915) os.rmdir(system_context.file_name("/usr/lib/initrd.d"))
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" if not os.path.exists(system_context.file_name("usr/bin/mkinitcpio")): info("Skipping initrd generation: No mkinitcpio binary.") return if not os.path.exists( os.path.join(system_context.boot_directory, "vmlinuz")): info("Skipping initrd generation: No vmlinuz in boot directory.") return self._vg = system_context.substitution("DEFAULT_VG", None) if not self._vg: self._vg = None self._image_fs = system_context.substitution("IMAGE_FS", "ext2") self._image_device = _deviceify( system_context.substitution("IMAGE_DEVICE", "")) self._image_options = system_context.substitution( "IMAGE_OPTIONS", "rw") name_prefix = system_context.substitution("DISTRO_ID", "clrm") name_version = system_context.substitution("DISTRO_VERSION_ID", system_context.timestamp) self._full_name = "{}_{}".format(name_prefix, name_version) initrd = args[0] to_clean_up = [] # type: typing.List[str] to_clean_up += "/boot/vmlinuz" to_clean_up += self._install_extra_binaries(location, system_context) to_clean_up += self._create_systemd_units(location, system_context) to_clean_up += self._install_mkinitcpio(location, system_context) to_clean_up += self._install_mkinitcpio_hooks(location, system_context) copy( system_context, os.path.join(system_context.boot_directory, "vmlinuz"), "/boot/vmlinuz", from_outside=True, ) run( "/usr/bin/mkinitcpio", "-p", "cleanroom", chroot=system_context.fs_directory, chroot_helper=self._binary(Binaries.CHROOT_HELPER), ) initrd_directory = os.path.dirname(initrd) os.makedirs(initrd_directory, exist_ok=True) move(system_context, "/boot/initramfs.img", initrd, to_outside=True) _cleanup_extra_files(location, system_context, *to_clean_up) self._remove_mkinitcpio(location, system_context) assert os.path.isfile(initrd)
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" pacman_report( system_context, system_context.file_name("/usr/lib/pacman"), pacman_command=self._binary(Binaries.PACMAN), )
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any ) -> None: """Execute command.""" run("/usr/bin/sed", "-i", "-e", args[0], system_context.file_name(args[1]))
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" location.set_description("Strip documentation files") to_remove = [ "/usr/share/doc/*", "/usr/share/gtk-doc/html", "/usr/share/help/*" ] if not os.path.exists(system_context.file_name("/usr/bin/man")): debug("No /usr/bin/man: Removing man pages.") to_remove += ["/usr/share/man/*"] if not os.path.exists(system_context.file_name("/usr/bin/info")): debug("No /usr/bin/info: Removing info pages.") to_remove += ["/usr/share/info/*"] self._execute(location, system_context, "remove", *to_remove, recursive=True, force=True)
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" location.set_description('Strip documentation files') to_remove = [ '/usr/share/doc/*', '/usr/share/gtk-doc/html', '/usr/share/help/*' ] if not os.path.exists(system_context.file_name('/usr/bin/man')): debug('No /usr/bin/man: Removing man pages.') to_remove += ['/usr/share/man/*'] if not os.path.exists(system_context.file_name('/usr/bin/info')): debug('No /usr/bin/info: Removing info pages.') to_remove += ['/usr/share/info/*'] self._execute(location, system_context, 'remove', *to_remove, recursive=True, force=True)
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" if not os.path.exists(system_context.file_name('usr/bin/mkinitcpio')): info('Skipping initrd generation: No mkinitcpio binary.') return if not os.path.exists( os.path.join(system_context.boot_directory, 'vmlinuz')): info('Skipping initrd generation: No vmlinuz in boot directory.') return self._vg = system_context.substitution('DEFAULT_VG', None) if not self._vg: self._vg = None self._image_fs = system_context.substitution('IMAGE_FS', 'ext2') self._image_device = \ _deviceify(system_context.substitution('IMAGE_DEVICE', '')) self._image_options = system_context.substitution( 'IMAGE_OPTIONS', 'rw') name_prefix = system_context.substitution('DISTRO_ID', 'clrm') name_version = system_context.substitution('DISTRO_VERSION_ID', system_context.timestamp) self._full_name = "{}_{}".format(name_prefix, name_version) initrd = args[0] to_clean_up = [] # type: typing.List[str] to_clean_up += '/boot/vmlinuz' to_clean_up += self._install_extra_binaries(location, system_context) to_clean_up += self._create_systemd_units(location, system_context) to_clean_up += self._install_mkinitcpio(location, system_context) to_clean_up += self._install_mkinitcpio_hooks(location, system_context) copy(system_context, os.path.join(system_context.boot_directory, 'vmlinuz'), '/boot/vmlinuz', from_outside=True) run('/usr/bin/mkinitcpio', '-p', 'cleanroom', chroot=system_context.fs_directory, chroot_helper=self._binary(Binaries.CHROOT_HELPER)) initrd_directory = os.path.dirname(initrd) os.makedirs(initrd_directory, exist_ok=True) move(system_context, '/boot/initramfs.img', initrd, to_outside=True) _cleanup_extra_files(location, system_context, *to_clean_up) self._remove_mkinitcpio(location, system_context) assert (os.path.isfile(initrd))
def _install_shadow_file(staging_area: str, system_context: SystemContext): for shadow_file in ( system_context.file_name("/etc/shadow.initramfs"), system_context.file_name( "/usr/share/defaults/etc/shadow.initramfs"), ): if os.path.exists(shadow_file): os.makedirs(os.path.join(staging_area, "etc"), exist_ok=True) shutil.copyfile( shadow_file, os.path.join( staging_area, "etc/shadow", ), ) os.chmod(os.path.join(staging_area, "etc/shadow"), 0o600) os.remove(shadow_file) trace( "Installed /etc/shadow.initramfs as /etc/shadow into initrd.")
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" work_directory = kwargs.get('work_directory', '/') source = system_context.file_name(os.path.join(work_directory, args[0])) to_outside = kwargs.get('to_outside', False) target = args[1] if to_outside \ else system_context.file_name(os.path.join(work_directory, args[1])) assert os.path.isabs(target) arguments = ['-cz'] if kwargs.get('compress', False) else ['-c'] run(self._binary(Binaries.TAR), *arguments, '-f', target, source, work_directory=work_directory)
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" if system_context.substitution('ROOT_DEVICE') is None: GenerateError('ROOT_DEVICE must be set when creating EFI kernel.', location=location) output = args[0] kernel = kwargs.get('kernel', '') initrd_directory \ = kwargs.get('initrd', os.path.join(system_context.boot_directory, 'initrd-parts')) initrd_files = _get_initrd_parts(location, initrd_directory) cmdline_input = kwargs.get('commandline', '') osrelease_file = system_context.file_name('/usr/lib/os-release') efistub = system_context.file_name('/usr/lib/systemd/boot/efi/' 'linuxx64.efi.stub') debug('{}: Kernel : {}.'.format(self.name, kernel)) debug('{}: Initrd : {}.'.format(self.name, ', '.join(initrd_files))) debug('{}: cmdline : {}.'.format(self.name, cmdline_input)) debug('{}: osrelease: {}.'.format(self.name, osrelease_file)) debug('{}: efistub : {}.'.format(self.name, efistub)) self._validate_files(kernel, *initrd_files, osrelease_file, efistub) with tempfile.TemporaryDirectory() as tmp: initrd = _create_initrd(tmp, *initrd_files) cmdline = _create_cmdline_file(tmp, cmdline_input) run(self._binary(Binaries.OBJCOPY), '--add-section', '.osrel={}'.format(osrelease_file), '--change-section-vma', '.osrel=0x20000', '--add-section', '.cmdline={}'.format(cmdline), '--change-section-vma', '.cmdline=0x30000', '--add-section', '.linux={}'.format(kernel), '--change-section-vma', '.linux=0x40000', '--add-section', '.initrd={}'.format(initrd), '--change-section-vma', '.initrd=0x3000000', efistub, output) os.remove(initrd) os.remove(cmdline)