Skip to content

Commit

Permalink
bin/ubuntu-core-initramfs: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsosanchezbeato committed Jan 10, 2024
1 parent 86c7aa4 commit 913abb8
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions bin/ubuntu-core-initramfs
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,16 @@ def install_file_to_path(file, dest_dir, dest_path):
env=proc_env)


# Returns as a list the files contained in a list of deb packages.
def package_files(pkgs):
out = check_output(["dpkg", "-L"] + pkgs)
return out.decode("utf-8").splitlines()


def install_systemd_files(dest_dir):
# Build list of files and directories

out = check_output(["dpkg", "-L", "systemd", "systemd-sysv"])
lines = out.decode("utf-8").splitlines()
lines = package_files(["systemd", "systemd-sysv"])
# From systemd, we pull
# * units configuration
# * Executables
Expand All @@ -325,8 +330,7 @@ def install_systemd_files(dest_dir):
)
files = [i for i in lines if to_include.match(i)]

out = check_output(["dpkg", "-L", "udev"])
lines = out.decode("utf-8").splitlines()
lines = package_files(["udev"])
# From udev, we pull
# * Executables
# * systemd configuration (units, tmpfiles)
Expand All @@ -353,17 +357,15 @@ def install_systemd_files(dest_dir):
# This hack should be removed with PR#113
check_call([r"sed -i '/^After=/"
r"{;s, *plymouth-start[.]service *, ,;/"
r"^After= *$$/d;}' "
r"^After= *$/d;}' "
+ os.path.join(dest_dir,
"usr/lib/systemd/system/systemd-ask-password-*")],
shell=True)
# Generate hw database (/usr/lib/udev/hwdb.bin) for udev and
# remove redundant definitions after that.
check_call(["systemd-hwdb", "--root", dest_dir,
"update", "--usr", "--strict"])
check_call(["rm -rf " + os.path.join(dest_dir,
"usr/lib/udev/hwdb.d")],
shell=True)
shutil.rmtree(os.path.join(dest_dir, "usr/lib/udev/hwdb.d"))


def install_busybox(dest_dir):
Expand All @@ -373,16 +375,16 @@ def install_busybox(dest_dir):
bb_cmd = os.path.join(dest_dir, "usr/bin/busybox")
out = check_output([bb_cmd, "--list-long"])
cmds = out.decode("utf-8").splitlines()
# Remove command we do not want
to_remove = ["busybox", "reboot", "mount", "umount"]
# Remove commands we do not want
to_remove = ["busybox", "reboot", "mount", "umount", "modinfo"]
cmds = [c for c in cmds if c not in to_remove]
for c in cmds:
os.symlink("busybox", os.path.join(dest_dir, "usr/bin", c))


def install_misc(dest_dir):
# dmsetup rules
rules = check_output(["dpkg", "-L", "dmsetup"]).decode("utf-8").splitlines()
rules = package_files(["dmsetup"])
to_include = re.compile(r".*rules.d/")
rules = [i for i in rules if to_include.match(i)]
install_files(rules, dest_dir)
Expand Down

0 comments on commit 913abb8

Please sign in to comment.