898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# ex: ts=8 sw=4 sts=4 et filetype=sh
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny VereshchaginLOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes)
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pittif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
09f6f45a29d8691b67152d4e6f5bbb1453be778eEvgeny VereshchaginBASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm"
09f6f45a29d8691b67152d4e6f5bbb1453be778eEvgeny VereshchaginDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier # QEMU's own build system calls it qemu-system-x86_64
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier echo "Could not find a suitable QEMU binary" >&2
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer if [ -f /etc/machine-id ]; then
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer [ -z "$INITRD" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/initrd" ] \
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer && INITRD="/boot/$MACHINE_ID/$KERNEL_VER/initrd"
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer [ -z "$KERNEL_BIN" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/linux" ] \
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer && KERNEL_BIN="/boot/$MACHINE_ID/$KERNEL_VER/linux"
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin default_fedora_initrd=/boot/initramfs-${KERNEL_VER}.img
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin default_debian_initrd=/boot/initrd.img-${KERNEL_VER}
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin [ "$INITRD" ] || { [ -e "$default_fedora_initrd" ] && INITRD=$default_fedora_initrd; }
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin [ "$INITRD" ] || { [ "$LOOKS_LIKE_DEBIAN" ] && [ -e "$default_debian_initrd" ] && INITRD=$default_debian_initrd; }
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierraid=noautodetect \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierconsole=ttyS0 \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack if [ -c /dev/kvm ]; then
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack QEMU_OPTIONS="$QEMU_OPTIONS -machine accel=kvm -enable-kvm -cpu host"
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
24be78d72b931b0175f08cee12fd23d631c024bfEvgeny Vereshchagin ../../systemd-nspawn --register=no --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin # don't forget KERNEL_APPEND='... selinux=1 ...'
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin if [[ "$SETUP_SELINUX" != "yes" ]]; then
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin local _fixfiles_tools="bash uname cat sort uniq awk grep egrep head expr find rm secon setfiles"
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin if ! cp -ar $_conf_dir $initdir/$_conf_dir; then
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin cat <<EOF >$initdir/etc/systemd/system/autorelabel.service
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginDescription=Relabel all filesystems
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginDefaultDependencies=no
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginRequires=local-fs.target
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginConflicts=shutdown.target
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginAfter=local-fs.target
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginBefore=sysinit.target shutdown.target
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginConditionSecurity=selinux
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginConditionPathExists=|/.autorelabel
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && fixfiles -f -F relabel && rm /.autorelabel && systemctl --force reboot'
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginRemainAfterExit=yes
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin mkdir -p $initdir/etc/systemd/system/basic.target.wants
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin ln -fs autorelabel.service $initdir/etc/systemd/system/basic.target.wants/autorelabel.service
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin if ! type -p valgrind; then
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin local _valgrind_bins=$(strace -e execve valgrind /bin/true 2>&1 >/dev/null | perl -lne 'print $1 if /^execve\("([^"]+)"/')
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin local _valgrind_libs=$(LD_DEBUG=files valgrind /bin/true 2>&1 >/dev/null | perl -lne 'print $1 if m{calling init: (/.*vgpreload_.*)}')
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin strace -e open valgrind /bin/true 2>&1 >/dev/null |
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin perl -lne 'if (my ($fname) = /^open\("([^"]+).*= (?!-)\d+/) { print $fname if $fname =~ /debug|\.supp$/ }'
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin local _valgrind_wrapper=$initdir/$ROOTLIBDIR/systemd-under-valgrind
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchaginexec valgrind --leak-check=full --log-file=/valgrind.out $ROOTLIBDIR/systemd "\$@"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier type -P dmeventd >/dev/null && dracut_install dmeventd
ac289ce3f5eb3f13806f7c631c6b23cee18b26daEvgeny Vereshchagin # dmsetup installs 55-dm and 60-persistent-storage-dm on Debian/Ubuntu
ac289ce3f5eb3f13806f7c631c6b23cee18b26daEvgeny Vereshchagin # see https://anonscm.debian.org/cgit/pkg-lvm/lvm2.git/tree/debian/patches/0007-udev.patch
ac289ce3f5eb3f13806f7c631c6b23cee18b26daEvgeny Vereshchagin inst_rules 55-dm.rules 60-persistent-storage-dm.rules
ac289ce3f5eb3f13806f7c631c6b23cee18b26daEvgeny Vereshchagin inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # we strip binaries since debug symbols increase binaries size a lot
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # Create the blank file to use as a root filesystem
1b1eae69ce52ef6c89a1200e8d3758549b291991Daniel Mack dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=400
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek mkfs.ext3 -L systemd "${LOOPDEV}p1"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin ddebug "install any Execs from the service files"
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin export PKG_CONFIG_PATH=$TEST_BASE_DIR/../src/core/
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin systemdsystemunitdir=$(pkg-config --variable=systemdsystemunitdir systemd)
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin systemduserunitdir=$(pkg-config --variable=systemduserunitdir systemd)
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/{$systemdsystemunitdir,$systemduserunitdir}/*.service \
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin | while read i; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /lib/modules/$KERNEL_VER/modules.builtin
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # install plymouth, if found... else remove plymouth service files
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier echo systemd-testsuite > $initdir/etc/hostname
889a90422dd47284dffa32b9234a6e58991b000cRonny ChevalierLABEL=systemd / ext3 rw 0 1
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
7d023341c765c205068e33d23d63a4000ec211dfMartin Pitt # in Debian ldconfig is just a shell script wrapper around ldconfig.real
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
cffae62bcb6912fbaf1b7b282d9d170c9d308897Martin Pitt NSS_LIBS=$(LD_DEBUG=files getent passwd 2>&1 >/dev/null |sed -n '/calling init: .*libnss_/ {s!^.* /!/!; p}')
e63b61be5350dbe92ea12e1eeb96dde251ed9292Evgeny Vereshchagin /etc/dbus-1 /usr/share/dbus-1 -xtype f \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier | while read file; do
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null && find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
d5172c79136fceaac6324fd1896efe1e576fd71dEvgeny Vereshchagin # see http://www.linux-pam.org/Linux-PAM-html/sag-pam_unix.html
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin cp /etc/pam.d/systemd-user $initdir/etc/pam.d/
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -f $i ]] || continue
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /usr/lib/kbd/consolefonts/latarcyrheb-sun16*; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -f $i ]] || continue
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [ -f ${_terminfodir}/l/linux ] && break
53d90f9582f96208b3674da823ad1a3d2c3b1aa4Martin Pitt cp $TEST_BASE_DIR/testsuite.target $initdir/etc/systemd/system/
5c404f1ab8e96efedb983806443ca982a1b2a372Evgeny Vereshchagin cp $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ln -fs testsuite.target $initdir/etc/systemd/system/default.target
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ddebug "cp -ar $initdir $TESTDIR/nspawn-root"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer 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
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $_line = 'not a dynamic executable' ]] && break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $_line =~ $_so_regex ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e ${initdir}/$_file ]] && continue
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $_line =~ not\ found ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dfatal "Missing a shared library required by $_bin."
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dfatal "Run \"ldd $_bin\" to find out what it is."
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Converts numeric logging level to the first letter of level name.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param lvl Numeric logging level in range from 1 to 6.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 1 if @a lvl is out of range.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 if @a lvl is correct.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @result Echoes first letter of level name.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *) return 1;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Internal helper function for _do_dlog()
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param lvl Numeric logging level.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @note This function is not supposed to be called manually. Please use
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# dtrace(), ddebug(), or others instead which wrap this one.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# This function calls _do_dlog() either with parameter msg, or if
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# none is given, it will read standard input and will use every line as
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# This enables:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# dwarn "This is a warning"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# echo "This is a warning" | dwarn
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [ $1 -le $LOG_LEVEL ] || return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [ $# -ge 1 ]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer while read line; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at TRACE level (6)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at DEBUG level (5)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# [ -n "$debug" ] && set -x || :
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at INFO level (4)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at WARN level (3)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at ERROR level (2)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# [ -n "$debug" ] && set -x || :
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at FATAL level (1)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Generic substring function. If $2 is in $1, return 0.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# normalize_path <path>
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Prints the normalized path, where it removes any duplicated
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# and trailing slashes.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $ normalize_path ///test/test//
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# convert_abs_rel <from> <to>
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Prints the relative path, when creating a symlink to <to> from <from>.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $ convert_abs_rel /usr/bin/test /bin/test-2
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local __current __absolute __abssize __cursize __newpath
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer while [[ ${__absolute[__level]} == ${__current[__level]} ]]
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (( __level > __abssize || __level > __cursize ))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for ((__i = __level; __i < __cursize-1; __i++))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Install a directory, keeping symlinks as on the original system.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# will create ${initdir}/lib64, ${initdir}/lib64/file,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# and a symlink ${initdir}/lib -> lib64.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e ${initdir}/"$1" ]] && return 0 # already there
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -L $_file ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mkdir -m 0755 -p "${initdir}/$_file" || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $1 = file to copy to ramdisk
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $2 (optional) Name for the file on the ramdisk
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Location of the image dir is assumed to be $initdir
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# We never overwrite the target if it exists.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if ! [[ -d ${initdir}/$target ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e ${initdir}/$target ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L ${initdir}/$target ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -d "${initdir}/${target%/*}" ]] || inst_dir "${target%/*}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer cp --sparse=always -pfL "$_src" "${initdir}/$target"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# find symlinks linked to given library file
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $1 = library file
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Function searches for symlinks by stripping version numbers appended to
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# library filename, checks if it points to the same target and finally
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# prints the list of symlinks to stdout.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# rev_lib_symlinks libfoo.so.8.1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# (Only if libfoo.so.8 and libfoo.so exists on host system.)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ ! $1 ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local fn="$1" orig="$(readlink -f "$1")" links=''
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ ${fn} =~ .*\.so\..* ]] || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Same as above, but specialized to handle dynamic libraries.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# It handles making symlinks according to how the original library
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# is referenced.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e $initdir/$_dest ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -L $_src ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # Create additional symlinks. See rev_symlinks description.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# find a binary. If we were not passed the full path directly,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# search in the usual places to find the binary.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Same as above, but specialized to install binary executables.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Install binary executable, and all shared library dependencies, if any.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e $initdir/$_target ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $_line = 'not a dynamic executable' ]] && break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $_line =~ $_so_regex ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e ${initdir}/$_file ]] && continue
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $_line =~ not\ found ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dfatal "Missing a shared library required by $_bin."
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dfatal "Run \"ldd $_bin\" to find out what it is."
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# same as above, except for shell scripts.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# If your shell script does not start with shebang, it is not a shell script.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # If debug is set, clean unprintable chars to prevent messing up the term
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $_line =~ $_shebang_regex ]] || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# same as above, but specialized for symlinks
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _src=$1 _target=${2:-$1} _realsrc
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L $1 ]] || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L $initdir/$_target ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if ! [[ -e $initdir/$_realsrc ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -d $_realsrc ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ln -sfn $(convert_abs_rel "${_target}" "${_realsrc}") "$initdir/$_target"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# attempt to install any programs specified in a udev rule
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [ -x /lib/udev/$_prog ]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# udev rules always get installed in the same place, so
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# create a function to install them to make life simpler.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for r in /lib/udev/rules.d /etc/udev/rules.d; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -f $r/$_rule ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -f ${r}$_rule ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# general purpose installation function
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Same args as above.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 2) [[ ! $initdir && -d $2 ]] && export initdir=$2
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $initdir = $2 ]] && set $1;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 3) [[ -z $initdir ]] && export initdir=$2
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *) dfatal "inst only takes 1 or 2 or 3 arguments"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _x in inst_symlink inst_script inst_binary inst_simple; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# install any of listed files
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# If first argument is '-d' and second some destination path, first accessible
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# source is installed into this path, otherwise it will installed in the same
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# path as source. If none of listed files was installed, function return 1.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# On first successful installation it returns with 0 status.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# inst_any -d /bin/foo /bin/bar /bin/baz
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -e $f ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# dracut_install [-o ] <file> [<file> ... ]
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Install <file> to the initramfs image
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# -o optionally install the <file> and don't fail, if it is not there
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $_optional = yes ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dinfo "Skipping program $1 as it cannot be found and is" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# Install a single kernel module along with any firmware it may require.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# $1 = full path to kernel module to install
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # no need to go further if the module is already installed
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ -e "${initdir}/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" ]] \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ -e "$initdir/.kernelmodseen/${1##*/}" ]] && return 0
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ "${1##*/lib/modules/$KERNEL_VER/}" =~ $omit_drivers ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer inst_simple "$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer || return $?
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer for _fw in $(modinfo -k $KERNEL_VER -F firmware $1 2>/dev/null); do
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ $_found != yes ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if ! grep -qe "\<${_modname//-/_}\>" /proc/modules; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dinfo "Possible missing firmware \"${_fw}\" for kernel module" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dwarn "Possible missing firmware \"${_fw}\" for kernel module" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# Do something with all the dependencies of a kernel module.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# Note that kernel modules depend on themselves using the technique we use
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# $1 = function to call for each dependency we find
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# It will be passed the full path to the found kernel module
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# $2 = module to get dependencies for
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# rest of args = arguments to modprobe
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# _fderr specifies FD passed from surrounding scope
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _func=$1 _kmod=$2 _cmd _modpath _options _found=0
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | (
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer while read _cmd _modpath _options; do
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ $_cmd = insmod ]] || continue
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ $_found -eq 0 ]] && exit 1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# filter kernel modules to install certain modules that meet specific
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# requirements.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# $1 = search only in subdirectory of /kernel/$1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# $2 = function to call with module name to filter.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# This function will be passed the full path to the module to test.
c53158818d8cdaf46b3f1b5299b9bda118a1043fThomas Hindoe Paaboel Andersen# The behavior of this function can vary depending on whether $hostonly is set.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# If it is, we will only look at modules that are already in memory.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# If it is not, we will look at all kernel modules
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# This function returns the full filenames of modules that match $1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if ! [[ $hostonly ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _filtercmd='find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra"'
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _filtercmd+=' "$KERNEL_MODS/weak-updates" -name "*.ko" -o -name "*.ko.gz"'
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename '
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if ! [[ $hostonly ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra" "$KERNEL_MODS/weak-updates" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer -name "*.ko" -o -name "*.ko.gz" -o -name "*.ko.xz" 2>/dev/null
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer | xargs modinfo -F filename -k $KERNEL_VER 2>/dev/null
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# instmods [-c] <kernel module> [<kernel module> ... ]
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# instmods [-c] <kernel subsystem>
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# install kernel modules along with all their dependencies.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ $no_kernel = yes ]] && return
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer find "$KERNEL_MODS" -path "*/${_mod#=}/*" -printf '%f\n' ) \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer i2o_scsi) return ;; # Do not load this diagnostic-only module
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # if we are already installed, skip this module and go on
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ -f "$initdir/.kernelmodseen/${_mod%.ko}.ko" ]] && return
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ $omit_drivers ]] && [[ "$1" =~ $omit_drivers ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # If we are building a host-specific initramfs and this
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # module is not already loaded, move on to the next one.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ $hostonly ]] && ! grep -qe "\<${_mod//-/_}\>" /proc/modules \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer && ! echo $add_drivers | grep -qe "\<${_mod}\>" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # We use '-d' option in modprobe only if modules prefix path
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # differs from default '/'. This allows us to use Dracut with
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # old version of modprobe which doesn't have '-d' option.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _moddirname=${KERNEL_MODS%%/lib/modules/*}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # ok, load the module, all its dependencies, and any firmware
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer --set-version $KERNEL_VER ${_moddirname} $_mpargs
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer while read _mod; do
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _ret _filter_not_found='FATAL: Module .* not found.'
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # Capture all stderr from modprobe to _fderr. We could use {var}>...
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # redirections, but that would make dracut require bash4 at least.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer | while read line; do [[ "$line" =~ $_filter_not_found ]] && echo $line || echo $line >&2 ;done | derror
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# inst_libdir_file [-n <pattern>] <file> [<file>...]
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Install a <file> located on a lib directory to the initramfs image
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# -n <pattern> install non-matching files
33a5e20ffaa2cbb2853f14265566bac66a7f9026Harald Hoyer echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Detect lib paths
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $libdir ]] || for libdir in /lib64 /lib; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -d $libdir ]] && libdirs+=" $libdir" && break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [ $ret -eq 0 ]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [ $ret -eq 0 ]; then