forked from killermoehre/fedIPA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkosi.build
executable file
·141 lines (129 loc) · 4.35 KB
/
mkosi.build
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
# vim: smarttab:expandtab:ts=4:sw=4:ft=python
from os import environ
from subprocess import run
from pathlib import Path
import venv
import rpm
output_dir: Path = Path(environ["BUILDDIR"])
virtual_env_dir: Path = Path("/ipa")
python_bin_dir: Path = Path(virtual_env_dir, "bin/python3")
dracut_module_dir: Path = Path(
"/usr/lib/dracut/modules.d/49ironic-python-agent"
)
dracut_module_setup_script: Path = Path(dracut_module_dir, "module-setup.sh")
# even though pip is a python module, the preferred interface is via the CLI
pip: list = [python_bin_dir, "-m", "pip"]
# get some information about the system we're running on
os_release: Path = Path("/etc/os-release")
if not os_release.exists():
os_release: Path = Path("/usr/lib/os-release")
os_release_env: dict = {}
with os_release.open("r") as f:
for line in f:
(key, seperator, value) = line.partition("=")
os_release_env[key.strip()]: str = value.strip()
tinyipa_initramfs: Path = Path(
output_dir, "tinyipa.{}.initramfs".format(os_release_env["ID"])
)
tinyipa_kernel: Path = Path(
output_dir, "tinyipa.{}.kernel".format(os_release_env["ID"])
)
# only one kernel will be installed.
# we need this variable to instruct dracut not to use `uname`,
# as this returns the wrong value in a container
for hdr in rpm.TransactionSet().dbMatch("name", "kernel"):
kernel_version: str = "{}-{}.{}".format(
hdr[rpm.RPMTAG_VERSION], hdr[rpm.RPMTAG_RELEASE], hdr[rpm.RPMTAG_ARCH]
)
kernel_path: Path = Path("/usr/lib/modules", kernel_version, "vmlinuz")
# creating the virtual env to install IPA into
environ["VIRTUAL_ENV"]: str = str(virtual_env_dir)
venv.create(virtual_env_dir, clear=True, symlinks=True, with_pip=True)
# install the wanted application from upstream
run(
pip
+ [
"install",
"--ignore-installed",
"--no-warn-script-location",
"ironic-python-agent",
],
check=True,
)
# create dracut module-setup.sh file with the proper file list
dracut_module_dir.mkdir(parents=True, exist_ok=True)
with dracut_module_setup_script.open("w") as dracut_setup:
# write the header of the file
dracut_setup.write(
"""#!/bin/bash
function check() {
require_binaries qemu-img \\
dd \\
sgdisk \\
blockdev \\
wipefs \\
parted \\
partprobe \\
efibootmgr \\
findfs \\
lshw \\
hdparm \\
smartctl
return 0
}
function depends() {
echo python
echo dbus-broker
echo systemd-initrd
echo systemd-networkd
echo bash
echo mdraid
echo iscsi
echo debug
echo base
return 0
}
"""
)
dracut_setup.write(
"""function install() {
inst_multiple qemu-img dd sgdisk blockdev wipefs
inst_multiple parted partprobe efibootmgr findfs lshw hdparm smartctl
"""
)
for venv_file in virtual_env_dir.rglob("*"):
dracut_setup.write(" inst '{}'\n".format(str(venv_file)))
dracut_setup.write(
""" inst_simple "${moddir}/ironic-python-agent.service" \\
"${systemdsystemunitdir}/ironic-python-agent.service"
systemctl -q --root "$initdir" enable ironic-python-agent.service
systemctl -q --root "$initdir" set-default multi-user.target
}
"""
)
# create the initramfs
dracut_options: list = []
dracut_options.append("/usr/bin/dracut")
dracut_options.append("--verbose")
dracut_options.append("--force")
dracut_options.extend(["--kver", kernel_version])
dracut_options.extend(["--modules", "bash systemd ironic-python-agent"])
dracut_options.extend(
["--install", "/etc/systemd/network/all-links-dhcp.network"]
)
dracut_options.append("--nofscks")
dracut_options.append("--nomdadmconf")
dracut_options.append("--nolvmconf")
dracut_options.append("--ro-mnt")
dracut_options.append("--no-hostonly")
dracut_options.append("--no-hostonly-cmdline")
dracut_options.append("--no-hostonly-default-device")
dracut_options.append("--no-hostonly-i18n")
dracut_options.append(tinyipa_initramfs)
run(dracut_options)
tinyipa_initramfs.chmod(0o644)
# capture the kernel
# as $BUILDDIR is mounted in with a bind mount, we need to read/write the file
# here, a simple mv/rename won't work
tinyipa_kernel.write_bytes(kernel_path.read_bytes())