#!/bin/bash
-# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
-# ex: ts=8 sw=4 sts=4 et filetype=sh
#
# functions used by dracut and other tools.
#
export LC_MESSAGES=C
if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
- if ! [[ -d "$initdir/.kernelmodseen" ]]; then
- mkdir -p "$initdir/.kernelmodseen"
+ if [[ -d "$initdir/.kernelmodseen" ]]; then
+ DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen"
fi
- DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen"
-fi
-
-if [[ $initdir ]] && ! [[ -d $initdir ]]; then
- mkdir -p "$initdir"
fi
# Generic substring function. If $2 is in $1, return 0.
-strstr() { [[ $1 = *$2* ]]; }
+strstr() { [[ $1 = *"$2"* ]]; }
+# Generic glob matching function. If glob pattern $2 matches anywhere in $1, OK
+strglobin() { [[ $1 = *$2* ]]; }
+# Generic glob matching function. If glob pattern $2 matches all of $1, OK
+strglob() { [[ $1 = $2 ]]; }
+# returns OK if $1 contains literal string $2 at the beginning, and isn't empty
+str_starts() { [ "${1#"$2"*}" != "$1" ]; }
+# returns OK if $1 contains literal string $2 at the end, and isn't empty
+str_ends() { [ "${1%*"$2"}" != "$1" ]; }
+
+# 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
+
+ if [[ "$1" = "-m" ]]; then
+ _module_name="$2"
+ shift 2
+ fi
+
+ for cmd in "$@"; do
+ if ! find_binary "$cmd" &>/dev/null; then
+ dinfo "dracut 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
+
+ if [[ "$1" = "-m" ]]; then
+ _module_name="$2"
+ shift 2
+ fi
+
+ 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
+}
# find a binary. If we were not passed the full path directly,
# search in the usual places to find the binary.
ldconfig_paths()
{
- local a i
- declare -A a
- for i in $(
- ldconfig -pN 2>/dev/null | while read a b c d; do
- [[ "$c" != "=>" ]] && continue
- printf "%s\n" ${d%/*};
- done
- ); do
- [[ "$i" = "/lib" || "$i" = "/usr/lib" || "$i" = "/lib64" || "$i" = "/usr/lib64" ]] && continue
- a["$i"]=1;
- done;
- printf "%s\n" ${!a[@]}
+ ldconfig -pN 2>/dev/null | grep -E -v '/(lib|lib64|usr/lib|usr/lib64)/[^/]*$' | sed -n 's,.* => \(.*\)/.*,\1,p' | sort | uniq
}
# Detect lib paths
}
export srcmods
-if ! type dinfo >/dev/null 2>&1; then
+# is_func <command>
+# Check whether $1 is a function.
+is_func() {
+ [[ "$(type -t "$1")" = "function" ]]
+}
+
+if ! is_func dinfo >/dev/null 2>&1; then
. "$dracutbasedir/dracut-logger.sh"
dlog_init
fi
[[ -e ${1%/*} ]] || mkdir -m 0755 -p -- "${1%/*}"
}
-# is_func <command>
-# Check whether $1 is a function.
-is_func() {
- [[ "$(type -t "$1")" = "function" ]]
-}
-
# Function prints global variables in format name=value line by line.
# $@ = list of global variables' name
print_vars() {
for _var in "$@"
do
- eval printf -v _value "%s" "\$$_var"
+ eval printf -v _value "%s" \""\$$_var"\"
[[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
done
}
[[ $1 ]] || return
unset ID_FS_TYPE
ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \
- | while read line; do
+ | while read line || [ -n "$line" ]; do
if [[ "$line" == TYPE\=* ]]; then
printf "%s" "${line#TYPE=}";
exit 0;
return
fi
done
+ printf -- "%s" "$1"
}
expand_persistent_dev() {
# $ find_block_device /usr
# 8:4
find_block_device() {
- local _majmin _dev _majmin _find_mpt
+ local _dev _majmin _find_mpt
_find_mpt="$1"
if [[ $use_fstab != yes ]]; then
[[ -d $_find_mpt/. ]]
findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
- while read _majmin _dev; do
+ while read _majmin _dev || [ -n "$_dev" ]; do
if [[ -b $_dev ]]; then
if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
_majmin=$(get_maj_min $_dev)
# fall back to /etc/fstab
findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
- while read _majmin _dev; do
+ while read _majmin _dev || [ -n "$_dev" ]; do
if ! [[ $_dev ]]; then
_dev="$_majmin"
unset _majmin
if [[ $use_fstab != yes ]]; then
findmnt -e -v -n -o 'FSTYPE' --target "$1" | { \
- while read _fs; do
+ while read _fs || [ -n "$_fs" ]; do
[[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue
printf "%s" "$_fs"
fi
findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1" | { \
- while read _fs; do
+ while read _fs || [ -n "$_fs" ]; do
[[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue
printf "%s" "$_fs"
if [[ $use_fstab != yes ]]; then
findmnt -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \
- while read _fs; do
+ while read _fs || [ -n "$_fs" ]; do
[[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue
printf "%s" "$_fs"
fi
findmnt --fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \
- while read _fs; do
+ while read _fs || [ -n "$_fs" ]; do
[[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue
printf "%s" "$_fs"
local _dev
local _ret=1
- [[ "${!host_fs_types[@]}" ]] || return 0
+ [[ "${#host_fs_types[@]}" ]] || return 0
for _dev in "${!host_fs_types[@]}"; do
$_func "$_dev" "${host_fs_types[$_dev]}" && _ret=0
[[ "${host_devs[@]}" ]] || return 0
- for _dev in ${host_devs[@]}; do
+ for _dev in "${host_devs[@]}"; do
[[ -b "$_dev" ]] || continue
if check_block_and_slaves_all $_func $(get_maj_min $_dev); then
_ret=0
[[ "${host_devs[@]}" ]] || return 0
- for _dev in ${host_devs[@]}; do
+ for _dev in "${host_devs[@]}"; do
[[ -b "$_dev" ]] || continue
check_block_and_slaves $_func $(get_maj_min $_dev) && return 0
done
# but you cannot create the logical volume without the volume group.
# And the volume group might be bigger than the devices the LV needs.
check_vol_slaves() {
- local _lv _vg _pv
+ local _lv _vg _pv _dm
for i in /dev/mapper/*; do
[[ $i == /dev/mapper/control ]] && continue
_lv=$(get_maj_min $i)
+ _dm=/sys/dev/block/$_lv/dm
+ [[ -f $_dm/uuid && $(<$_dm/uuid) =~ LVM-* ]] || continue
if [[ $_lv = $2 ]]; then
_vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
# strip space
done
}
-
if ! [[ $DRACUT_INSTALL ]]; then
DRACUT_INSTALL=$(find_binary dracut-install)
fi
if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then
DRACUT_INSTALL=$dracutbasedir/dracut-install
+elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install/dracut-install ]]; then
+ DRACUT_INSTALL=$dracutbasedir/install/dracut-install
fi
if ! [[ -x $DRACUT_INSTALL ]]; then
}
inst() {
+ local _hostonly_install
+ if [[ "$1" == "-H" ]]; then
+ _hostonly_install="-H"
+ shift
+ fi
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
- #dinfo "$DRACUT_INSTALL -l $@"
- $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
- (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
}
inst_simple() {
+ local _hostonly_install
+ if [[ "$1" == "-H" ]]; then
+ _hostonly_install="-H"
+ shift
+ fi
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
[[ -e $1 ]] || return 1 # no source
- $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@"
- (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@" || :
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
}
inst_symlink() {
+ local _hostonly_install
+ if [[ "$1" == "-H" ]]; then
+ _hostonly_install="-H"
+ shift
+ fi
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
[[ -L $1 ]] || return 1
- $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
- (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
}
inst_multiple() {
- local ret
- #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
- $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
- ret=$?
- (($ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
- return $ret
+ local _ret
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+ _ret=$?
+ (($_ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+ return $_ret
}
dracut_install() {
}
inst_library() {
+ local _hostonly_install
+ if [[ "$1" == "-H" ]]; then
+ _hostonly_install="-H"
+ shift
+ fi
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
[[ -e $1 ]] || return 1 # no source
- $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
- (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
}
inst_binary() {
- $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
- (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
}
inst_script() {
- $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
- (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
+}
+
+mark_hostonly() {
+ for i in "$@"; do
+ echo "$i" >> "$initdir/lib/dracut/hostonly-files"
+ done
}
# find symlinks linked to given library file
for _rule in "$@"; do
if [ "${_rule#/}" = "$_rule" ]; then
for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
- if [[ -e $r/$_rule ]]; then
- _found="$r/$_rule"
- inst_rule_programs "$_found"
- inst_rule_group_owner "$_found"
- inst_rule_initqueue "$_found"
- inst_simple "$_found"
- fi
+ [[ -e $r/$_rule ]] || continue
+ _found="$r/$_rule"
+ inst_rule_programs "$_found"
+ inst_rule_group_owner "$_found"
+ inst_rule_initqueue "$_found"
+ inst_simple "$_found"
done
fi
for r in '' $dracutbasedir/rules.d/; do
# skip rules without an absolute path
[[ "${r}$_rule" != /* ]] && continue
-
- if [[ -f ${r}$_rule ]]; then
- _found="${r}$_rule"
- inst_rule_programs "$_found"
- inst_rule_group_owner "$_found"
- inst_rule_initqueue "$_found"
- inst_simple "$_found" "$_target/${_found##*/}"
- fi
+ [[ -f ${r}$_rule ]] || continue
+ _found="${r}$_rule"
+ inst_rule_programs "$_found"
+ inst_rule_group_owner "$_found"
+ inst_rule_initqueue "$_found"
+ inst_simple "$_found" "$_target/${_found##*/}"
done
[[ $_found ]] || dinfo "Skipping udev rule: $_rule"
done
}
+inst_rules_wildcard() {
+ local _target=/etc/udev/rules.d _rule _found
+
+ inst_dir "${udevdir}/rules.d"
+ inst_dir "$_target"
+ for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
+ [[ -e $_rule ]] || continue
+ inst_rule_programs "$_rule"
+ inst_rule_group_owner "$_rule"
+ inst_rule_initqueue "$_rule"
+ inst_simple "$_rule"
+ _found=$_rule
+ done
+ if [[ -n ${hostonly} ]] ; then
+ for _rule in ${_target}/$1 ; do
+ [[ -f $_rule ]] || continue
+ inst_rule_programs "$_rule"
+ inst_rule_group_owner "$_rule"
+ inst_rule_initqueue "$_rule"
+ inst_simple "$_rule"
+ _found=$_rule
+ done
+ fi
+ [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
+}
+
prepare_udev_rules() {
[ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
for f in "$@"; do
f="${initdir}/etc/udev/rules.d/$f"
[ -e "$f" ] || continue
- while read line; do
+ while read line || [ -n "$line" ]; do
if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
if [ $UDEVVERSION -ge 174 ]; then
printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}"
[[ $1 = '-d' ]] && to="$2" && shift 2
for f in "$@"; do
- if [[ -e $f ]]; then
- [[ $to ]] && inst "$f" "$to" && return 0
- inst "$f" && return 0
- fi
+ [[ -e $f ]] || continue
+ [[ $to ]] && inst "$f" "$to" && return 0
+ inst "$f" && return 0
done
return 1
inst_opt_decompress() {
local _src
- for _src in $@
- do
+ for _src in $@; do
inst_decompress "${_src}" || inst "${_src}"
done
}
# or the "check" script, if module-setup.sh is not found
# "check $hostonly" is called
module_check() {
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
local _ret
local _forced=0
local _hostonly=$hostonly
. $_moddir/module-setup.sh
is_func check || return 0
[ $_forced -ne 0 ] && unset hostonly
- check $hostonly
+ moddir=$_moddir check $hostonly
_ret=$?
unset check depends cmdline install installkernel
fi
# or the "check" script, if module-setup.sh is not found
# "mount_needs=1 check 0" is called
module_check_mount() {
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
local _ret
mount_needs=1
[[ -d $_moddir ]] || return 1
unset check depends cmdline install installkernel
check() { false; }
. $_moddir/module-setup.sh
- check 0
+ moddir=$_moddir check 0
_ret=$?
unset check depends cmdline install installkernel
fi
# execute the depends() function of module-setup.sh of <dracut module>
# or the "depends" script, if module-setup.sh is not found
module_depends() {
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
local _ret
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
unset check depends cmdline install installkernel
depends() { true; }
. $_moddir/module-setup.sh
- depends
+ moddir=$_moddir depends
_ret=$?
unset check depends cmdline install installkernel
return $_ret
# execute the cmdline() function of module-setup.sh of <dracut module>
# or the "cmdline" script, if module-setup.sh is not found
module_cmdline() {
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
local _ret
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
unset check depends cmdline install installkernel
cmdline() { true; }
. $_moddir/module-setup.sh
- cmdline
+ moddir=$_moddir cmdline
_ret=$?
unset check depends cmdline install installkernel
return $_ret
# execute the install() function of module-setup.sh of <dracut module>
# or the "install" script, if module-setup.sh is not found
module_install() {
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
local _ret
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
unset check depends cmdline install installkernel
install() { true; }
. $_moddir/module-setup.sh
- install
+ moddir=$_moddir install
_ret=$?
unset check depends cmdline install installkernel
return $_ret
# execute the installkernel() function of module-setup.sh of <dracut module>
# or the "installkernel" script, if module-setup.sh is not found
module_installkernel() {
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
local _ret
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
unset check depends cmdline install installkernel
installkernel() { true; }
. $_moddir/module-setup.sh
- installkernel
+ moddir=$_moddir installkernel
_ret=$?
unset check depends cmdline install installkernel
return $_ret
# device and filesystem types in "${host_fs_types[@]}"
check_mount() {
local _mod=$1
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
local _ret
local _moddep
- [ "${#host_fs_types[*]}" -le 0 ] && return 1
+ [ "${#host_fs_types[@]}" -le 0 ] && return 1
# If we are already scheduled to be loaded, no need to check again.
[[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
fi
fi
-
for _moddep in $(module_depends $_mod); do
# handle deps as if they were manually added
- [[ " $add_dracutmodules " == *\ $_moddep\ * ]] || \
- add_dracutmodules+=" $_moddep "
- [[ " $force_add_dracutmodules " == *\ $_moddep\ * ]] || \
- force_add_dracutmodules+=" $_moddep "
+ [[ " $dracutmodules " == *\ $_mod\ * ]] \
+ && [[ " $dracutmodules " != *\ $_moddep\ * ]] \
+ && dracutmodules+=" $_moddep "
+ [[ " $add_dracutmodules " == *\ $_mod\ * ]] \
+ && [[ " $add_dracutmodules " != *\ $_moddep\ * ]] \
+ && add_dracutmodules+=" $_moddep "
+ [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] \
+ && [[ " $force_add_dracutmodules " != *\ $_moddep\ * ]] \
+ && force_add_dracutmodules+=" $_moddep "
# if a module we depend on fail, fail also
if ! check_module $_moddep; then
derror "dracut module '$_mod' depends on '$_moddep', which can't be installed"
# that the modules were checked for the dependency tracking process
check_module() {
local _mod=$1
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
local _ret
local _moddep
# If we are already scheduled to be loaded, no need to check again.
fi
if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
- if [[ " $force_add_dracutmodules " == *\ $_mod\ * ]]; then
+ if [[ " $dracutmodules $force_add_dracutmodules " == *\ $_mod\ * ]]; then
module_check $_mod 1; ret=$?
else
module_check $_mod 0; ret=$?
# module not in our list
if [[ $dracutmodules = all ]]; then
# check, if we can and should install this module
- module_check $_mod || return 1
+ module_check $_mod; ret=$?
+ if [[ $ret != 0 ]]; then
+ [[ $2 ]] && return 1
+ [[ $ret != 255 ]] && return 1
+ fi
else
# skip this module
return 1
for _moddep in $(module_depends $_mod); do
# handle deps as if they were manually added
- [[ " $add_dracutmodules " == *\ $_moddep\ * ]] || \
- add_dracutmodules+=" $_moddep "
- [[ " $force_add_dracutmodules " == *\ $_moddep\ * ]] || \
- force_add_dracutmodules+=" $_moddep "
+ [[ " $dracutmodules " == *\ $_mod\ * ]] \
+ && [[ " $dracutmodules " != *\ $_moddep\ * ]] \
+ && dracutmodules+=" $_moddep "
+ [[ " $add_dracutmodules " == *\ $_mod\ * ]] \
+ && [[ " $add_dracutmodules " != *\ $_moddep\ * ]] \
+ && add_dracutmodules+=" $_moddep "
+ [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] \
+ && [[ " $force_add_dracutmodules " != *\ $_moddep\ * ]] \
+ && force_add_dracutmodules+=" $_moddep "
# if a module we depend on fail, fail also
if ! check_module $_moddep; then
derror "dracut module '$_mod' depends on '$_moddep', which can't be installed"
# Report any missing dracut modules, the user has specified
_modcheck="$add_dracutmodules $force_add_dracutmodules"
- [[ $dracutmodules != all ]] && _modcheck="$m $dracutmodules"
+ [[ $dracutmodules != all ]] && _modcheck="$_modcheck $dracutmodules"
for _mod in $_modcheck; do
[[ " $mods_to_load " == *\ $_mod\ * ]] && continue
- [[ " $omit_dracutmodules " == *\ $_mod\ * ]] && continue
+
+ [[ " $force_add_dracutmodules " != *\ $_mod\ * ]] \
+ && [[ " $dracutmodules " != *\ $_mod\ * ]] \
+ && [[ " $omit_dracutmodules " == *\ $_mod\ * ]] \
+ && continue
+
derror "dracut module '$_mod' cannot be found or installed."
+ [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] && exit 1
+ [[ " $dracutmodules " == *\ $_mod\ * ]] && exit 1
+ [[ " $add_dracutmodules " == *\ $_mod\ * ]] && exit 1
done
}
if [[ $omit_drivers ]]; then
local _kmod=${1##*/}
- _kmod=${_kmod%.ko}
+ _kmod=${_kmod%.ko*}
_kmod=${_kmod/-/_}
if [[ "$_kmod" =~ $omit_drivers ]]; then
dinfo "Omitting driver $_kmod"
if [[ $silent_omit_drivers ]]; then
local _kmod=${1##*/}
- _kmod=${_kmod%.ko}
+ _kmod=${_kmod%.ko*}
_kmod=${_kmod/-/_}
[[ "$_kmod" =~ $silent_omit_drivers ]] && return 0
[[ "${1##*/lib/modules/$kernel/}" =~ $silent_omit_drivers ]] && return 0
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
+ [[ -d $_fwdir && -f $_fwdir/$_fw ]] || continue
+ inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
+ _found=yes
done
if [[ $_found != yes ]]; then
if ! [[ -d $(echo /sys/module/${_modname//-/_}|{ read a b; echo $a; }) ]]; then
local _func=$1 _kmod=$2 _cmd _modpath _options
shift 2
modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | (
- while read _cmd _modpath _options; do
+ while read _cmd _modpath _options || [ -n "$_cmd" ]; do
[[ $_cmd = insmod ]] || continue
$_func ${_modpath} || exit $?
done
--ignore-install --show-depends --set-version $kernel \
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev/null \
| sort -u \
- | while read _cmd _modpath _options; do
+ | while read _cmd _modpath _options || [ -n "$_cmd" ]; do
[[ $_cmd = insmod ]] || continue
echo "$_modpath"
done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
(
if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
- xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
+ xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
else
- while read _modpath; do
+ while read _modpath || [ -n "$_modpath" ]; do
local _destpath=$_modpath
[[ $_moddirname ]] && _destpath=${_destpath##$_moddirname/}
_destpath=${_destpath##*/lib/modules/$kernel/}
done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
fi
) &
- _pid=$(jobs -p | while read a ; do printf ":$a";done)
+ _pid=$(jobs -p | while read a || [ -n "$a" ]; do printf ":$a";done)
_pid=${_pid##*:}
if [[ $DRACUT_INSTALL ]]; then
xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
- | while read line; do
+ | while read line || [ -n "$line" ]; do
for _fwdir in $fw_dir; do
echo $_fwdir/$line;
done;
- done | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
+ done | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} -a -o
else
for _fw in $(xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
for _fwdir in $fw_dir; do
- if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
- inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
- break
- fi
+ [[ -d $_fwdir && -f $_fwdir/$_fw ]] || continue
+ inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
+ break
done
done
fi
wait $_pid
fi
- for _f in modules.builtin.bin modules.builtin; do
- [[ $srcmods/$_f ]] && break
- done || {
- dfatal "No modules.builtin.bin and modules.builtin found!"
- return 1
- }
-
for _f in modules.builtin.bin modules.builtin modules.order; do
[[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
done
local _mod=$1
local _modenc a i _k _s _v _aliases
_mod=${_mod##*/}
- _mod=${_mod%.ko}
+ _mod=${_mod%.ko*}
_modenc=${_mod//-/_}
[[ " $add_drivers " == *\ ${_mod}\ * ]] && return 0
_OLDIFS=$IFS
IFS=:
- while read a rest; do
- [[ $a = */$1/* ]] || continue
+ while read a rest || [ -n "$a" ]; do
+ [[ $a = */$1/* ]] || [[ $a = updates/* ]] || continue
printf "%s\n" "$srcmods/$a"
done < "$srcmods/modules.dep"
IFS=$_OLDIFS
--*) _mpargs+=" $_mod" ;;
*)
_mod=${_mod##*/}
+ # Check for aliased modules
+ _modalias=$(modinfo -k $kernel -F filename $_mod 2> /dev/null)
+ _modalias=${_modalias%.ko*}
+ if [[ $_modalias ]] && [ "${_modalias##*/}" != "${_mod%.ko*}" ] ; then
+ _mod=${_modalias##*/}
+ fi
+
# if we are already installed, skip this module and go on
# to the next one.
if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
- [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
- read _ret <"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
+ [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko*}" ]]; then
+ read _ret <"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko*}"
return $_ret
fi
((_ret+=$?))
else
[[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
- echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
+ echo ${_mod%.ko*} >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
fi
;;
esac
function instmods_1() {
local _mod _mpargs
if (($# == 0)); then # filenames from stdin
- while read _mod; do
+ while read _mod || [ -n "$_mod" ]; do
inst1mod "${_mod%.ko*}" || {
- if [[ "$_check" == "yes" ]]; then
- [[ "$_silent" == "no" ]] && dfatal "Failed to install module $_mod"
- return 1
+ if [[ "$_check" == "yes" ]] && [[ "$_silent" == "no" ]]; then
+ dfatal "Failed to install module $_mod"
fi
}
done
fi
while (($# > 0)); do # filenames as arguments
inst1mod ${1%.ko*} || {
- if [[ "$_check" == "yes" ]]; then
- [[ "$_silent" == "no" ]] && dfatal "Failed to install module $1"
- return 1
+ if [[ "$_check" == "yes" ]] && [[ "$_silent" == "no" ]]; then
+ dfatal "Failed to install module $1"
fi
}
shift
# Capture all stderr from modprobe to _fderr. We could use {var}>...
# redirections, but that would make dracut require bash4 at least.
eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
- | while read line; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
+ | while read line || [ -n "$line" ]; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
_ret=$?
return $_ret
}
+
+check_kernel_config()
+{
+ local _config_opt="$1"
+ local _config_file
+ [[ -f /boot/config-$kernel ]] \
+ && _config_file="/boot/config-$kernel"
+ [[ -f /lib/modules/$kernel/config ]] \
+ && _config_file="/lib/modules/$kernel/config"
+
+ # no kernel config file, so return true
+ [[ $_config_file ]] || return 0
+
+ grep -q -F "${_config_opt}=" "$_config_file" && return 0
+ return 1
+}
+
+
# get_cpu_vendor
# Only two values are returned: AMD or Intel
get_cpu_vendor ()
[[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]
}
+btrfs_devs() {
+ local _mp="$1"
+ btrfs device usage "$_mp" \
+ | while read _dev _rest; do
+ str_starts "$_dev" "/" || continue
+ _dev=${_dev%,}
+ printf -- "%s\n" "$_dev"
+ done
+}