diff options
-rw-r--r-- | functions | 8 | ||||
-rw-r--r-- | install/autodetect | 38 | ||||
-rwxr-xr-x | mkinitcpio | 7 |
3 files changed, 29 insertions, 24 deletions
@@ -273,8 +273,8 @@ add_checked_modules() { local mod mods - if [[ -s $_f_autodetect_cache ]]; then - mapfile -t mods < <(all_modules "$@" | grep -xFf "$_f_autodetect_cache") + if (( ${#_autodetect_cache[*]} )); then + mapfile -t mods < <(all_modules "$@" | grep -xFf <(printf '%s\n' "${!_autodetect_cache[@]}")) else mapfile -t mods < <(all_modules "$@") fi @@ -293,8 +293,8 @@ checked_modules() { # DEPRECATED: Use add_checked_modules instead # - if [[ -s $_f_autodetect_cache ]]; then - grep -xFf "$_f_autodetect_cache" <(all_modules "$@") + if (( ${#_autodetect_cache[*]} )); then + all_modules "$@" | grep -xFf <(printf '%s\n' "${!_autodetect_cache[@]}") return 1 else all_modules "$@" diff --git a/install/autodetect b/install/autodetect index 4f1e4bb..907a85a 100644 --- a/install/autodetect +++ b/install/autodetect @@ -1,20 +1,19 @@ #!/bin/bash build() { - local -a md_devs - - _f_autodetect_cache=$_d_workdir/autodetect_modules + local m= + local -a md_devs mods add_if_avail() { - local resolved + local r= resolved= # treat this as an alias, since ext3 might be aliased to ext4. IFS=$'\n' read -rd '' -a resolved < \ <(modprobe -d "$_optmoduleroot" -S "$KERNELVERSION" -R "$1" 2>/dev/null) - if (( ${#resolved[*]} )); then - printf '%s\n' "${resolved[@]}" >>"$_f_autodetect_cache" - fi + for r in "${resolved[@]}"; do + _autodetect_cache["$r"]=1 + done } if [[ ! -d /sys/devices ]]; then @@ -22,7 +21,10 @@ build() { return 1 fi - auto_modules >"$_f_autodetect_cache" + mapfile -t mods < <(auto_modules) + for m in "${mods[@]}"; do + _autodetect_cache["$m"]=1 + done # detect filesystem for root if rootfstype=$(findmnt -uno fstype '/'); then @@ -41,22 +43,24 @@ build() { md_devs=(/sys/class/block/md*/md/level) if [[ -e $md_devs ]]; then quiet "found %d mdadm arrays to scan" "${#md_devs[*]}" - awk '{ gsub(/raid[456]/, "raid456"); print; }' "${md_devs[@]}" | - sort -u >>"$_f_autodetect_cache" + mapfile -t mods < <(awk '{ gsub(/raid[456]/, "raid456"); print; }' "${md_devs[@]}") + for m in "${mods[@]}"; do + _autodetect_cache["$m"]=1 + done fi - if [[ -s $_f_autodetect_cache ]]; then - quiet "caching %d modules" $(wc -l < "$_f_autodetect_cache") + if (( ${#_autodetect_cache[*]} )); then + quiet "caching %d modules" "${#_autodetect_cache[*]}" fi } help() { cat <<HELPEOF -This hook shrinks your initramdisk to a smaller size by autodetecting your -needed modules. Be sure to verify included modules are correct and none are -missing. This hook must be run before other subsystem hooks in order to take -advantage of auto-detection. Any hooks placed before 'autodetect' will be -installed in full. +This hook shrinks your initramfs to a smaller size by autodetecting the needed +modules. Be sure to verify included modules are correct and none are missing. +This hook must be run before other subsystem hooks in order to take advantage +of auto-detection. Any hooks placed before 'autodetect' will be installed in +full. HELPEOF } @@ -17,12 +17,12 @@ _d_install=(install /usr/lib/initcpio/install /lib/initcpio/install) _d_presets=mkinitcpio.d # options and runtime data -_optmoduleroot= _optkver= _f_autodetect_cache= _optgenimg= _optpreset= +_optmoduleroot= _optkver= _optgenimg= _optpreset= _optcompress= _optshowautomods=0 _optsavetree=0 _optshowmods=0 _optquiet=1 _optcolor=1 _optskiphooks=() _optaddhooks=() _modpaths=() _hooks=() -declare -A _runhooks=() _addedmodules=() +declare -A _runhooks=() _addedmodules=() _autodetect_cache=() # export a sane PATH export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' @@ -64,6 +64,7 @@ cleanup() { if [[ $_d_workdir ]]; then # when _optpreset is set, we're in the main loop, not a worker process if (( _optsavetree )) && [[ -z $_optpreset ]]; then + printf '%s\n' "${!_autodetect_cache[@]}" > "$_d_workdir/autodetect_modules" msg "build directory saved in %s" "$_d_workdir" else rm -rf "$_d_workdir" @@ -378,7 +379,7 @@ if (( _optshowautomods )); then _f_autodetect_hook=$(find_in_dirs 'autodetect' "${_d_install[@]}") . "$_f_autodetect_hook" build - cat "$_f_autodetect_cache" + printf '%s\n' "${!_autodetect_cache[@]}" | sort cleanup 0 fi |