diff options
author | Dave Reisner <dreisner@archlinux.org> | 2012-05-11 18:49:10 +0200 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-05-16 23:55:54 +0200 |
commit | 01cb8b7a20ab53967a68e56a64152c357e12ff41 (patch) | |
tree | 7c2206aa25973a26cfedcb8f121eb125dbb240c4 /functions | |
parent | 799ca0ab2dfb509f152fe268dfc916df2d33cbd1 (diff) | |
download | mkinitcpio-01cb8b7a20ab53967a68e56a64152c357e12ff41.tar.gz mkinitcpio-01cb8b7a20ab53967a68e56a64152c357e12ff41.tar.xz |
functions: introduce add_checked_modules and add_all_modules
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>
Diffstat (limited to 'functions')
-rw-r--r-- | functions | 52 |
1 files changed, 50 insertions, 2 deletions
@@ -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 |