forked from osbuild/osbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
org.osbuild.dracut.conf
executable file
·66 lines (50 loc) · 1.94 KB
/
org.osbuild.dracut.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python3
import sys
import osbuild.api
def bool_to_string(value):
return "yes" if value else "no"
# Writes to a given file option with the following format:
# persistent_policy="<policy>"
def string_option_writer(f, option, value):
f.write(f'{option}="{value}"\n')
# Writes to a given file option with the following format:
# add_dracutmodules+=" <dracut modules> "
def list_option_writer(f, option, value):
value_str = " ".join(value)
f.write(f'{option}+=" {value_str} "\n')
# Writes to a given file option with the following format:
# reproducible="{yes|no}"
def bool_option_writer(f, option, value):
f.write(f'{option}="{bool_to_string(value)}"\n')
def main(tree, options):
config = options["config"]
filename = options["filename"]
config_files_dir = f"{tree}/usr/lib/dracut/dracut.conf.d"
SUPPORTED_OPTIONS = {
# simple string options
"compress": string_option_writer,
# list options
"add_dracutmodules": list_option_writer,
"dracutmodules": list_option_writer,
"omit_dracutmodules": list_option_writer,
"drivers": list_option_writer,
"add_drivers": list_option_writer,
"omit_drivers": list_option_writer,
"force_drivers": list_option_writer,
"filesystems": list_option_writer,
"install_items": list_option_writer,
# bool options
"early_microcode": bool_option_writer,
"reproducible": bool_option_writer
}
with open(f"{config_files_dir}/{filename}", "w", encoding="utf8") as f:
for option, value in config.items():
try:
writter_func = SUPPORTED_OPTIONS[option]
writter_func(f, option, value)
except KeyError as e:
raise ValueError(f"unsupported configuration option '{option}'") from e
if __name__ == '__main__':
args = osbuild.api.arguments()
r = main(args["tree"], args["options"])
sys.exit(r)