2008-12-18 00:57:43 +03:00
#!/bin/bash
#
2009-07-22 14:43:26 +04:00
# functions used by dracut and other tools.
2008-12-18 00:57:43 +03:00
#
2009-07-22 14:43:26 +04:00
# Copyright 2005-2009 Red Hat, Inc. All rights reserved.
2008-12-18 00:57:43 +03:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2009-03-04 19:29:42 +03:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-12-18 00:57:43 +03:00
#
IF_RTLD=""
IF_dynamic=""
2009-02-13 15:42:28 +03:00
2009-03-07 06:41:31 +03:00
# Generic substring function. If $2 is in $1, return 0.
2009-08-20 07:20:12 +04:00
strstr() { [[ $1 =~ $2 ]]; }
2009-02-13 15:43:26 +03:00
2009-05-30 07:53:11 +04:00
# Log initrd creation.
2009-05-29 06:41:05 +04:00
if ! [[ $dracutlogfile ]]; then
2009-10-27 11:28:53 +03:00
[[ $dracutbasedir = /usr/share/dracut ]] && \
2009-08-16 17:18:58 +04:00
dracutlogfile=/var/log/dracut.log || \
dracutlogfile=/tmp/dracut.log
2009-08-31 16:54:13 +04:00
# [[ -w $dracutlogfile ]] || dracutlogfile=/tmp/dracut.log
if [[ -w $dracutlogfile ]]; then
>"$dracutlogfile"
fi
2009-08-16 17:18:58 +04:00
fi
2009-05-29 06:41:05 +04:00
2009-05-15 14:45:21 +04:00
dwarning() {
echo "W: $@" >&2
2009-08-15 16:38:26 +04:00
[[ -w $dracutlogfile ]] && echo "W: $@" >>"$dracutlogfile"
2009-05-15 14:45:21 +04:00
}
dinfo() {
2009-05-20 14:30:22 +04:00
[[ $beverbose ]] && echo "I: $@" >&2
2009-08-15 16:38:26 +04:00
[[ -w $dracutlogfile ]] && echo "I: $@" >>"$dracutlogfile"
2009-05-15 14:45:21 +04:00
}
derror() {
echo "E: $@" >&2
2009-08-15 16:38:26 +04:00
[[ -w $dracutlogfile ]] && echo "E: $@" >>"$dracutlogfile"
2009-05-15 14:45:21 +04:00
}
2009-08-22 21:04:11 +04:00
get_fs_env() {
2010-05-03 13:34:30 +04:00
eval $(udevadm info --query=env --name=$1|egrep 'ID_FS_(TYPE|UUID)=')
[[ $ID_FS_TYPE ]] && return
2009-08-20 00:51:54 +04:00
if [[ -x /lib/udev/vol_id ]]; then
2009-08-22 21:04:11 +04:00
eval $(/lib/udev/vol_id --export $1)
elif find_binary blkid >/dev/null; then
eval $(blkid -o udev $1)
2009-08-20 00:51:54 +04:00
else
return 1
fi
2009-08-22 21:04:11 +04:00
}
get_fs_type() (
get_fs_env $1 || return
echo $ID_FS_TYPE
)
get_fs_uuid() (
get_fs_env $1 || return
echo $ID_FS_UUID
2009-08-20 00:51:54 +04:00
)
2009-08-16 19:29:21 +04:00
# finds the major:minor of the block device backing the root filesystem.
2009-08-20 07:20:12 +04:00
find_block_device() {
2009-08-16 19:29:21 +04:00
local rootdev blkdev fs type opts misc
while read blkdev fs type opts misc; do
[[ $blkdev = rootfs ]] && continue # skip rootfs entry
2009-08-20 07:20:12 +04:00
[[ $fs = $1 ]] && { rootdev=$blkdev; break; } # we have a winner!
2009-08-16 19:29:21 +04:00
done < /proc/mounts
[[ -b $rootdev ]] || return 1 # oops, not a block device.
# get major/minor for the device
ls -nLl "$rootdev" | \
(read x x x x maj min x; maj=${maj//,/}; echo $maj:$min)
}
2009-08-20 07:20:12 +04:00
find_root_block_device() { find_block_device /; }
2009-08-16 19:29:21 +04:00
# Walk all the slave relationships for a given block device.
# Stop when our helper function returns success
# $1 = function to call on every found block device
# $2 = block device in major:minor format
check_block_and_slaves() {
local x
[[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
"$1" $2 && return
2009-08-31 16:58:44 +04:00
check_vol_slaves "$@" && return 0
2010-05-19 10:13:12 +04:00
if [[ -f "/sys/dev/block/$2/../dev" ]]; then
check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") && return 0
fi
2009-08-16 19:29:21 +04:00
[[ -d /sys/dev/block/$2/slaves ]] || return 1
for x in /sys/dev/block/$2/slaves/*/dev; do
2009-08-19 19:08:57 +04:00
[[ -f $x ]] || continue
2009-08-16 19:29:21 +04:00
check_block_and_slaves $1 $(cat "$x") && return 0
done
return 1
}
2009-08-31 16:58:44 +04:00
get_numeric_dev() {
ls -lH "$1" | { read a b c d maj min rest; printf "%d:%d" ${maj%%,} $min;}
}
# ugly workaround for the lvm design
# There is no volume group device,
# so, there are no slave devices for volume groups.
# Logical volumes only have the slave devices they really live on,
# but you cannot create the logical volume without the volume group.
2009-10-29 12:29:58 +03:00
# And the volume group might be bigger than the devices the LV needs.
2009-08-31 16:58:44 +04:00
check_vol_slaves() {
for i in /dev/mapper/*; do
lv=$(get_numeric_dev $i)
if [[ $lv = $2 ]]; then
2009-08-31 16:54:13 +04:00
vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
2009-08-31 16:58:44 +04:00
# strip space
vg=$(echo $vg)
if [[ $vg ]]; then
2009-08-31 16:54:13 +04:00
for pv in $(lvm vgs --noheadings -o pv_name "$vg" 2>/dev/null); \
2009-08-31 16:58:44 +04:00
do
check_block_and_slaves $1 $(get_numeric_dev $pv) \
&& return 0
done
fi
fi
done
return 1
}
2009-09-27 08:33:41 +04:00
# Install a directory, keeping symlinks as on the original system.
# Example: if /lib64 points to /lib on the host, "inst_dir /lib/file"
# will create ${initdir}/lib64, ${initdir}/lib64/file,
# and a symlink ${initdir}/lib -> lib64.
inst_dir() {
local dir="$1"
[[ -e "${initdir}$dir" ]] && return 0
# iterate over parent directories
local file=""
local IFS="/"
for part in $dir; do
[ -z "$part" ] && continue
file="$file/$part"
[[ -e "${initdir}$file" ]] && continue
if [ -L "$file" ]; then
# create link as the original
local target=$(readlink "$file")
ln -sfn "$target" "${initdir}$file" || return 1
# resolve relative path and recursively install destionation
[[ "$target" = "${target##*/}" ]] && target="${file%/*}/$target"
inst_dir "$target"
else
# create directory
mkdir -p "${initdir}$file" || return 1
fi
done
}
2009-02-13 15:42:28 +03:00
# $1 = file to copy to ramdisk
# $2 (optional) Name for the file on the ramdisk
# Location of the image dir is assumed to be $initdir
2009-03-07 06:41:31 +03:00
# We never overwrite the target if it exists.
2009-02-13 15:42:28 +03:00
inst_simple() {
2009-03-04 03:21:19 +03:00
local src target
[[ -f $1 ]] || return 1
2009-09-27 08:33:41 +04:00
src=$1 target="${2:-$1}"
2009-11-26 12:53:09 +03:00
if ! [[ -d ${initdir}$target ]]; then
[[ -e ${initdir}$target ]] && return 0
inst_dir "${target%/*}"
fi
2009-05-15 14:45:21 +04:00
dinfo "Installing $src"
2009-09-30 17:34:12 +04:00
cp -pfL "$src" "${initdir}$target"
2009-02-13 15:42:28 +03:00
}
2009-10-29 12:29:58 +03:00
# Same as above, but specialized to handle dynamic libraries.
2009-03-07 06:41:31 +03:00
# It handles making symlinks according to how the original library
# is referenced.
2009-02-13 15:42:28 +03:00
inst_library() {
local src=$1 dest=${2:-$1}
2009-09-30 17:35:33 +04:00
[[ -e $initdir$dest ]] && return 0
2009-02-13 15:42:28 +03:00
if [[ -L $src ]]; then
2009-08-15 16:38:26 +04:00
reallib=$(readlink -f "$src")
2009-02-13 15:42:28 +03:00
lib=${src##*/}
2009-02-27 17:37:47 +03:00
inst_simple "$reallib" "$reallib"
2009-09-27 08:33:41 +04:00
inst_dir "${dest%/*}"
2009-02-13 15:42:28 +03:00
(cd "${initdir}${dest%/*}" && ln -s "$reallib" "$lib")
else
inst_simple "$src" "$dest"
fi
}
2009-03-07 06:41:31 +03:00
# find a binary. If we were not passed the full path directly,
# search in the usual places to find the binary.
2009-03-06 22:56:06 +03:00
find_binary() {
local binpath="/bin /sbin /usr/bin /usr/sbin" p
2009-08-01 11:52:16 +04:00
[[ -z ${1##/*} && -x $1 ]] && { echo $1; return 0; }
2009-02-13 15:43:09 +03:00
for p in $binpath; do
2009-03-06 22:56:06 +03:00
[[ -x $p/$1 ]] && { echo "$p/$1"; return 0; }
2009-02-13 15:43:09 +03:00
done
return 1
}
2009-02-13 15:42:28 +03:00
2009-03-07 06:41:31 +03:00
# Same as above, but specialized to install binary executables.
# Install binary executable, and all shared library dependencies, if any.
2009-02-13 15:42:28 +03:00
inst_binary() {
2009-03-04 03:21:19 +03:00
local bin target
2009-03-06 22:56:06 +03:00
bin=$(find_binary "$1") || return 1
2009-03-07 06:41:31 +03:00
target=${2:-$bin}
2009-09-30 17:35:33 +04:00
inst_symlink $bin $target && return 0
2009-02-13 15:42:28 +03:00
local LDSO NAME IO FILE ADDR I1 n f TLIBDIR
2009-09-30 17:35:33 +04:00
[[ -e $initdir$target ]] && return 0
2009-02-13 15:42:20 +03:00
# I love bash!
2009-03-09 11:17:41 +03:00
ldd $bin 2>/dev/null | while read line; do
2009-02-13 15:43:26 +03:00
[[ $line = 'not a dynamic executable' ]] && return 1
2009-05-23 06:24:31 +04:00
if [[ $line =~ not\ found ]]; then
2009-05-15 14:45:21 +04:00
derror "Missing a shared library required by $bin."
derror "Run \"ldd $bin\" to find out what it is."
derror "dracut cannot create an initrd."
2009-02-13 15:42:28 +03:00
exit 1
2009-05-23 06:24:31 +04:00
fi
2009-06-08 19:17:29 +04:00
so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
[[ $line =~ $so_regex ]] || continue
2009-02-13 15:43:26 +03:00
FILE=${BASH_REMATCH[1]}
2009-09-30 17:35:33 +04:00
[[ -e ${initdir}$FILE ]] && continue
2009-02-13 15:42:20 +03:00
# see if we are loading an optimized version of a shared lib.
2009-06-08 19:17:29 +04:00
lib_regex='^(/lib[^/]*).*'
if [[ $FILE =~ $lib_regex ]]; then
2009-02-13 15:42:20 +03:00
TLIBDIR=${BASH_REMATCH[1]}
2009-08-15 16:38:26 +04:00
BASE=${FILE##*/}
2009-02-13 15:42:20 +03:00
# prefer nosegneg libs, then unoptimized ones.
for f in "$TLIBDIR/i686/nosegneg" "$TLIBDIR"; do
2009-09-30 17:35:33 +04:00
[[ -e $f/$BASE ]] || continue
2009-08-15 16:38:26 +04:00
FILE=$f/$BASE
2009-02-13 15:42:20 +03:00
break
done
2009-02-13 15:42:28 +03:00
inst_library "$FILE" "$TLIBDIR/$BASE"
2009-08-15 16:38:26 +04:00
IF_dynamic=yes
2009-02-13 15:42:28 +03:00
continue
2009-05-23 06:24:31 +04:00
fi
2009-02-13 15:42:28 +03:00
inst_library "$FILE"
2009-03-09 11:17:41 +03:00
done
2009-03-07 06:41:31 +03:00
inst_simple "$bin" "$target"
2009-02-13 15:42:28 +03:00
}
2008-12-18 00:57:43 +03:00
2009-02-13 15:42:28 +03:00
# same as above, except for shell scripts.
# If your shell script does not start with shebang, it is not a shell script.
inst_script() {
2009-03-04 03:21:19 +03:00
[[ -f $1 ]] || return 1
2009-03-06 22:58:56 +03:00
local line
read -r -n 80 line <"$1"
2009-05-20 11:03:01 +04:00
# If debug is set, clean unprintable chars to prevent messing up the term
[[ $debug ]] && line=$(echo -n "$line" | tr -c -d '[:print:][:space:]')
2009-06-08 19:17:29 +04:00
shebang_regex='(#! *)(/[^ ]+).*'
[[ $line =~ $shebang_regex ]] || return 1
2009-03-06 22:58:56 +03:00
inst "${BASH_REMATCH[2]}" && inst_simple "$@"
2008-12-18 00:57:43 +03:00
}
2009-02-13 15:42:28 +03:00
# same as above, but specialized for symlinks
inst_symlink() {
local src=$1 target=$initdir${2:-$1} realsrc
[[ -L $1 ]] || return 1
[[ -L $target ]] && return 0
2009-02-27 17:37:47 +03:00
realsrc=$(readlink -f "$src")
2009-08-15 16:38:26 +04:00
[[ $realsrc = ${realsrc##*/} ]] && realsrc=${src%/*}/$realsrc
2009-02-13 15:42:28 +03:00
inst "$realsrc" && ln -s "$realsrc" "$target"
}
2009-10-29 12:29:58 +03:00
# find a udev rule in the usual places.
2009-03-04 03:21:13 +03:00
find_rule() {
2009-05-25 16:08:39 +04:00
[[ -f $1 ]] && { echo "$1"; return 0; }
2009-10-27 11:28:53 +03:00
for r in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
2009-03-04 03:21:13 +03:00
[[ -f $r/$1 ]] && { echo "$r/$1"; return 0; }
done
return 1
}
2009-02-13 15:43:26 +03:00
# udev rules always get installed in the same place, so
# create a function to install them to make life simpler.
inst_rules() {
2009-08-15 16:38:26 +04:00
local target=/etc/udev/rules.d
2009-09-27 08:33:41 +04:00
inst_dir "/lib/udev/rules.d"
inst_dir "$target"
2009-02-13 15:43:26 +03:00
for rule in "$@"; do
2009-08-15 16:38:26 +04:00
rule=$(find_rule "$rule") && \
2009-03-07 17:32:02 +03:00
inst_simple "$rule" "$target/${rule##*/}"
2009-02-13 15:43:26 +03:00
done
}
2009-02-13 15:42:28 +03:00
# general purpose installation function
# Same args as above.
2009-02-13 15:42:15 +03:00
inst() {
2009-09-14 21:33:54 +04:00
case $# in
1) ;;
2)
[[ -z $initdir ]] && [[ -d $2 ]] && export initdir=$2
[[ $initdir = $2 ]] && set $1
;;
3)
[[ -z $initdir ]] && export initdir=$2
set $1 $3
;;
*)
derror "inst only takes 1 or 2 or 3 arguments"
exit 1
;;
esac
2009-02-13 15:42:59 +03:00
for x in inst_symlink inst_script inst_binary inst_simple; do
2009-03-06 22:44:48 +03:00
$x "$@" && return 0
2009-02-13 15:42:28 +03:00
done
return 1
2008-12-18 00:57:43 +03:00
}
2009-02-13 15:43:29 +03:00
# install function specialized for hooks
# $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
# All hooks should be POSIX/SuS compliant, they will be sourced by init.
inst_hook() {
2009-05-23 06:24:31 +04:00
if ! [[ -f $3 ]]; then
2009-05-15 14:45:21 +04:00
derror "Cannot install a hook ($3) that does not exist."
derror "Aborting initrd creation."
2009-02-13 15:43:29 +03:00
exit 1
2009-05-23 06:24:31 +04:00
elif ! strstr "$hookdirs" "$1"; then
2009-05-15 14:45:21 +04:00
derror "No such hook type $1. Aborting initrd creation."
2009-02-13 15:43:29 +03:00
exit 1
2009-05-23 06:24:31 +04:00
fi
2009-02-13 15:43:29 +03:00
inst_simple "$3" "/${1}/${2}${3##*/}"
}
2009-02-13 15:43:24 +03:00
dracut_install() {
2009-08-15 16:55:59 +04:00
if [[ $1 = '-o' ]]; then
local optional=yes
shift
fi
2009-02-13 15:43:24 +03:00
while (($# > 0)); do
2009-08-15 16:55:59 +04:00
if ! inst "$1" ; then
if [[ $optional = yes ]]; then
dwarning "Skipping program $1 as it cannot be found and is flagged to be optional"
else
derror "Failed to install $1"
exit 1
fi
fi
shift
2009-02-13 15:43:24 +03:00
done
}
2009-05-24 09:29:44 +04:00
check_module_deps() {
2009-05-30 07:53:11 +04:00
local moddir dep ret
# if we are already set to be loaded, we do not have to be checked again.
2009-08-15 16:55:59 +04:00
strstr "$mods_to_load" " $1 " && return
2009-05-24 09:29:44 +04:00
# turn a module name into a directory, if we can.
2009-10-27 11:28:53 +03:00
moddir=$(echo ${dracutbasedir}/modules.d/??${1})
2009-05-24 09:29:44 +04:00
[[ -d $moddir && -x $moddir/install ]] || return 1
# if we do not have a check script, we are unconditionally included
if [[ -x $moddir/check ]]; then
2009-05-30 07:53:11 +04:00
"$moddir/check"
ret=$?
# a return value of 255 = load module only as a dependency.
((ret==0||ret==255)) || return 1
2009-05-24 09:29:44 +04:00
for dep in $("$moddir/check" -d); do
2009-05-30 07:53:11 +04:00
check_module_deps "$dep" && continue
2009-05-24 09:29:44 +04:00
dwarning "Dependency $mod failed."
return 1
done
fi
mods_to_load+=" $1 "
}
should_source_module() {
local dep
2009-08-15 19:56:36 +04:00
if [[ $kernel_only = yes ]]; then
2009-07-22 14:43:26 +04:00
[[ -x $1/installkernel ]] && return 0
return 1
fi
2009-08-27 14:52:24 +04:00
[[ -x $1/install ]] || [[ -x $1/installkernel ]] || return 1
2009-05-24 09:29:44 +04:00
[[ -x $1/check ]] || return 0
"$1/check" $hostonly || return 1
for dep in $("$1/check" -d); do
2009-05-30 07:53:11 +04:00
check_module_deps "$dep" && continue
2010-05-26 19:43:18 +04:00
dwarning "Cannot load dracut module \"$mod\", dependencies failed."
2009-05-24 09:29:44 +04:00
return 1
done
}
check_modules() {
2010-05-26 19:42:57 +04:00
local modcheck;
local mod;
2009-10-27 11:28:53 +03:00
for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
2009-05-24 09:29:44 +04:00
local mod=${moddir##*/}; mod=${mod#[0-9][0-9]}
2009-05-30 07:53:11 +04:00
# If we are already scheduled to be loaded, no need to check again.
strstr "$mods_to_load" " $mod " && continue
# This should never happen, but...
2009-05-24 09:29:44 +04:00
[[ -d $moddir ]] || continue
[[ $dracutmodules != all ]] && ! strstr "$dracutmodules" "$mod" && \
continue
strstr "$omit_dracutmodules" "$mod" && continue
2009-07-02 16:50:22 +04:00
if ! strstr "$add_dracutmodules" "$mod"; then
2009-07-02 13:57:23 +04:00
should_source_module "$moddir" || continue
fi
2009-05-24 09:29:44 +04:00
mods_to_load+=" $mod "
done
2010-05-26 19:42:57 +04:00
modcheck=$add_dracutmodules
[[ $dracutmodules != all ]] && modcheck="$m $dracutmodules"
for mod in $modcheck; do
strstr "$mods_to_load" "$mod" && continue
strstr "$omit_dracutmodules" "$mod" && continue
dwarning "Dracut module \"$mod\" cannot be found."
done
2009-05-24 09:29:44 +04:00
}
2009-08-15 23:17:19 +04:00
# Install a single kernel module along with any firmware it may require.
# $1 = full path to kernel module to install
install_kmod_with_fw() {
local modname=${1##*/} fwdir found
2010-01-13 17:53:17 +03:00
modname=${modname%.ko*}
2009-08-21 07:21:33 +04:00
inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" || \
return 0 # no need to go further if the module is already installed
2009-08-15 23:17:19 +04:00
for fw in $(modinfo -k $kernel -F firmware $1 2>/dev/null); do
found=''
for fwdir in $fw_dir; do
if [[ -d $fwdir && -f $fwdir/$fw ]]; then
inst_simple "$fwdir/$fw" "/lib/firmware/$fw"
found=yes
fi
done
if [[ $found != yes ]]; then
2010-05-26 19:43:18 +04:00
dinfo "Possible missing firmware \"${fw}\" for kernel module \"${mod}.ko\""
2009-08-15 23:17:19 +04:00
fi
done
}
# Do something with all the dependencies of a kernel module.
# Note that kernel modules depend on themselves using the technique we use
# $1 = function to call for each dependency we find
# It will be passed the full path to the found kernel module
# $2 = module to get dependencies for
# rest of args = arguments to modprobe
for_each_kmod_dep() {
local func=$1 kmod=$2 cmd modpapth options
shift 2
modprobe "$@" --ignore-install --show-depends $kmod 2>/dev/null | \
while read cmd modpath options; do
[[ $cmd = insmod ]] || continue
$func $modpath
done
}
2009-10-29 12:29:58 +03:00
# filter kernel modules to install certain modules that meet specific
2009-08-21 00:52:45 +04:00
# requirements.
# $1 = function to call with module name to filter.
# This function will be passed the full path to the module to test.
# The behaviour of this function can vary depending on whether $hostonly is set.
# If it is, we will only look at modules that are already in memory.
# If it is not, we will look at all kernel modules
2009-08-21 07:21:33 +04:00
# This function returns the full filenames of modules that match $1
2009-08-21 00:52:45 +04:00
filter_kernel_modules () (
2009-11-27 16:29:32 +03:00
if ! [[ $hostonly ]]; then
2010-01-13 17:53:17 +03:00
filtercmd='find "$srcmods/kernel/drivers" -name "*.ko" -o -name "*.ko.gz"'
2009-08-21 00:52:45 +04:00
else
2009-08-21 07:21:33 +04:00
filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename -k $kernel'
2009-08-21 00:52:45 +04:00
fi
2009-08-21 07:21:33 +04:00
for modname in $(eval $filtercmd); do
2010-01-13 17:53:17 +03:00
case $modname in
*.ko)
"$1" "$modname" && echo "$modname"
;;
*.ko.gz)
gzip -dc "$modname" > $initdir/$$.ko
$1 $initdir/$$.ko && echo "$modname"
rm -f $initdir/$$.ko
;;
esac
2009-08-21 07:21:33 +04:00
done
2009-08-21 00:52:45 +04:00
)
2009-08-15 23:17:19 +04:00
# install kernel modules along with all their dependencies.
2009-02-13 15:42:25 +03:00
instmods() {
2009-08-15 19:56:36 +04:00
[[ $no_kernel = yes ]] && return
2009-02-13 15:42:25 +03:00
local mod mpargs modpath modname cmd
while (($# > 0)); do
2010-01-13 17:53:17 +03:00
mod=${1%.ko*}
2009-02-13 15:42:25 +03:00
case $mod in
2009-03-06 22:51:28 +03:00
=*) # This introduces 2 incompatible meanings for =* arguments
2009-03-06 22:50:04 +03:00
# to instmods. We need to decide which one to keep.
2009-08-15 19:56:36 +04:00
if [[ $mod = =ata && -f $srcmods/modules.block ]] ; then
2009-05-29 06:13:16 +04:00
instmods $mpargs $(egrep 'ata|ahci' "${srcmods}/modules.block")
2009-03-06 17:09:44 +03:00
elif [ -f $srcmods/modules.${mod#=} ]; then
2009-03-06 23:00:34 +03:00
instmods $mpargs $(cat ${srcmods}/modules.${mod#=} )
2009-03-06 16:35:19 +03:00
else
2009-03-06 23:00:34 +03:00
instmods $mpargs $(find "$srcmods" -path "*/${mod#=}/*")
2009-03-06 16:35:19 +03:00
fi
;;
2009-08-28 15:28:19 +04:00
--*)
mod=${mod##*/}
mpargs+=" $mod";;
2009-06-12 03:28:02 +04:00
i2o_scsi)
# Must never run this diagnostic-only module
shift; continue;
;;
2009-08-28 15:28:19 +04:00
*)
mod=${mod##*/}
# if we are already installed, skip this module and go on
2009-05-30 07:53:11 +04:00
# to the next one.
2009-03-07 06:41:31 +03:00
[[ -f $initdir/$1 ]] && { shift; continue; }
2009-05-30 07:53:11 +04:00
# If we are building a host-specific initramfs and this
# module is not already loaded, move on to the next one.
2010-01-13 18:02:10 +03:00
[[ $hostonly ]] && ! grep -q "${mod//-/_}" /proc/modules && \
! echo $add_drivers | grep -qe "\<${mod}\>" && {
2009-05-30 07:53:11 +04:00
shift; continue;
}
2009-08-15 19:56:36 +04:00
# ok, load the module, all its dependencies, and any firmware
# it may require
2009-08-15 23:17:19 +04:00
for_each_kmod_dep install_kmod_with_fw $mod \
--set-version $kernel -d ${srcmods%%/lib/modules/*}/
2009-02-13 15:42:25 +03:00
;;
2009-05-29 06:13:16 +04:00
esac
2009-02-13 15:42:25 +03:00
shift
2008-12-18 00:57:43 +03:00
done
2009-02-13 15:42:25 +03:00
}
2008-12-18 00:57:43 +03:00
# vim:ts=8:sw=4:sts=4:et