test-functions revision 889a90422dd47284dffa32b9234a6e58991b000c
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# ex: ts=8 sw=4 sts=4 et filetype=sh
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrseBASICTOOLS="sh bash setsid loadkeys setfont login sushell sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrseDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd ro console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse ../../systemd-nspawn --boot --directory=$TESTDIR/nspawn-root /usr/lib/systemd/systemd
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse # we strip binaries since debug symbols increase binaries size a lot
ae398ee382477f3c2bbe9afcb325ae563e9c1595dougm for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
d572c96f3a1c0f6b712bf2522352b929872a607edougm dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm [ -b $LOOPDEV ] || return 1
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#!/bin/bash
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse | while read i; do
6cf71da67fecb3acb6f300daae49463148bfbf2adougm if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse # install plymouth, if found... else remove plymouth service files
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
bfd35b329124266ebdab96567241bea57f2e8481dougm # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
6cf71da67fecb3acb6f300daae49463148bfbf2adougm rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrseLABEL=systemd / ext3 rw 0 1
ad668861e40da485f2eea24dc4c1f9940e470698rbb | while read file; do
5576b15d077ac45713567be95d13b1c778cad7fajwoolley | while read file; do
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ -f $i ]] || continue
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm [[ -f $i ]] || continue
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm [ -f ${_terminfodir}/l/linux ] && break
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm cp $TEST_BASE_DIR/{testsuite.target,end.service} $initdir/etc/systemd/system/
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm ln -fs testsuite.target $initdir/etc/systemd/system/default.target
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm for d in usr/bin usr/sbin bin etc lib "$libdir" sbin tmp usr var var/log dev proc sys sysroot root run run/lock run/initramfs; do
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz [[ $_line = 'not a dynamic executable' ]] && break
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz if [[ $_line =~ $_so_regex ]]; then
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz [[ -e ${initdir}/$_file ]] && continue
f367c0bc73c39f48669bbdcf02dfa6bbf1dbc306dougm if [[ $_line =~ not\ found ]]; then
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ -e $STATEFILE ]] && . $STATEFILE
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
615d8325d256f306dea742098e0855b2e207feb1dougm## @brief Converts numeric logging level to the first letter of level name.
615d8325d256f306dea742098e0855b2e207feb1dougm# @param lvl Numeric logging level in range from 1 to 6.
bfd35b329124266ebdab96567241bea57f2e8481dougm# @retval 1 if @a lvl is out of range.
bfd35b329124266ebdab96567241bea57f2e8481dougm# @retval 0 if @a lvl is correct.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# @result Echoes first letter of level name.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm 1) echo F;;
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse 2) echo E;;
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse 3) echo W;;
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse 4) echo I;;
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse 5) echo D;;
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm 6) echo T;;
1cde33c7e2019830f8fb3224e01649305583916etrawick *) return 1;;
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse## @brief Internal helper function for _do_dlog()
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# @param lvl Numeric logging level.
a943533fd4d91d114af622731a405407990c4fb1rse# @param msg Message.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @retval 0 It's always returned, even if logging failed.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @note This function is not supposed to be called manually. Please use
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# dtrace(), ddebug(), or others instead which wrap this one.
93e04e27f5508c78897599cc15abd27ffbbd5424dougm# This function calls _do_dlog() either with parameter msg, or if
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# none is given, it will read standard input and will use every line as
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# a message.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# This enables:
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# dwarn "This is a warning"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# echo "This is a warning" | dwarn
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [ $1 -le $LOG_LEVEL ] || return 0
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if [ $# -ge 1 ]; then
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse while read line; do
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse## @brief Logs message at TRACE level (6)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @param msg Message.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @retval 0 It's always returned, even if logging failed.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse## @brief Logs message at DEBUG level (5)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @param msg Message.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @retval 0 It's always returned, even if logging failed.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# [ -n "$debug" ] && set -x || :
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse## @brief Logs message at INFO level (4)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @param msg Message.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# @retval 0 It's always returned, even if logging failed.
bfd35b329124266ebdab96567241bea57f2e8481dougm## @brief Logs message at WARN level (3)
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# @param msg Message.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @retval 0 It's always returned, even if logging failed.
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz## @brief Logs message at ERROR level (2)
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# @param msg Message.
bfd35b329124266ebdab96567241bea57f2e8481dougm# @retval 0 It's always returned, even if logging failed.
a943533fd4d91d114af622731a405407990c4fb1rse# [ -n "$debug" ] && set -x || :
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse## @brief Logs message at FATAL level (1)
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# @param msg Message.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# @retval 0 It's always returned, even if logging failed.
bfd35b329124266ebdab96567241bea57f2e8481dougm# Generic substring function. If $2 is in $1, return 0.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# normalize_path <path>
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# Prints the normalized path, where it removes any duplicated
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# and trailing slashes.
bfd35b329124266ebdab96567241bea57f2e8481dougm# $ normalize_path ///test/test//
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# convert_abs_rel <from> <to>
bfd35b329124266ebdab96567241bea57f2e8481dougm# Prints the relative path, when creating a symlink to <to> from <from>.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm local __current __absolute __abssize __cursize __newpath
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm while [[ ${__absolute[__level]} == ${__current[__level]} ]]
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz# Install a directory, keeping symlinks as on the original system.
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz# Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# will create ${initdir}/lib64, ${initdir}/lib64/file,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# and a symlink ${initdir}/lib -> lib64.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if [[ -L $_file ]]; then
bfd35b329124266ebdab96567241bea57f2e8481dougm [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# $1 = file to copy to ramdisk
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# $2 (optional) Name for the file on the ramdisk
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# Location of the image dir is assumed to be $initdir
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# We never overwrite the target if it exists.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if ! [[ -d ${initdir}/$target ]]; then
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm [[ -e ${initdir}/$target ]] && return 0
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ -L ${initdir}/$target ]] && return 0
bfd35b329124266ebdab96567241bea57f2e8481dougm [[ -d "${initdir}/${target%/*}" ]] || inst_dir "${target%/*}"
bfd35b329124266ebdab96567241bea57f2e8481dougm inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# find symlinks linked to given library file
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# $1 = library file
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# Function searches for symlinks by stripping version numbers appended to
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# library filename, checks if it points to the same target and finally
bfd35b329124266ebdab96567241bea57f2e8481dougm# prints the list of symlinks to stdout.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# rev_lib_symlinks libfoo.so.8.1
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# (Only if libfoo.so.8 and libfoo.so exists on host system.)
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz [[ ! $1 ]] && return 0
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz local fn="$1" orig="$(readlink -f "$1")" links=''
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ ${fn} =~ .*\.so\..* ]] || return 1
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# Same as above, but specialized to handle dynamic libraries.
8c118e10f6e74359cb990ce2652578ca6af6b038dougm# It handles making symlinks according to how the original library
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# is referenced.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm [[ -e $initdir/$_dest ]] && return 0
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm if [[ -L $_src ]]; then
615d8325d256f306dea742098e0855b2e207feb1dougm inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
615d8325d256f306dea742098e0855b2e207feb1dougm ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}"
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm # Create additional symlinks. See rev_symlinks description.
615d8325d256f306dea742098e0855b2e207feb1dougm for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
a943533fd4d91d114af622731a405407990c4fb1rse# find a binary. If we were not passed the full path directly,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# search in the usual places to find the binary.
615d8325d256f306dea742098e0855b2e207feb1dougm if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
a943533fd4d91d114af622731a405407990c4fb1rse# Same as above, but specialized to install binary executables.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# Install binary executable, and all shared library dependencies, if any.
1cde33c7e2019830f8fb3224e01649305583916etrawick [[ -e $initdir/$_target ]] && return 0
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz [[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
f2c178ff26c0840e23cf468322111cbb721776a4rse if [[ $_line =~ $_so_regex ]]; then
f2c178ff26c0840e23cf468322111cbb721776a4rse [[ -e ${initdir}/$_file ]] && continue
f2c178ff26c0840e23cf468322111cbb721776a4rse if [[ $_line =~ not\ found ]]; then
f2c178ff26c0840e23cf468322111cbb721776a4rse# same as above, except for shell scripts.
f2c178ff26c0840e23cf468322111cbb721776a4rse# If your shell script does not start with shebang, it is not a shell script.
f2c178ff26c0840e23cf468322111cbb721776a4rse # If debug is set, clean unprintable chars to prevent messing up the term
f2c178ff26c0840e23cf468322111cbb721776a4rse [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
f2c178ff26c0840e23cf468322111cbb721776a4rse [[ $_line =~ $_shebang_regex ]] || return 1
f2c178ff26c0840e23cf468322111cbb721776a4rse# same as above, but specialized for symlinks
f2c178ff26c0840e23cf468322111cbb721776a4rse local _src=$1 _target=${2:-$1} _realsrc
f2c178ff26c0840e23cf468322111cbb721776a4rse [[ -L $1 ]] || return 1
f2c178ff26c0840e23cf468322111cbb721776a4rse [[ -L $initdir/$_target ]] && return 0
f2c178ff26c0840e23cf468322111cbb721776a4rse if ! [[ -e $initdir/$_realsrc ]]; then
f2c178ff26c0840e23cf468322111cbb721776a4rse if [[ -d $_realsrc ]]; then
f2c178ff26c0840e23cf468322111cbb721776a4rse [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
f2c178ff26c0840e23cf468322111cbb721776a4rse [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/}
f2c178ff26c0840e23cf468322111cbb721776a4rse ln -sfn $(convert_abs_rel "${_target}" "${_realsrc}") "$initdir/$_target"
f2c178ff26c0840e23cf468322111cbb721776a4rse# attempt to install any programs specified in a udev rule
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
e59e4b703b7e19c4b35030e4baac8a96a8d4b504dougm if [ -x /lib/udev/$_prog ]; then
e59e4b703b7e19c4b35030e4baac8a96a8d4b504dougm dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# udev rules always get installed in the same place, so
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# create a function to install them to make life simpler.
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz if [[ -f $r/$_rule ]]; then
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz if [[ -f ${r}$_rule ]]; then
5717c6b0b97a065a84fba32cebeee959a5fe4f15dougm# general purpose installation function
5717c6b0b97a065a84fba32cebeee959a5fe4f15dougm# Same args as above.
1cde33c7e2019830f8fb3224e01649305583916etrawick 2) [[ ! $initdir && -d $2 ]] && export initdir=$2
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz [[ $initdir = $2 ]] && set $1;;
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm 3) [[ -z $initdir ]] && export initdir=$2
a943533fd4d91d114af622731a405407990c4fb1rse set $1 $3;;
615d8325d256f306dea742098e0855b2e207feb1dougm for _x in inst_symlink inst_script inst_binary inst_simple; do
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# install any of listed files
9c124948099335e241040410375e626691c33844dougm# If first argument is '-d' and second some destination path, first accessible
9c124948099335e241040410375e626691c33844dougm# source is installed into this path, otherwise it will installed in the same
9c124948099335e241040410375e626691c33844dougm# path as source. If none of listed files was installed, function return 1.
9c124948099335e241040410375e626691c33844dougm# On first successful installation it returns with 0 status.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# initramfs.
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz if [[ -e $f ]]; then
5717c6b0b97a065a84fba32cebeee959a5fe4f15dougm# dracut_install [-o ] <file> [<file> ... ]
5717c6b0b97a065a84fba32cebeee959a5fe4f15dougm# Install <file> to the initramfs image
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# -o optionally install the <file> and don't fail, if it is not there
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm if [[ $_optional = yes ]]; then
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm dinfo "Skipping program $1 as it cannot be found and is" \
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# Install a single kernel module along with any firmware it may require.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# $1 = full path to kernel module to install
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz # no need to go further if the module is already installed
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ -e "${initdir}/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" ]] \
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse && return 0
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz if [[ $omit_drivers ]]; then
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if [[ "${1##*/lib/modules/$KERNEL_VER/}" =~ $omit_drivers ]]; then
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse inst_simple "$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse || return $?
1cde33c7e2019830f8fb3224e01649305583916etrawick for _fw in $(modinfo -k $KERNEL_VER -F firmware $1 2>/dev/null); do
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1cde33c7e2019830f8fb3224e01649305583916etrawick if [[ $_found != yes ]]; then
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz if ! grep -qe "\<${_modname//-/_}\>" /proc/modules; then
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz dinfo "Possible missing firmware \"${_fw}\" for kernel module" \
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse dwarn "Possible missing firmware \"${_fw}\" for kernel module" \
bfd35b329124266ebdab96567241bea57f2e8481dougm# Do something with all the dependencies of a kernel module.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# Note that kernel modules depend on themselves using the technique we use
bfd35b329124266ebdab96567241bea57f2e8481dougm# $1 = function to call for each dependency we find
bfd35b329124266ebdab96567241bea57f2e8481dougm# It will be passed the full path to the found kernel module
bfd35b329124266ebdab96567241bea57f2e8481dougm# $2 = module to get dependencies for
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# rest of args = arguments to modprobe
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# _fderr specifies FD passed from surrounding scope
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm local _func=$1 _kmod=$2 _cmd _modpath _options _found=0
a943533fd4d91d114af622731a405407990c4fb1rse modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | (
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm while read _cmd _modpath _options; do
1cde33c7e2019830f8fb3224e01649305583916etrawick [[ $_cmd = insmod ]] || continue
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm $_func ${_modpath} || exit $?
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ $_found -eq 0 ]] && exit 1
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# filter kernel modules to install certain modules that meet specific
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# requirements.
1cde33c7e2019830f8fb3224e01649305583916etrawick# $1 = search only in subdirectory of /kernel/$1
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz# $2 = function to call with module name to filter.
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz# This function will be passed the full path to the module to test.
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz# The behavior of this function can vary depending on whether $hostonly is set.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# If it is, we will only look at modules that are already in memory.
1cde33c7e2019830f8fb3224e01649305583916etrawick# If it is not, we will look at all kernel modules
d12ae8e4992cea4901eed3035335ce3a6533f003jerenkrantz# This function returns the full filenames of modules that match $1
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm if ! [[ $hostonly ]]; then
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm _filtercmd='find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra"'
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm _filtercmd+=' "$KERNEL_MODS/weak-updates" -name "*.ko" -o -name "*.ko.gz"'
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm _filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename '
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if ! [[ $hostonly ]]; then
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra" "$KERNEL_MODS/weak-updates" \
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse -name "*.ko" -o -name "*.ko.gz" -o -name "*.ko.xz" 2>/dev/null
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# instmods [-c] <kernel module> [<kernel module> ... ]
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# instmods [-c] <kernel subsystem>
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# install kernel modules along with all their dependencies.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm# <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm [[ $no_kernel = yes ]] && return
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm find "$KERNEL_MODS" -path "*/${_mod#=}/*" -printf '%f\n' ) \
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse i2o_scsi) return ;; # Do not load this diagnostic-only module
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse # if we are already installed, skip this module and go on
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm [[ -f "$initdir/.kernelmodseen/${_mod%.ko}.ko" ]] && return
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm if [[ $omit_drivers ]] && [[ "$1" =~ $omit_drivers ]]; then
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm # If we are building a host-specific initramfs and this
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse # module is not already loaded, move on to the next one.
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm [[ $hostonly ]] && ! grep -qe "\<${_mod//-/_}\>" /proc/modules \
ee950d863ae02c3105a32e53373fefbc38b96244dougm # We use '-d' option in modprobe only if modules prefix path
ee950d863ae02c3105a32e53373fefbc38b96244dougm # differs from default '/'. This allows us to use Dracut with
ee950d863ae02c3105a32e53373fefbc38b96244dougm # old version of modprobe which doesn't have '-d' option.
ee950d863ae02c3105a32e53373fefbc38b96244dougm [[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/"
ee950d863ae02c3105a32e53373fefbc38b96244dougm # ok, load the module, all its dependencies, and any firmware
bfd35b329124266ebdab96567241bea57f2e8481dougm while read _mod; do
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm local _ret _filter_not_found='FATAL: Module .* not found.'
a943533fd4d91d114af622731a405407990c4fb1rse # Capture all stderr from modprobe to _fderr. We could use {var}>...
0a621c0dfbe5dc8d2ee2a65e84ab833d22d52714dougm # redirections, but that would make dracut require bash4 at least.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse | while read line; do [[ "$line" =~ $_filter_not_found ]] && echo $line || echo $line >&2 ;done | derror
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# inst_libdir_file [-n <pattern>] <file> [<file>...]
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# Install a <file> located on a lib directory to the initramfs image
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# -n <pattern> install non-matching files
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse# Detect lib paths
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse [[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if [ $ret -eq 0 ]; then
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if [ $ret -eq 0 ]; then
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse *) break ;;