stages/rpm: cleanup /etc/kernel again if oprhaned
If the run of dracut has been disabled via installing a link to /dev/null in /etc/kernel/install.d and after the installation of the packages the /etc/kernel directory is not owned by any newly installed packages, remove it again.
This commit is contained in:
parent
1cca184ccd
commit
01ae8a528e
1 changed files with 20 additions and 0 deletions
|
|
@ -184,6 +184,25 @@ def enable_dracut(masked_files):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_unowned_etc_kernel(tree):
|
||||||
|
# if installed, /etc/kernel is owned by systemd-udev; but
|
||||||
|
# in case the directory is un-owned, remove it again
|
||||||
|
res = subprocess.run(["rpm",
|
||||||
|
"--root", tree,
|
||||||
|
"-qf", "/etc/kernel"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
check=False)
|
||||||
|
owner = res.stdout.strip()
|
||||||
|
|
||||||
|
if res == 0 and owner:
|
||||||
|
print(f"/etc/kernel is owned by {owner}")
|
||||||
|
return
|
||||||
|
|
||||||
|
with contextlib.suppress(OSError):
|
||||||
|
os.rmdir("etc/kernel/install.d")
|
||||||
|
os.rmdir("etc/kernel")
|
||||||
|
|
||||||
|
|
||||||
def parse_input(inputs):
|
def parse_input(inputs):
|
||||||
packages = inputs["packages"]
|
packages = inputs["packages"]
|
||||||
path = packages["path"]
|
path = packages["path"]
|
||||||
|
|
@ -263,6 +282,7 @@ def main(tree, inputs, options):
|
||||||
# re-enabled dracut
|
# re-enabled dracut
|
||||||
if no_dracut:
|
if no_dracut:
|
||||||
enable_dracut(masked_files)
|
enable_dracut(masked_files)
|
||||||
|
remove_unowned_etc_kernel(tree)
|
||||||
|
|
||||||
# remove temporary machine ID if it was created by us
|
# remove temporary machine ID if it was created by us
|
||||||
if not machine_id_set_previously:
|
if not machine_id_set_previously:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue