]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
refactor: move defining require_X functions to dracut-functions.sh
authorJo Zzsi <jozzsicsataban@gmail.com>
Sat, 20 Dec 2025 17:53:28 +0000 (12:53 -0500)
committerBenjamin Drung <bdrung@ubuntu.com>
Sun, 21 Dec 2025 22:02:42 +0000 (23:02 +0100)
require_X are public interfaces to dracut modules, move them
to `dracut-functions.sh`.

Add documentation for these public functions to make it clear that
it is expected to be used in out-of-tree dracut modules as well.

dracut-functions.sh
dracut.sh
man/dracut.modules.7.adoc

index 4ba7dc2df009812e1a2df851ca2015d10091a502..e62d9114ede770a112c1ecb9d58bdf577ee2c0ba 100755 (executable)
@@ -1438,6 +1438,60 @@ elif ! [[ $DRACUT_INSTALL ]] && [[ -x "${BASH_SOURCE[0]%/*}/src/install/dracut-i
     DRACUT_INSTALL="${BASH_SOURCE[0]%/*}/src/install/dracut-install"
 fi
 
+# helper function for check() in module-setup.sh
+# to check for required installed binaries
+# issues a standardized warning message
+require_binaries() {
+    local _module_name="${moddir##*/}"
+    local _ret=0
+
+    for cmd in "$@"; do
+        if ! find_binary "$cmd" &> /dev/null; then
+            ddebug "Module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
+            ((_ret++))
+        fi
+    done
+    return "$_ret"
+}
+
+require_any_binary() {
+    local _module_name="${moddir##*/}"
+    local _ret=1
+
+    for cmd in "$@"; do
+        if find_binary "$cmd" &> /dev/null; then
+            _ret=0
+            break
+        fi
+    done
+
+    if ((_ret != 0)); then
+        dinfo "$_module_name: Could not find any command of '$*'!"
+        return 1
+    fi
+
+    return 0
+}
+
+# helper function for check() in module-setup.sh
+# to check for required kernel modules
+# issues a standardized warning message
+require_kernel_modules() {
+    local _module_name="${moddir##*/}"
+    local _ret=0
+
+    # Ignore kernel module requirement for no-kernel build
+    [[ $no_kernel == yes ]] && return 0
+
+    for mod in "$@"; do
+        if ! check_kernel_module "$mod" &> /dev/null; then
+            dinfo "Module '${_module_name#[0-9][0-9]}' will not be installed, because kernel module '$mod' is not available!"
+            ((_ret++))
+        fi
+    done
+    return "$_ret"
+}
+
 # Test if the configured dracut-install command exists.
 # Catch DRACUT_INSTALL being unset/empty.
 # The variable DRACUT_INSTALL may be set externally as:
index 15bd2a8b75c61db6c531dacc72e8859cc48b3cd7..767304c8c9b5dee3b9c359aacd6321d17857b833 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -1540,60 +1540,6 @@ if ! [[ ${libdirs-} ]]; then
     export libdirs
 fi
 
-# helper function for check() in module-setup.sh
-# to check for required installed binaries
-# issues a standardized warning message
-require_binaries() {
-    local _module_name="${moddir##*/}"
-    local _ret=0
-
-    for cmd in "$@"; do
-        if ! find_binary "$cmd" &> /dev/null; then
-            ddebug "Module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
-            ((_ret++))
-        fi
-    done
-    return "$_ret"
-}
-
-require_any_binary() {
-    local _module_name="${moddir##*/}"
-    local _ret=1
-
-    for cmd in "$@"; do
-        if find_binary "$cmd" &> /dev/null; then
-            _ret=0
-            break
-        fi
-    done
-
-    if ((_ret != 0)); then
-        dinfo "$_module_name: Could not find any command of '$*'!"
-        return 1
-    fi
-
-    return 0
-}
-
-# helper function for check() in module-setup.sh
-# to check for required kernel modules
-# issues a standardized warning message
-require_kernel_modules() {
-    local _module_name="${moddir##*/}"
-    local _ret=0
-
-    # Ignore kernel module requirement for no-kernel build
-    [[ $no_kernel == yes ]] && return 0
-
-    for mod in "$@"; do
-        if ! check_kernel_module "$mod" &> /dev/null; then
-            dinfo "Module '${_module_name#[0-9][0-9]}' will not be installed, because kernel module '$mod' is not available!"
-            ((_ret++))
-        fi
-    done
-    return "$_ret"
-}
-
 dracut_module_included() {
     [[ " $mods_to_load $modules_loaded " == *\ $*\ * ]]
 }
index b8694571d2f8262af7cbc65b74446cd67b66755a..cb1569c43def30a8f5cefed9077ca249e33b2dc2 100644 (file)
@@ -369,6 +369,24 @@ dracut module.
 This function is maintained only to provide compatibility for modules aimed at older
 dracut releases.
 
+==== require_binaries
+
+Helper function for check() in module-setup.sh to check for required installed binaries.
+All of the binaries listed in the arguments of this function should exists in the host.
+Issues a standardized warning message.
+
+==== require_any_binary
+
+Helper function for check() in module-setup.sh to check for required installed binaries.
+At least one of the binaries listed in the arguments of this function should exists in
+the host.
+Issues a standardized warning message.
+
+==== require_kernel_modules
+
+Helper function for check() in module-setup.sh to check for required kernel modules.
+Issues a standardized warning message.
+
 === Initramfs Functions
 
 FIXME