]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
feat(dracut-init.sh): introduce a new helper require_kernel_modules
authorKairui Song <kasong@tencent.com>
Tue, 6 Dec 2022 09:24:47 +0000 (17:24 +0800)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Wed, 21 Dec 2022 16:07:46 +0000 (17:07 +0100)
Some dracut modules won't work without certain kernel modules,
this helper will be helpful for checking such kernel configs in
check() and error out early.

Signed-off-by: Kairui Song <kasong@tencent.com>
dracut-init.sh

index c89f7e80ea4b2ca3606903f4337a17621f3a6a10..c86ab45aad0f83c474dfa42b71ad1a4a68483d9d 100755 (executable)
@@ -150,6 +150,28 @@ require_any_binary() {
     return 0
 }
 
+# helper function for check() in module-setup.sh
+# to check for required kernel modules
+# issues a standardized warning message
+require_kernel_modules() {
+    # shellcheck disable=SC2154
+    local _module_name="${moddir##*/}"
+    local _ret=0
+
+    if [[ $1 == "-m" ]]; then
+        _module_name="$2"
+        shift 2
+    fi
+
+    for mod in "$@"; do
+        if ! check_kernel_module "$mod" &> /dev/null; then
+            dinfo "dracut module '${_module_name#[0-9][0-9]}' will not be installed, because kernel module '$mod' is not available!"
+            ((_ret++))
+        fi
+    done
+    return "$_ret"
+}
+
 dracut_need_initqueue() {
     : > "$initdir/lib/dracut/need-initqueue"
 }