Skip to content
Snippets Groups Projects
Unverified Commit 23c58a68 authored by Oliver Smith's avatar Oliver Smith
Browse files

main/postmarketos-mkinitfs: modules from files (!1123)

Read kernel module names from files in
/etc/postmarketos-mkinitfs/modules and print out which modules are
required by which of these files as the initramfs gets generated. Put
the default modules into a new 00-default.modules. This allows mkinitfs
hooks to add modules to the initramfs.

Parse the modules from a file similar to modules-load.d, with commented
lines and empty lines ignored. Add a simple test script for that and run
it in check().
parent 3e760460
No related branches found
No related tags found
No related merge requests found
Pipeline #193298 passed
......@@ -20,6 +20,7 @@ sh_files="
./main/postmarketos-mkinitfs/init_functions.sh
./main/postmarketos-mkinitfs/mkinitfs.sh
./main/postmarketos-mkinitfs/mkinitfs_functions.sh
./main/postmarketos-mkinitfs/mkinitfs_test.sh
./main/postmarketos-mkinitfs-hook-debug-shell/20-debug-shell.sh
./main/postmarketos-update-kernel/update-kernel.sh
./main/mdss-fb-init-hack/mdss-fb-init-hack.sh
......
dm_crypt
ext4
usb_f_rndis
pkgname=postmarketos-mkinitfs
pkgver=0.11.1
pkgver=0.12.0
pkgrel=0
pkgdesc="Tool to generate initramfs images for postmarketOS"
url="https://postmarketos.org"
......@@ -7,15 +7,16 @@ url="https://postmarketos.org"
depends="busybox-extras lddtree cryptsetup kmod multipath-tools
device-mapper parted e2fsprogs e2fsprogs-extra osk-sdl charging-sdl triggerhappy xz bzip2 lz4"
triggers="$pkgname.trigger=/etc/postmarketos-mkinitfs/hooks:/usr/share/kernel/*"
source="init.sh.in
source="00-default.modules
init.sh.in
init_functions.sh
mkinitfs.sh
mkinitfs_functions.sh
mkinitfs_test.sh
"
arch="noarch"
license="GPL2"
provides="mkinitfs=0.0.1"
options="!check"
package() {
for file in init.sh.in init_functions.sh mkinitfs_functions.sh; do
......@@ -23,13 +24,22 @@ package() {
"$pkgdir/usr/share/postmarketos-mkinitfs/$file"
done
install -Dm644 "$srcdir/00-default.modules" \
"$pkgdir/etc/postmarketos-mkinitfs/modules/00-default.modules"
install -Dm755 "$srcdir/mkinitfs.sh" \
"$pkgdir/sbin/mkinitfs"
mkdir -p "$pkgdir/etc/postmarketos-mkinitfs/hooks/"
}
sha512sums="1d49db8a48ad513cc548b8a0ea23cc64518e71c93863155b4e9d2271fb46090506331c03d6955d693c8568c248ecc76b218efe4a6f6bba57c41c5f6d775dc61b init.sh.in
check() {
/bin/busybox sh ./mkinitfs_test.sh
}
sha512sums="5037cb7285bb7c0c40ca9e6df332d882ef9a8b379756c785f921e062dab1b7e7f3139d00897f69323a916d709ced4297fea8cbd3a13ebae575b873ec9e2cbfae 00-default.modules
1d49db8a48ad513cc548b8a0ea23cc64518e71c93863155b4e9d2271fb46090506331c03d6955d693c8568c248ecc76b218efe4a6f6bba57c41c5f6d775dc61b init.sh.in
315cc6e8a73f9984e6843395d68734d26ac2fffce34039ec5f229ebcd818bdb353318398d6c824cede5d0b36e13d7589a1f1d3295d8162279b5dc6a2b939da88 init_functions.sh
7201d4640a3e9ead8a47ffd9916b068476b7d950760a84c37e02268c942d49896bc986da6bdee27e832639c90775354d68046a6475205d8d1da995b068120d8f mkinitfs.sh
a3e61f10ab63000b7ee2aafe021c248367ac2dd0ac6e5c263cfaf9d510e64b6e3dc9983e3b49e47fb7d8734ebcc277948003af01fa79f5f11703f7fb79281f4b mkinitfs_functions.sh"
c448b6d8810deb85590ac9e4254a8390fd25b3c5f1aef0a49cfaa6d489c58d45f5f7bda376f87ce241a432aaeccf1046ba63bfda2508fd456f5a0a93e2ca6f7d mkinitfs_functions.sh
c7a3c33daeb12b33ac72207191941c4d634f15c22958273b52af381a70ebaba1d3a9299483f0c447d9e66c560151fe7b9588bb4bbef2c8914f83185984ee4622 mkinitfs_test.sh"
......@@ -100,8 +100,37 @@ get_modules_by_globs()
done
}
# NOTE: This does not work with busybox' modprobe
# That's why postmarketos-mkinitfs depends on kmod
# Read a modules-load.d style file into a single line. The file is expected to
# have empty lines, lines starting with "#" that are comments or one word in
# the line. The resulting parsed line is printed to stdout.
# $1: file to parse
parse_file_as_line()
{
_first="true"
while IFS= read -r line; do
case "$line" in
""|"#"*)
# Comment or empty line, ignore
;;
*)
if [ "$_first" = "true" ]; then
_first="false"
else
printf " "
fi
printf "%s" "$line"
;;
esac
done < "$1"
}
# Parse modules by name from deviceinfo and from these files:
# /etc/postmarketos-mkinitfs/modules/*.modules. The postmarketos-mkinitfs
# package installs a 00-default.modules there.
# Resolved kernel module paths get printed to stdout, informative logging to
# stderr.
# NOTE: This does not work with busybox' modprobe. That's why
# postmarketos-mkinitfs depends on kmod.
get_modules_by_name()
{
{
......@@ -111,9 +140,15 @@ get_modules_by_name()
echo "with 'y' instead of 'm' (module)."
} >&2
MODULES="$deviceinfo_modules_initfs"
echo " - deviceinfo: $deviceinfo_modules_initfs" >&2
MODULES="dm_crypt ext4 usb_f_rndis \
${deviceinfo_modules_initfs}"
for file in "/etc/postmarketos-mkinitfs/modules/"*.modules; do
[ -f "$file" ] || continue
_modules_file="$(parse_file_as_line "$file")"
echo " - $(basename "$file"): $_modules_file" >&2
MODULES="$MODULES $_modules_file"
done
# shellcheck disable=SC2086
modprobe \
......
#!/bin/sh -e
# Test single functions of mkinitfs_functions.sh. Add -x for verbosity.
. ./mkinitfs_functions.sh
echo ":: testing parse_file_as_line()"
cat << EOF > _test
# comment
module1
module2
# comment2
module3
EOF
if [ "$(parse_file_as_line _test)" != "module1 module2 module3" ]; then
echo "ERROR in line $LINENO"
exit 1
fi
echo ":: all tests passed"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment