def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" etc = "/etc" localtime = "localtime" etc_localtime = etc + "/" + localtime timezone = args[0] full_timezone = "../usr/share/zoneinfo/" + timezone if not exists(system_context, full_timezone, work_directory=etc): raise GenerateError( f'Timezone "{timezone}" not found when trying to set timezone.', location=location, ) self._execute(location, system_context, "remove", etc_localtime) self._execute( location.next_line(), system_context, "symlink", full_timezone, localtime, work_directory="/etc", )
def _check_or_create_directory(self, location: Location, system_context: SystemContext, directory: str, **kwargs: typing.Any) -> None: if not exists(system_context, directory): makedirs(system_context, directory, **kwargs) return if not isdir(system_context, directory): raise GenerateError( '"{}" needs directory "{}", but that exists and is not a directory.' .format(self.name, directory), location=location)
def _persistent_known_hosts(self, location: Location, system_context: SystemContext) -> None: if not exists(system_context, "/usr/lib/tmpfiles.d/ssh.conf"): create_file( system_context, "/usr/lib/tmpfiles.d/ssh.conf", textwrap.dedent("""\ d /var/etc/ssh 644 root root - - f /var/etc/ssh/ssh_known_hosts 644 root root - L /etc/ssh/ssh_known_hosts - - - - /var/etc/ssh/ssh_known_hosts """).encode("utf-8"), mode=0o644, )
def _check_or_create_directory( self, location: Location, system_context: SystemContext, directory: str, **kwargs: typing.Any, ) -> None: if not exists(system_context, directory): self._execute(location.next_line(), system_context, "mkdir", directory, **kwargs) return if not isdir(system_context, directory): raise GenerateError( f'"{self.name}" needs directory "{directory}", but that exists and is not a directory.', location=location, )
def _create_root_tarball(self, location: Location, system_context: SystemContext) -> None: tarball = 'usr/lib/boot/root-fs.tar' os.makedirs(system_context.file_name('/usr/lib/boot')) if exists(system_context, tarball): raise GenerateError( '"{}": Root tarball "{}" already exists.'.format( self.name, tarball), location=location) run(self._binary(Binaries.TAR), '-cf', tarball, '--sort=name', 'etc', 'root', work_directory=system_context.fs_directory)
def _create_root_tarball(self, location: Location, system_context: SystemContext) -> None: tarball = "usr/lib/boot/root-fs.tar" os.makedirs(system_context.file_name("/usr/lib/boot")) if exists(system_context, tarball): raise GenerateError( f'"{self.name}": Root tarball "{tarball}" already exists.', location=location, ) run( self._binary(Binaries.TAR), "-cf", tarball, "--sort=name", "etc", "root", work_directory=system_context.fs_directory, )
def __call__( self, location: Location, system_context: SystemContext, *args: typing.Any, **kwargs: typing.Any, ) -> None: """Execute command.""" system = args[0] description = kwargs.get("description", "") after_input = kwargs.get("after", "") requires_input = kwargs.get("requires", "") timeout = kwargs.get("timeout", "3m") enable = kwargs.get("enable", False) bin_directory = "/usr/bin" systemd_directory = "/usr/lib/systemd/system" location.set_description("Update update-all-containers.sh") updater_script = os.path.join(bin_directory, "update-all-containers.sh") if not exists(system_context, updater_script): self._execute( location.next_line(), system_context, "create", updater_script, "#!/usr/bin/bash\n", ) self._execute( location.next_line(), system_context, "append", updater_script, '/usr/bin/update-container.sh "{}" || exit 1\n', ) location.set_description("") if not os.path.isdir(system_context.file_name(systemd_directory)): os.makedirs(system_context.file_name(systemd_directory)) override_dir = f"{systemd_directory}/systemd-nspawn@{system}.service.d" self._execute(location.next_line(), system_context, "mkdir", override_dir) after = _nspawn_ify("After", *after_input.split(",")) requires = _nspawn_ify("Requires", *requires_input.split(",")) self._execute( location.next_line(), system_context, "create", f"{override_dir}/override.conf", textwrap.dedent(f"""\ [Unit] Description=Container {system}: {description}{after}{requires} [Service] TimeoutStartSec={timeout} """), ) if enable: location.set_description("Enabling container") self._execute( location.next_line(), system_context, "symlink", "../[email protected]", f"systemd-nspawn@{system}.service", work_directory=f"{systemd_directory}/machines.target.wants", )