Skip to content

Commit

Permalink
Merge pull request #212 from desultory/dev
Browse files Browse the repository at this point in the history
add option to randomize the build dir name
  • Loading branch information
desultory authored Feb 9, 2025
2 parents 93db60f + b115ef5 commit b079b97
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Modules write to a shared config dict that is accessible by other modules.
* `validate` (true) adds additional checks to verify the initramfs will work on the build host.
* `tmpdir` (/tmp) Sets the temporary directory as the base for the build and out dir.
* `build_dir` (initramfs_build) If relative, it will be placed under `tmpdir`, defines the build directory.
* `random_build_dir` (false) Adds a uuid to the end of the build fir name when true.
* `build_logging` (false) Enables additional logging during the build process.
* `make_nodes` (false) Create real device nodes in the build dir.
* `find_libgcc` (true) Automatically locates libgcc using ldconfig -p and adds it to the initramfs.
Expand Down
1 change: 1 addition & 0 deletions src/ugrd/base/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ timeout = "int" # The timeout for _run commands, defaults to 15 seconds
_custom_init_file = "str" # Add the _custom_init_file propety, used to set where the custom init file is located
tmpdir = "Path" # The base directory for builds
build_dir = "Path" # The directory where the initramfs is built
random_build_dir = "bool" # If true, a random build directory will be used
build_logging = "bool" # If true, additional build information will be logged to the console
_build_log_level = "int" # The level of logging to use for the build log, set to 10 by default and incremeted by if build_log is true (min 20)
symlinks = "dict" # Symlinks dict, defines the symlinks to be made in the initramfs
Expand Down
15 changes: 12 additions & 3 deletions src/ugrd/generator_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
from shutil import copy2
from subprocess import CompletedProcess, TimeoutExpired, run
from typing import Union
from uuid import uuid4

from zenlib.util import colorize, pretty_print

__version__ = "1.6.1"
__version__ = "1.6.2"
__author__ = "desultory"


_RANDOM_BUILD_ID = str(uuid4())


def get_subpath(path: Path, subpath: Union[Path, str]) -> Path:
"""Returns the subpath of a path."""
if not isinstance(subpath, Path):
Expand All @@ -33,8 +37,13 @@ def _get_out_path(self, path: Union[Path, str]) -> Path:
return get_subpath(get_subpath(self.tmpdir, self.out_dir), path)

def _get_build_path(self, path: Union[Path, str]) -> Path:
"""Returns the path relative to the build directory, under the tmpdir."""
return get_subpath(get_subpath(self.tmpdir, self.build_dir), path)
"""Returns the path relative to the build directory, under the tmpdir.
if random_build_dir is true, appends a uuid4() to the build directory."""
if self.random_build_dir:
build_dir = self.build_dir.with_name(self.build_dir.name + "-" + _RANDOM_BUILD_ID)
else:
build_dir = self.build_dir
return get_subpath(get_subpath(self.tmpdir, build_dir), path)

def _mkdir(self, path: Path, resolve_build=True) -> None:
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/cryptsetup_included_key.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ modules = [
out_dir = "initramfs_test"
test_memory = '2G'

random_build_dir = true

#kernel_version = "6.6.35-gentoo-dist"
#test_kernel = "/boot/vmlinuz-6.6.35-gentoo-dist"
cpio_compression = false
Expand Down

0 comments on commit b079b97

Please sign in to comment.