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