Skip to content

Commit 4d1a95a

Browse files
committed
added copies function, improved docs
Signed-off-by: Zen <[email protected]>
1 parent 123a5a3 commit 4d1a95a

File tree

7 files changed

+64
-21
lines changed

7 files changed

+64
-21
lines changed

readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ Modules write to a shared config dict that is accessible by other modules.
5959
* `binaries` is a list used to define programs to be pulled into the initrams. `which` is used to find the path of added entries, and `lddtree` is used to resolve dependendies.
6060
* `paths` is a list of directores to create in the `build_dir`. They do not need a leading `/`.
6161

62+
##### symlink creation
63+
64+
Symlinks are defined in the `symlinks` dict. Each entry must have a name, `source` and `target`:
65+
66+
```
67+
[symlinks.pinentry]
68+
source = "/usr/bin/pinentry-tty"
69+
target = "/usr/bin/pinentry"
70+
```
71+
72+
73+
##### Copying files to a different destination
74+
75+
Using the `dependencies` list will pull files into the initramfs using the same path on the host system.
76+
77+
To copy files to a different path:
78+
79+
```
80+
[copies.my_key]
81+
source = "/home/larry/.gnupg/pubkey.gpg"
82+
destination = "/etc/ugrd/pub.gpg"
83+
```
84+
6285
##### Device node creation
6386

6487
Device nodes can be created by defining them in the `nodes` dict using the following keys:

ugrd/base/core.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '1.0.0'
2+
__version__ = '1.0.1'
33

44
from pathlib import Path
55

@@ -38,6 +38,15 @@ def deploy_dependencies(self):
3838
self._copy(dependency)
3939

4040

41+
def deploy_copies(self):
42+
"""
43+
Copiues everything from self.config_dict['copies'] into the build directory
44+
"""
45+
for copy_name, copy_parameters in self.config_dict['copies'].items():
46+
self.logger.debug("[%s] Copying: %s" % (copy_name, copy_parameters))
47+
self._copy(copy_parameters['source'], copy_parameters['destination'])
48+
49+
4150
def deploy_symlinks(self):
4251
"""
4352
Creates symlinks for all symlinks in self.config_dict['symlinks']
@@ -98,10 +107,24 @@ def _process_dependencies_multi(self, dependency):
98107
self['dependencies'].append(dependency)
99108

100109

110+
def _process_copies_multi(self, copy_name, copy_parameters):
111+
"""
112+
Processes a copy from the copies parameter
113+
Ensures the source and target are defined in the parameters.
114+
"""
115+
self.logger.debug("[%s] Processing copy: %s" % (copy_name, copy_parameters))
116+
if 'source' not in copy_parameters:
117+
raise ValueError("[%s] No source specified" % copy_name)
118+
if 'destination' not in copy_parameters:
119+
raise ValueError("[%s] No target specified" % copy_name)
120+
121+
self['copies'][copy_name] = copy_parameters
122+
123+
101124
def _process_symlinks_multi(self, symlink_name, symlink_parameters):
102125
"""
103126
Processes a symlink,
104-
Ensuures the source and target are defined in the parameters.
127+
Ensures the source and target are defined in the parameters.
105128
"""
106129
self.logger.debug("[%s] Processing symlink: %s" % (symlink_name, symlink_parameters))
107130
if 'source' not in symlink_parameters:

ugrd/base/core.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ minor = 1
1010

1111
[imports.config_processing]
1212
"ugrd.base.core" = [ "_process_binaries_multi",
13-
"_process_dependencies_multi",
13+
"_process_dependencies_multi",
14+
"_process_copies_multi",
1415
"_process_symlinks_multi",
1516
"_process_file_owner",
1617
"_process_nodes_multi"
1718
]
1819

1920
[imports.build_tasks]
20-
"ugrd.base.core" = [ "deploy_dependencies", "deploy_symlinks", "deploy_nodes" ]
21+
"ugrd.base.core" = [ "deploy_dependencies", "deploy_copies", "deploy_nodes", "deploy_symlinks" ]
2122

2223
[custom_parameters]
2324
binaries = "NoDupFlatList" # Binaries which should be included in the intiramfs, dependencies resolved with lddtree
2425
dependencies = "NoDupFlatList" # Add the dependencies property, used to define the dependencies of the initramfs
2526
symlinks = "dict" # Add the symlinks property, used to define the symlinks to be made in the initramfs
27+
copies = "dict" # Add the copies property, used to define the files to be copied to the initramfs
2628
nodes = "dict" # Add the nodes property, used to define the device nodes to be created
2729
paths = "NoDupFlatList" # Paths to be copied to the initramfs
2830
build_dir = "Path" # The directory where the initramfs is built

ugrd/crypto/cryptsetup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__author__ = 'desultory'
22

3-
__version__ = '0.5.0'
3+
__version__ = '0.5.2'
44

55

66
CRYPTSETUP_PARAMETERS = ['key_type', 'partuuid', 'uuid', 'key_file', 'header_file']
@@ -83,9 +83,9 @@ def crypt_init(self):
8383
return out
8484

8585

86-
def copy_libgcc(self):
86+
def find_libgcc(self):
8787
"""
88-
Copies libgcc_s.so
88+
Finds libgcc.so, adds a copies item for it.
8989
"""
9090
from subprocess import run
9191
from pathlib import Path
@@ -95,5 +95,4 @@ def copy_libgcc(self):
9595
source_path = Path(libgcc.partition('=> ')[-1])
9696
self.logger.debug("Source path for libgcc_s: %s" % source_path)
9797

98-
self._copy(source_path, f"/lib64/{source_path.name}")
99-
98+
self.config_dict['copies']['libgcc_s'] = {'source': source_path, 'destination': Path('/lib64/')}

ugrd/crypto/cryptsetup.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ _kmod_depend = [ "dm_crypt", "crc32c" ]
1515
[imports.init_late]
1616
"ugrd.crypto.cryptsetup" = [ "crypt_init" ]
1717

18-
[imports.build_tasks]
19-
"ugrd.crypto.cryptsetup" = [ "copy_libgcc" ]
18+
[imports.build_pre]
19+
"ugrd.crypto.cryptsetup" = [ "find_libgcc" ]
2020

2121
[custom_parameters]
2222
cryptsetup = "dict" # Dict of cryptsetup volume to be unlocked, keyed by mapped device name

ugrd/crypto/gpg.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__author__ = 'desultory'
22

3-
__version__ = '0.3.0'
3+
__version__ = '0.3.1'
44

55

66
def fetch_keys(self):
@@ -23,14 +23,6 @@ def import_keys(self):
2323
return f"gpg --import {self.config_dict['gpg_public_key']}"
2424

2525

26-
def symlink_pinentry(self):
27-
"""
28-
Symlink pinentry
29-
"""
30-
pinentry = self.config_dict.get('pinentry', 'pinentry-tty')
31-
return f"ln -s /usr/bin/{pinentry} /usr/bin/pinentry"
32-
33-
3426
def start_agent(self):
3527
"""
3628
Start the GPG agent

ugrd/initramfs_generator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
__author__ = "desultory"
3-
__version__ = "0.7.3"
3+
__version__ = "0.7.4"
44

55
from tomllib import load
66
from pathlib import Path
@@ -291,6 +291,10 @@ def _copy(self, source, dest=None, in_build_dir=True):
291291

292292
if dest_path.is_file():
293293
self.logger.warning("File already exists: %s" % dest_path)
294+
elif dest_path.is_dir():
295+
self.logger.debug("Destination is a directory, adding source filename: %s" % source.name)
296+
dest_path = dest_path / source.name
297+
294298
self.logger.info("Copying '%s' to '%s'" % (source, dest_path))
295299
copy2(source, dest_path)
296300

0 commit comments

Comments
 (0)