def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" self._execute(location, system_context, 'pacman', 'xorg-server', 'xorg-server-xwayland') # Copy snippets from systems config folder: copy(system_context, self._config_directory(system_context) + '/*', '/etc/X11/xorg.conf.d', from_outside=True, recursive=True) chown(system_context, 0, 0, '/etc/X11/xorg.conf.d/*') chmod(system_context, 0o644, '/etc/X11/xorg.conf.d/*') create_file(system_context, '/etc/X11/xinit/xinitrc.d/99-access-to-user.sh', textwrap.dedent('''\ #!/usr/bin/bash # Allow local access for the user: xhost "+local:$$USER" ''').encode('utf-8'), mode=0o755) # Install some extra fonts: self._execute(location.next_line(), system_context, 'pkg_fonts')
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" if not os.path.exists( os.path.join(system_context.boot_directory, "vmlinuz")): info("Skipping initrd generation: No vmlinuz in boot directory.") return initrd = args[0] copy( system_context, os.path.join(system_context.boot_directory, "vmlinuz"), "/boot/vmlinuz", from_outside=True, ) # Use pre-created initrs if possible! pre_created = os.path.join(system_context.initrd_parts_directory, "50-clr") assert os.path.exists(pre_created) if pre_created != initrd: shutil.copyfile(pre_created, initrd) assert os.path.isfile(initrd)
def __call__(self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any) -> None: """Execute command.""" self._execute(location, system_context, "pacman", "xorg-server", "xorg-server-xwayland") # Copy snippets from systems config folder: copy( system_context, self._config_directory(system_context) + "/*", "/etc/X11/xorg.conf.d", from_outside=True, recursive=True, ) chown(system_context, 0, 0, "/etc/X11/xorg.conf.d/*") chmod(system_context, 0o644, "/etc/X11/xorg.conf.d/*") create_file( system_context, "/etc/X11/xinit/xinitrc.d/99-access-to-user.sh", textwrap.dedent("""\ #!/usr/bin/bash # Allow local access for the user: xhost "+local:$$USER" """).encode("utf-8"), mode=0o755, ) # Install some extra fonts: self._execute(location.next_line(), system_context, "pkg_fonts")
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 test_file_with_extension_to_dir_copy( populated_system_context: SystemContext, ) -> None: fs = populated_system_context.fs_directory filehelper.copy(populated_system_context, "/home/test/example.txt", "/etc") assert (_read_file(os.path.join( fs, "home/test/example.txt")) == "/home/test/example.txt") assert _read_file(os.path.join( fs, "etc/example.txt")) == "/home/test/example.txt"
def test_file_with_extension_to_dir_copy( populated_system_context: SystemContext) -> None: fs = populated_system_context.fs_directory filehelper.copy(populated_system_context, '/home/test/example.txt', '/etc') assert _read_file(os.path.join(fs, 'home/test/example.txt')) \ == '/home/test/example.txt' assert _read_file(os.path.join(fs, 'etc/example.txt')) \ == '/home/test/example.txt'
def test_file_to_overwrite_file_copy( populated_system_context: SystemContext) -> None: fs = populated_system_context.fs_directory filehelper.copy(populated_system_context, "/usr/bin/ls", "/etc/passwd", force=True) assert _read_file(os.path.join(fs, "usr/bin/ls")) == "/usr/bin/ls" assert _read_file(os.path.join(fs, "etc/passwd")) == "/usr/bin/ls"
def test_dir_to_dir_recursive_copy( populated_system_context: SystemContext) -> None: fs = populated_system_context.fs_directory filehelper.copy(populated_system_context, "/usr/bin", "/home", recursive=True) assert _read_file(os.path.join(fs, "usr/bin/ls")) == "/usr/bin/ls" assert _read_file(os.path.join(fs, "home/bin/ls")) == "/usr/bin/ls"
def test_dir_to_dir_recursive_copy( populated_system_context: SystemContext) -> None: fs = populated_system_context.fs_directory filehelper.copy(populated_system_context, '/usr/bin', '/home', recursive=True) assert _read_file(os.path.join(fs, 'usr/bin/ls')) == '/usr/bin/ls' assert _read_file(os.path.join(fs, 'home/bin/ls')) == '/usr/bin/ls'
def test_file_to_overwrite_file_copy( populated_system_context: SystemContext) -> None: fs = populated_system_context.fs_directory filehelper.copy(populated_system_context, '/usr/bin/ls', '/etc/passwd', force=True) assert _read_file(os.path.join(fs, 'usr/bin/ls')) == '/usr/bin/ls' assert _read_file(os.path.join(fs, 'etc/passwd')) == '/usr/bin/ls'
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any ) -> None: """Execute command.""" copy(system_context, *args, **kwargs)
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 _copy_extra_file(self, location: Location, system_context: SystemContext, extra_file: str) -> str: location.set_description( "Installing extra mkinitcpio file {}".format(extra_file)) helper_directory = self._helper_directory assert helper_directory source_path = os.path.join(helper_directory, extra_file) dest_path = os.path.join("/usr/bin", extra_file) copy(system_context, source_path, dest_path, from_outside=True) chmod(system_context, 0o755, dest_path) return dest_path
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" if not os.path.exists(os.path.join(system_context.boot_directory, "vmlinuz")): info("Skipping initrd generation: No vmlinuz in boot directory.") return initrd = args[0] self._install_dracut(location, system_context) copy( system_context, os.path.join(system_context.boot_directory, "vmlinuz"), "/boot/vmlinuz", from_outside=True, ) dracut_args: typing.List[str] = [] kernel_version = system_context.substitution_expanded("KERNEL_VERSION", "") assert kernel_version run( "/usr/bin/dracut", *dracut_args, "--no-early-microcode", "--no-hostonly", "--no-compress", "--reproducible", "--omit", "iscsi nbd network network-legacy nfs qemu qemu-net stratis", "--add", "busybox", "/boot/initramfs.img", kernel_version, chroot=system_context.fs_directory, chroot_helper=self._binary(Binaries.SYSTEMD_NSPAWN), ) initrd_directory = os.path.dirname(initrd) os.makedirs(initrd_directory, exist_ok=True) move(system_context, "/boot/initramfs.img", initrd, to_outside=True) self._remove_dracut(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.""" if not os.path.exists( os.path.join(system_context.boot_directory, "vmlinuz")): info("Skipping initrd generation: No vmlinuz in boot directory.") return initrd = args[0] to_clean_up: typing.List[str] = [] to_clean_up += "/boot/vmlinuz" to_clean_up += self._install_mkinitcpio(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.SYSTEMD_NSPAWN), ) 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 test_dir_to_file_copy(populated_system_context: SystemContext) -> None: with pytest.raises(IsADirectoryError): filehelper.copy(populated_system_context, "/usr/bin", "/etc/foo")
def test_file_to_file_copy(populated_system_context: SystemContext) -> None: fs = populated_system_context.fs_directory filehelper.copy(populated_system_context, "/usr/bin/ls", "/etc/foo") assert _read_file(os.path.join(fs, "usr/bin/ls")) == "/usr/bin/ls" assert _read_file(os.path.join(fs, "etc/foo")) == "/usr/bin/ls"
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" if not os.path.exists(os.path.join(system_context.boot_directory, "vmlinuz")): info("Skipping initrd generation: No vmlinuz in boot directory.") return initrd = args[0] self._install_dracut(location, system_context) copy( system_context, os.path.join(system_context.boot_directory, "vmlinuz"), "/boot/vmlinuz", from_outside=True, ) dracut_args: typing.List[str] = [] modules = ( system_context.substitution_expanded("INITRD_EXTRA_MODULES", "") .replace(",", " ") .replace(" ", " ") .split(" ") ) modules = list(set(modules)) modules.sort() if modules: dracut_args += [ "--add-drivers", " ".join(modules), ] run( "/usr/bin/dracut", *dracut_args, "--no-early-microcode", "--no-hostonly", "--no-compress", "--reproducible", "--omit", "iscsi nbd network network-legacy nfs qemu qemu-net stratis", "--add", "busybox", "/boot/initramfs.img", 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) self._remove_dracut(location, system_context) assert os.path.isfile(initrd)
def test_same_file_copy(populated_system_context: SystemContext) -> None: with pytest.raises(OSError): filehelper.copy(populated_system_context, "/usr/bin/ls", "/usr/bin/ls")
def test_file_to_dir_copy(populated_system_context: SystemContext) -> None: fs = populated_system_context.fs_directory filehelper.copy(populated_system_context, '/usr/bin/ls', '/etc') assert _read_file(os.path.join(fs, 'usr/bin/ls')) == '/usr/bin/ls' assert _read_file(os.path.join(fs, 'etc/ls')) == '/usr/bin/ls'
def test_file_to_existing_file_copy( populated_system_context: SystemContext) -> None: with pytest.raises(OSError): filehelper.copy(populated_system_context, '/usr/bin/ls', '/etc/passwd')
def test_same_file_in_parent_copy( populated_system_context: SystemContext) -> None: with pytest.raises(AssertionError): filehelper.copy(populated_system_context, '/usr/bin/ls', '/usr/bin')
def test_same_file_different_path_copy( populated_system_context: SystemContext) -> None: with pytest.raises(OSError): filehelper.copy(populated_system_context, '/usr/bin/ls', '/usr/../usr/bin/ls')
def test_dir_to_dir_copy(populated_system_context: SystemContext) -> None: with pytest.raises(IsADirectoryError): filehelper.copy(populated_system_context, '/usr/bin', '/home')