Skip to content

Commit 0826256

Browse files
committed
feat(pkg): implement setup-initramfs subcommand
Signed-off-by: Zeglius <[email protected]>
1 parent 8975b9b commit 0826256

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

pkg

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,37 @@ _PKG_MANAGER_remove=
2020

2121
####### endregion INTERNAL_VARS #######
2222

23+
#
24+
#
25+
#
26+
27+
####### region INTERNAL_FUNCTIONS #######
28+
29+
# Setup the initramfs in the current rootfs.
30+
# Is redeclared depending of the package manager, with a noop declaration as fallback.
31+
#
32+
# Arguments:
33+
# $1 - The path to the initramfs image file.
34+
#
35+
# Usage:
36+
# _pkg_setupinitramfs /path/to/initramfs.img
37+
_pkg_setupinitramfs() {
38+
echo >&2 "ERROR: To be implemented"
39+
return 1
40+
}
41+
42+
####### endregion INTERNAL_FUNCTIONS #######
43+
44+
#
45+
#
46+
#
47+
2348
####### region Collect input #######
2449

2550
# Possible values:
2651
# install
2752
# remove
53+
# setup-initramfs
2854
_command=$1
2955
shift 2>/dev/null || {
3056
echo >&2 "ERROR: missing args"
@@ -50,6 +76,17 @@ elif [ -x "$(command -v dnf)" ]; then
5076
echo >&2 "Package manager identified: dnf"
5177
_PKG_MANAGER_install="dnf install -yq"
5278
_PKG_MANAGER_remove="dnf remove -yq"
79+
_pkg_setupinitramfs() {
80+
_initramfs_path="${1:?}"
81+
$_PKG_MANAGER_install dracut-live
82+
_INSTALLED_KERNEL=$(rpm -q kernel-core --queryformat "%{evr}.%{arch}" | tail -n 1)
83+
mkdir -p "$(realpath /root)"
84+
export DRACUT_NO_XATTR=1
85+
dracut --zstd --reproducible --no-hostonly --kver "$_INSTALLED_KERNEL" \
86+
--add "dmsquash-live dmsquash-live-autooverlay" \
87+
--force "$_initramfs_path" 2>&1 | grep -v -e "Operation not supported"
88+
unset -v _INSTALLED_KERNEL
89+
}
5390

5491
elif [ -x "$(command -v pacman)" ]; then
5592

@@ -74,9 +111,17 @@ fi
74111

75112
# shellcheck disable=SC2086
76113
if [ "$_command" = "install" ]; then
114+
77115
$_PKG_MANAGER_install $_args
116+
78117
elif [ "$_command" = "remove" ]; then
118+
79119
$_PKG_MANAGER_remove $_args
120+
121+
elif [ "$_command" = "setup-initramfs" ]; then
122+
123+
_pkg_setupinitramfs $_args
124+
80125
else
81126
echo >&2 "ERROR: unknown command"
82127
exit 1

0 commit comments

Comments
 (0)