From: Jo Zzsi Date: Sat, 20 Dec 2025 17:53:28 +0000 (-0500) Subject: refactor: move defining require_X functions to dracut-functions.sh X-Git-Tag: 110~235 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3f7a6e5ec83f6081cf778567d29f05089cb82a5;p=thirdparty%2Fdracut-ng.git refactor: move defining require_X functions to dracut-functions.sh 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. --- diff --git a/dracut-functions.sh b/dracut-functions.sh index 4ba7dc2df..e62d9114e 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -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: diff --git a/dracut.sh b/dracut.sh index 15bd2a8b7..767304c8c 100755 --- 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 " == *\ $*\ * ]] } diff --git a/man/dracut.modules.7.adoc b/man/dracut.modules.7.adoc index b8694571d..cb1569c43 100644 --- a/man/dracut.modules.7.adoc +++ b/man/dracut.modules.7.adoc @@ -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