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.
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
ldconfig_paths()
{
- local a i
- declare -A a
- for i in $(
- ldconfig -pN 2>/dev/null | grep -F '=>' | grep -E -v '/(lib|lib64|usr/lib|usr/lib64)/[^/]*$' | while read a b c d; do
- d=${d%/*}
- printf "%s\n" "$d";
- done
- ); do
- 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
[[ $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;
# $ 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
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_dir "${udevdir}/rules.d"
inst_dir "$_target"
for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
- if [[ -e $_rule ]]; then
+ [[ -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
- fi
- done
- if [ -n ${hostonly} ] ; then
- for _rule in ${_target}/$1 ; do
- if [[ -f $_rule ]]; then
- inst_rule_programs "$_rule"
- inst_rule_group_owner "$_rule"
- inst_rule_initqueue "$_rule"
- inst_simple "$_rule"
- _found=$_rule
- fi
done
fi
[[ $_found ]] || dinfo "Skipping udev rule: $_rule"
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
# 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
# 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
# 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
# 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
# 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
# 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
# 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.
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"} ${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;
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
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
+ while read a rest || [ -n "$a" ]; do
[[ $a = */$1/* ]] || [[ $a = updates/* ]] || continue
printf "%s\n" "$srcmods/$a"
done < "$srcmods/modules.dep"
_mod=${_mod##*/}
# Check for aliased modules
_modalias=$(modinfo -k $kernel -F filename $_mod 2> /dev/null)
- _modalias=${_modalias%.ko}
- if [ "${_modalias##*/}" != "$_mod" ] ; then
+ _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
}
[[ ${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
+}