Message info
 
To:arch-projects@archlinux.org From:Dave Reisner Subject:[arch-projects] [mkinitcpio][PATCH 09/19] functions: introduce add_checked_modules and add_all_modules Date:Sun, 13 May 2012 13:57:12 -0400
 

Instead of returning a list of modules which the caller should then add
themselves or stuff into the MODULES string, call add_module for each
candidate. This is basically a different wrapper around all_modules.

DEPRECATION WARNING: This commit marks checked_modules as deprecated.
Although it is not slated to go away, direct usage of all_modules is
strongly discouraged.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
functions | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/functions b/functions
index 052dced..97b401c 100644
--- a/functions
+++ b/functions
@@ -199,12 +199,23 @@ auto_modules() {
all_modules() {
# Add modules to the initcpio, filtered by grep.
# $@: filter arguments to grep
+ # -f FILTER: ERE to filter found modules

local -i count=0
- local mod=
+ local mod= OPTIND= OPTARG= filter=()
+
+ while getopts ':f:' flag; do
+ case $flag in f) filter+=("$OPTARG") ;; esac
+ done
+ shift $(( OPTIND - 1 ))

while read -r -d '' mod; do
(( ++count ))
+
+ for f in "${filter[@]}"; do
+ [[ $mod =~ $f ]] && continue 2
+ done
+
mod=${mod##*/}
mod="${mod%.ko*}"
printf '%s\n' "${mod//-/_}"
@@ -213,11 +224,48 @@ all_modules() {
(( count ))
}

-checked_modules() {
+add_all_modules() {
+ # Add modules to the initcpio.
+ # $@: arguments to all_modules
+
+ local mod mods
+
+ mapfile -t mods < <(all_modules "$@")
+
+ for mod in "${mods[@]}"; do
+ add_module "$mod"
+ done
+
+ return $(( !${#mods[*]} ))
+}
+
+add_checked_modules() {
# Add modules to the initcpio, filtered by the list of autodetected
# modules.
# $@: arguments to all_modules

+ local mod mods
+
+ if [[ -s $MODULE_FILE ]]; then
+ mapfile -t mods < <(all_modules "$@" | grep -xFf "$MODULE_FILE")
+ else
+ mapfile -t mods < <(all_modules "$@")
+ fi
+
+ for mod in "${mods[@]}"; do
+ add_module "$mod"
+ done
+
+ return $(( !${#mods[*]} ))
+}
+
+checked_modules() {
+ # Returns a list of modules filtered by the list of autodetected modules.
+ # $@: arguments to all_modules
+ #
+ # DEPRECATED: Use add_checked_modules instead
+ #
+
if [[ -s $MODULE_FILE ]]; then
grep -xFf "$MODULE_FILE" <(all_modules "$@")
return 1
--
1.7.10.2