test-functions revision 8a8332f77e61d41f3bb28b8f929ed41e0ffaf721
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b#!/bin/bash
002a514a7a09e0b8700895f4f215e4c60e1b4f56cmarqu# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
243dbf825b00fe26765e4fb74da81d31ca50d837clytie# ex: ts=8 sw=4 sts=4 et filetype=sh
243dbf825b00fe26765e4fb74da81d31ca50d837clytiePATH=/sbin:/bin:/usr/sbin:/usr/bin
2ef193a799a61a07638e23e09e615942512e1320dinhtrungexport PATH
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu
397177a3ea73358d997386179e1dabd43bf47c17gouldtjKERNEL_VER=${KERNEL_VER-$(uname -r)}
397177a3ea73358d997386179e1dabd43bf47c17gouldtjKERNEL_MODS="/lib/modules/$KERNEL_VER/"
36de3346306c17768d6c2e284df34581c4cd0e67cmarqu
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"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
3e4d21d472e73bf9110eb6bf7b26f1336cf8e2f2clytiefunction find_qemu_bin() {
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b # SUSE and Red Hat call the binary qemu-kvm
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b # Debian and Gentoo call it kvm
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
14bb38d1bc2db12bf8febf5342c01abfc2bbf55fcmarqu
4b3f4bc82988fdc3a8b570989a6fa1bbadb3eaebcmarqu [ "$ARCH" ] || ARCH=$(uname -m)
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung case $ARCH in
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b x86_64)
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b # QEMU's own build system calls it qemu-system-x86_64
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung ;;
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b i*86)
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b # new i386 version of QEMU
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
60eb8a2a20c360b435029332f3f0067dab0da3e9clytie
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b # i386 version of QEMU
50549eaec302b98609b1238d4ad249a563998914helix [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
50549eaec302b98609b1238d4ad249a563998914helix ;;
2ef193a799a61a07638e23e09e615942512e1320dinhtrung esac
2ef193a799a61a07638e23e09e615942512e1320dinhtrung
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if [ ! -e "$QEMU_BIN" ]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung echo "Could not find a suitable QEMU binary" >&2
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung return 1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung fi
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrungrun_qemu() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [ "$INITRD" ] || INITRD=/boot/initramfs-${KERNEL_VER}.img
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [ "$QEMU_SMP" ] || QEMU_SMP=1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b find_qemu_bin || return 1
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix KERNEL_APPEND="root=/dev/sda1 \
50549eaec302b98609b1238d4ad249a563998914helixsystemd.log_level=debug \
50549eaec302b98609b1238d4ad249a563998914helixraid=noautodetect \
2ef193a799a61a07638e23e09e615942512e1320dinhtrungloglevel=2 \
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_binit=/usr/lib/systemd/systemd \
50549eaec302b98609b1238d4ad249a563998914helixro \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bconsole=ttyS0 \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bselinux=0 \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b$KERNEL_APPEND \
36de3346306c17768d6c2e284df34581c4cd0e67cmarqu"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung QEMU_OPTIONS="-machine accel=kvm:tcg \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung-smp $QEMU_SMP \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung-net none \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung-m 512M \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung-nographic \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung-kernel $KERNEL_BIN \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [ "$INITRD" ]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung fi
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung ( set -x
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrungrun_nspawn() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung set -x
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung ../../systemd-nspawn --boot --directory=$TESTDIR/nspawn-root /usr/lib/systemd/systemd $KERNEL_APPEND
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bsetup_basic_environment() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b # create the basic filesystem layout
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b setup_basic_dirs
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b install_systemd
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung install_missing_libraries
373b0de34a145937d77473735163f6b5860d385ematiphas install_config_files
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b create_rc_local
50549eaec302b98609b1238d4ad249a563998914helix install_basic_tools
2ef193a799a61a07638e23e09e615942512e1320dinhtrung install_libnss
af3a3a2181932782bd969f8c4dce5f058d797276luca_bruno install_pam
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b install_dbus
50549eaec302b98609b1238d4ad249a563998914helix install_fonts
2ef193a799a61a07638e23e09e615942512e1320dinhtrung install_keymaps
af3a3a2181932782bd969f8c4dce5f058d797276luca_bruno install_terminfo
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b install_execs
50549eaec302b98609b1238d4ad249a563998914helix install_plymouth
2ef193a799a61a07638e23e09e615942512e1320dinhtrung install_debug_tools
af3a3a2181932782bd969f8c4dce5f058d797276luca_bruno install_ld_so_conf
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung strip_binaries
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung install_depmod_files
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung generate_module_dependencies
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung # softlink mtab
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung ln -fs /proc/self/mounts $initdir/etc/mtab
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrunginstall_dmevent() {
50549eaec302b98609b1238d4ad249a563998914helix instmods dm_crypt =crypto
2ef193a799a61a07638e23e09e615942512e1320dinhtrung type -P dmeventd >/dev/null && dracut_install dmeventd
15ead0ea74aacd6d56e250b415371c6a9a66fd17mfloryan inst_libdir_file "libdevmapper-event.so*"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_binstall_systemd() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b # install compiled files
50549eaec302b98609b1238d4ad249a563998914helix (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
2ef193a799a61a07638e23e09e615942512e1320dinhtrung # remove unneeded documentation
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu rm -fr $initdir/usr/share/{man,doc,gtk-doc}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b # we strip binaries since debug symbols increase binaries size a lot
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung # and it could fill the available space
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung strip_binaries
373b0de34a145937d77473735163f6b5860d385ematiphas}
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_binstall_missing_libraries() {
50549eaec302b98609b1238d4ad249a563998914helix # install possible missing libraries
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
373b0de34a145937d77473735163f6b5860d385ematiphas inst_libs $i
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
50549eaec302b98609b1238d4ad249a563998914helix}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_bcreate_empty_image() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b rm -f "$TESTDIR/rootdisk.img"
50549eaec302b98609b1238d4ad249a563998914helix # Create the blank file to use as a root filesystem
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=300
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [ -b "$LOOPDEV" ] || return 1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung sfdisk -C 9600 -H 2 -S 32 -L "$LOOPDEV" <<EOF
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung,4800
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung,
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrungEOF
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung mkfs.ext3 -L systemd "${LOOPDEV}p1"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
50549eaec302b98609b1238d4ad249a563998914helixcheck_result_nspawn() {
50549eaec302b98609b1238d4ad249a563998914helix ret=1
50549eaec302b98609b1238d4ad249a563998914helix [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
50549eaec302b98609b1238d4ad249a563998914helix ls -l $TESTDIR/journal/*/*.journal
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung test -s $TESTDIR/failed && ret=$(($ret+1))
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b return $ret
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
50549eaec302b98609b1238d4ad249a563998914helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helixstrip_binaries() {
373b0de34a145937d77473735163f6b5860d385ematiphas ddebug "Strip binaries"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
50549eaec302b98609b1238d4ad249a563998914helix}
2ef193a799a61a07638e23e09e615942512e1320dinhtrung
373b0de34a145937d77473735163f6b5860d385ematiphascreate_rc_local() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b mkdir -p $initdir/etc/rc.d
50549eaec302b98609b1238d4ad249a563998914helix cat >$initdir/etc/rc.d/rc.local <<EOF
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix#!/bin/bash
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_bexit 0
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bEOF
a707c875b46e3c7f5d039f46bedb4b44938069a8helix chmod 0755 $initdir/etc/rc.d/rc.local
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
15ead0ea74aacd6d56e250b415371c6a9a66fd17mfloryan
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_binstall_execs() {
50549eaec302b98609b1238d4ad249a563998914helix # install any Execs from the service files
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
15ead0ea74aacd6d56e250b415371c6a9a66fd17mfloryan | while read i; do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung i=${i##Exec*=}; i=${i##-}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst $i
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung done
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrunggenerate_module_dependencies() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung ! depmod -a -b "$initdir" $KERNEL_VER; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung dfatal "\"depmod -a $KERNEL_VER\" failed."
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung exit 1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung fi
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrunginstall_depmod_files() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst /lib/modules/$KERNEL_VER/modules.order
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst /lib/modules/$KERNEL_VER/modules.builtin
0326e16bad05fdd8c288bad0de3f864f001516a5helix}
50549eaec302b98609b1238d4ad249a563998914helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helixinstall_plymouth() {
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
a6497e78e9df7f139540c920875ba8fe622f9371cwebb # dracut_install plymouth plymouthd
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b # else
50549eaec302b98609b1238d4ad249a563998914helix rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix # fi
af3a3a2181932782bd969f8c4dce5f058d797276luca_bruno}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrunginstall_ld_so_conf() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung cp -a /etc/ld.so.conf* $initdir/etc
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung ldconfig -r "$initdir"
50549eaec302b98609b1238d4ad249a563998914helix}
eb99432764fd5285381fc2b74b7b8ef5e1c6db54dinhtrung
af3a3a2181932782bd969f8c4dce5f058d797276luca_brunoinstall_config_files() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b inst /etc/sysconfig/init
50549eaec302b98609b1238d4ad249a563998914helix inst /etc/passwd
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix inst /etc/shadow
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst /etc/group
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b inst /etc/shells
50549eaec302b98609b1238d4ad249a563998914helix inst /etc/nsswitch.conf
eb99432764fd5285381fc2b74b7b8ef5e1c6db54dinhtrung inst /etc/pam.conf
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst /etc/securetty
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b inst /etc/os-release
50549eaec302b98609b1238d4ad249a563998914helix inst /etc/localtime
eb99432764fd5285381fc2b74b7b8ef5e1c6db54dinhtrung # we want an empty environment
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b > $initdir/etc/environment
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b > $initdir/etc/machine-id
50549eaec302b98609b1238d4ad249a563998914helix # set the hostname
2ef193a799a61a07638e23e09e615942512e1320dinhtrung echo systemd-testsuite > $initdir/etc/hostname
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b # fstab
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b cat >$initdir/etc/fstab <<EOF
50549eaec302b98609b1238d4ad249a563998914helixLABEL=systemd / ext3 rw 0 1
2ef193a799a61a07638e23e09e615942512e1320dinhtrungEOF
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helixinstall_basic_tools() {
2ef193a799a61a07638e23e09e615942512e1320dinhtrung [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
619df37631a53fcf45cbe42ac39a74f9750fee67cmarqu}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helixinstall_debug_tools() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helixinstall_libnss() {
50549eaec302b98609b1238d4ad249a563998914helix # install libnss_files for login
619df37631a53fcf45cbe42ac39a74f9750fee67cmarqu inst_libdir_file "libnss_files*"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrunginstall_dbus() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst /usr/lib/systemd/system/dbus.socket
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst /usr/lib/systemd/system/dbus.service
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung find \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung /etc/dbus-1 -xtype f \
50549eaec302b98609b1238d4ad249a563998914helix | while read file; do
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix inst $file
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
50549eaec302b98609b1238d4ad249a563998914helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helixinstall_pam() {
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b find \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b /etc/pam.d \
50549eaec302b98609b1238d4ad249a563998914helix /etc/security \
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix /lib64/security \
15ead0ea74aacd6d56e250b415371c6a9a66fd17mfloryan /lib/security -xtype f \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b | while read file; do
50549eaec302b98609b1238d4ad249a563998914helix inst $file
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix done
619df37631a53fcf45cbe42ac39a74f9750fee67cmarqu}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helixinstall_keymaps() {
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix for i in \
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b /usr/lib/kbd/keymaps/include/* \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b /usr/lib/kbd/keymaps/i386/include/* \
50549eaec302b98609b1238d4ad249a563998914helix /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix [[ -f $i ]] || continue
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst $i
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
50549eaec302b98609b1238d4ad249a563998914helix}
50549eaec302b98609b1238d4ad249a563998914helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_binstall_fonts() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b for i in \
50549eaec302b98609b1238d4ad249a563998914helix /usr/lib/kbd/consolefonts/latarcyrheb-sun16*; do
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix [[ -f $i ]] || continue
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst $i
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
50549eaec302b98609b1238d4ad249a563998914helix}
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_binstall_terminfo() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [ -f ${_terminfodir}/l/linux ] && break
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung done
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung dracut_install -o ${_terminfodir}/l/linux
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrungsetup_testsuite() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung cp $TEST_BASE_DIR/{testsuite.target,end.service} $initdir/etc/systemd/system/
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
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
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung # make the testsuite the default target
50549eaec302b98609b1238d4ad249a563998914helix ln -fs testsuite.target $initdir/etc/systemd/system/default.target
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bsetup_nspawn_root() {
a707c875b46e3c7f5d039f46bedb4b44938069a8helix rm -fr $TESTDIR/nspawn-root
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung ddebug "cp -ar $initdir $TESTDIR/nspawn-root"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b cp -ar $initdir $TESTDIR/nspawn-root
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b # we don't mount in the nspawn root
50549eaec302b98609b1238d4ad249a563998914helix rm -f $TESTDIR/nspawn-root/etc/fstab
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bsetup_basic_dirs() {
a707c875b46e3c7f5d039f46bedb4b44938069a8helix mkdir -p $initdir/run
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix mkdir -p $initdir/etc/systemd/system
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b mkdir -p $initdir/var/log/journal
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
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
50549eaec302b98609b1238d4ad249a563998914helix if [ -L "/$d" ]; then
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst_symlink "/$d"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b else
50549eaec302b98609b1238d4ad249a563998914helix inst_dir "/$d"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix ln -sfn /run "$initdir/var/run"
50549eaec302b98609b1238d4ad249a563998914helix ln -sfn /run/lock "$initdir/var/lock"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrunginst_libs() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung local _bin=$1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung local _file _line
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ $_line = 'not a dynamic executable' ]] && break
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [[ $_line =~ $_so_regex ]]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung _file=${BASH_REMATCH[1]}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ -e ${initdir}/$_file ]] && continue
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst_library "$_file"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung continue
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung fi
50549eaec302b98609b1238d4ad249a563998914helix
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung if [[ $_line =~ not\ found ]]; then
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b dfatal "Missing a shared library required by $_bin."
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b dfatal "Run \"ldd $_bin\" to find out what it is."
a707c875b46e3c7f5d039f46bedb4b44938069a8helix dfatal "$_line"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix dfatal "dracut cannot create an initrd."
a707c875b46e3c7f5d039f46bedb4b44938069a8helix exit 1
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
50549eaec302b98609b1238d4ad249a563998914helix done
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bimport_testdir() {
a707c875b46e3c7f5d039f46bedb4b44938069a8helix STATEFILE=".testdir"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix [[ -e $STATEFILE ]] && . $STATEFILE
a707c875b46e3c7f5d039f46bedb4b44938069a8helix if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
50549eaec302b98609b1238d4ad249a563998914helix echo "TESTDIR=\"$TESTDIR\"" > $STATEFILE
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix export TESTDIR
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
a707c875b46e3c7f5d039f46bedb4b44938069a8helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417heliximport_initdir() {
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b initdir=$TESTDIR/root
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b export initdir
50549eaec302b98609b1238d4ad249a563998914helix}
50549eaec302b98609b1238d4ad249a563998914helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b## @brief Converts numeric logging level to the first letter of level name.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b#
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.
50549eaec302b98609b1238d4ad249a563998914helix_lvl2char() {
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix case "$1" in
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;;
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix esac
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix## @brief Internal helper function for _do_dlog()
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix#
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# @param lvl Numeric logging level.
50549eaec302b98609b1238d4ad249a563998914helix# @param msg Message.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# @retval 0 It's always returned, even if logging failed.
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung#
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# @note This function is not supposed to be called manually. Please use
50549eaec302b98609b1238d4ad249a563998914helix# dtrace(), ddebug(), or others instead which wrap this one.
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix#
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.
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix#
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# This enables:
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# dwarn "This is a warning"
50549eaec302b98609b1238d4ad249a563998914helix# echo "This is a warning" | dwarn
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helixLOG_LEVEL=4
50549eaec302b98609b1238d4ad249a563998914helix
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bdlog() {
50549eaec302b98609b1238d4ad249a563998914helix [ -z "$LOG_LEVEL" ] && return 0
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix [ $1 -le $LOG_LEVEL ] || return 0
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local lvl="$1"; shift
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b local lvlc=$(_lvl2char "$lvl") || return 0
50549eaec302b98609b1238d4ad249a563998914helix
50549eaec302b98609b1238d4ad249a563998914helix if [ $# -ge 1 ]; then
50549eaec302b98609b1238d4ad249a563998914helix echo "$lvlc: $*"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b else
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung while read line; do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung echo "$lvlc: " "$line"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung done
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung fi
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung## @brief Logs message at TRACE level (6)
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung#
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# @param msg Message.
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# @retval 0 It's always returned, even if logging failed.
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrungdtrace() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung set +x
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung dlog 6 "$@"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [ -n "$debug" ] && set -x || :
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
50549eaec302b98609b1238d4ad249a563998914helix## @brief Logs message at DEBUG level (5)
50549eaec302b98609b1238d4ad249a563998914helix#
50549eaec302b98609b1238d4ad249a563998914helix# @param msg Message.
50549eaec302b98609b1238d4ad249a563998914helix# @retval 0 It's always returned, even if logging failed.
50549eaec302b98609b1238d4ad249a563998914helixddebug() {
50549eaec302b98609b1238d4ad249a563998914helix# set +x
50549eaec302b98609b1238d4ad249a563998914helix dlog 5 "$@"
50549eaec302b98609b1238d4ad249a563998914helix# [ -n "$debug" ] && set -x || :
50549eaec302b98609b1238d4ad249a563998914helix}
50549eaec302b98609b1238d4ad249a563998914helix
50549eaec302b98609b1238d4ad249a563998914helix## @brief Logs message at INFO level (4)
50549eaec302b98609b1238d4ad249a563998914helix#
50549eaec302b98609b1238d4ad249a563998914helix# @param msg Message.
50549eaec302b98609b1238d4ad249a563998914helix# @retval 0 It's always returned, even if logging failed.
50549eaec302b98609b1238d4ad249a563998914helixdinfo() {
50549eaec302b98609b1238d4ad249a563998914helix set +x
50549eaec302b98609b1238d4ad249a563998914helix dlog 4 "$@"
50549eaec302b98609b1238d4ad249a563998914helix [ -n "$debug" ] && set -x || :
50549eaec302b98609b1238d4ad249a563998914helix}
a557f9b884ea0f9544ef5de2d531d20c2a49e50ehelix
50549eaec302b98609b1238d4ad249a563998914helix## @brief Logs message at WARN level (3)
50549eaec302b98609b1238d4ad249a563998914helix#
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# @param msg Message.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# @retval 0 It's always returned, even if logging failed.
a707c875b46e3c7f5d039f46bedb4b44938069a8helixdwarn() {
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix set +x
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b dlog 3 "$@"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [ -n "$debug" ] && set -x || :
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
50549eaec302b98609b1238d4ad249a563998914helix
50549eaec302b98609b1238d4ad249a563998914helix## @brief Logs message at ERROR level (2)
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b#
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# @param msg Message.
a707c875b46e3c7f5d039f46bedb4b44938069a8helix# @retval 0 It's always returned, even if logging failed.
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helixderror() {
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# set +x
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b dlog 2 "$@"
50549eaec302b98609b1238d4ad249a563998914helix# [ -n "$debug" ] && set -x || :
50549eaec302b98609b1238d4ad249a563998914helix}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b## @brief Logs message at FATAL level (1)
a707c875b46e3c7f5d039f46bedb4b44938069a8helix#
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix# @param msg Message.
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# @retval 0 It's always returned, even if logging failed.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bdfatal() {
50549eaec302b98609b1238d4ad249a563998914helix set +x
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix dlog 1 "$@"
8bb4cfc8dd6632ca0e64da6608a02fbfdb13b94cmatiphas [ -n "$debug" ] && set -x || :
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
50549eaec302b98609b1238d4ad249a563998914helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# Generic substring function. If $2 is in $1, return 0.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bstrstr() { [ "${1#*$2*}" != "$1" ]; }
50549eaec302b98609b1238d4ad249a563998914helix
2ef193a799a61a07638e23e09e615942512e1320dinhtrung# normalize_path <path>
2ef193a799a61a07638e23e09e615942512e1320dinhtrung# Prints the normalized path, where it removes any duplicated
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# and trailing slashes.
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# Example:
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# $ normalize_path ///test/test//
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# /test/test
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrungnormalize_path() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung shopt -q -s extglob
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung set -- "${1//+(\/)//}"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung shopt -q -u extglob
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung echo "${1%/}"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# convert_abs_rel <from> <to>
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# Prints the relative path, when creating a symlink to <to> from <from>.
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# Example:
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# $ convert_abs_rel /usr/bin/test /bin/test-2
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# ../../bin/test-2
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrungconvert_abs_rel() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung local __current __absolute __abssize __cursize __newpath
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung local -i __i __level
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
fa7c4dbf91dc38cd0e9d2c10a2f197b04d5c7fd6a_b
50549eaec302b98609b1238d4ad249a563998914helix # corner case #1 - self looping link
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b # corner case #2 - own dir link
50549eaec302b98609b1238d4ad249a563998914helix [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
2ef193a799a61a07638e23e09e615942512e1320dinhtrung
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno IFS="/" __current=($1)
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b IFS="/" __absolute=($2)
50549eaec302b98609b1238d4ad249a563998914helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix __abssize=${#__absolute[@]}
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno __cursize=${#__current[@]}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix while [[ ${__absolute[__level]} == ${__current[__level]} ]]
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix do
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno (( __level++ ))
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if (( __level > __abssize || __level > __cursize ))
50549eaec302b98609b1238d4ad249a563998914helix then
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix break
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
50549eaec302b98609b1238d4ad249a563998914helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix for ((__i = __level; __i < __cursize-1; __i++))
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if ((__i > __level))
50549eaec302b98609b1238d4ad249a563998914helix then
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix __newpath=$__newpath"/"
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b __newpath=$__newpath".."
50549eaec302b98609b1238d4ad249a563998914helix done
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b for ((__i = __level; __i < __abssize; __i++))
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b do
50549eaec302b98609b1238d4ad249a563998914helix if [[ -n $__newpath ]]
2ef193a799a61a07638e23e09e615942512e1320dinhtrung then
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b __newpath=$__newpath"/"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
50549eaec302b98609b1238d4ad249a563998914helix __newpath=$__newpath${__absolute[__i]}
2ef193a799a61a07638e23e09e615942512e1320dinhtrung done
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b echo "$__newpath"
50549eaec302b98609b1238d4ad249a563998914helix}
8e93b18c725c29ca0902d98c944c2d2c98e473acdinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
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_binst_dir() {
50549eaec302b98609b1238d4ad249a563998914helix [[ -e ${initdir}/"$1" ]] && return 0 # already there
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local _dir="$1" _part="${1%/*}" _file
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
50549eaec302b98609b1238d4ad249a563998914helix _dir="$_part $_dir"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix _part=${_part%/*}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix # iterate over parent directories
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix for _file in $_dir; do
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno [[ -e "${initdir}/$_file" ]] && continue
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if [[ -L $_file ]]; then
50549eaec302b98609b1238d4ad249a563998914helix inst_symlink "$_file"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix else
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno # create directory
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b mkdir -m 0755 -p "${initdir}/$_file" || return 1
50549eaec302b98609b1238d4ad249a563998914helix [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung chmod u+w "${initdir}/$_file"
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
a707c875b46e3c7f5d039f46bedb4b44938069a8helix}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
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.
09c6a598c2b7cb18d7ab211e40024b1c11258af5dinhtrunginst_simple() {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ -f "$1" ]] || return 1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung strstr "$1" "/" || return 1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung local _src=$1 target="${2:-$1}"
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 fi
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung # install checksum files also
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung fi
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung ddebug "Installing $_src"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung cp --sparse=always -pfL "$_src" "${initdir}/$target"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
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.
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno#
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# Example:
a6e0b5e0e22d0bb1e1f9a9d7edfb0eb505d42f9fa_b# rev_lib_symlinks libfoo.so.8.1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# output: libfoo.so.8 libfoo.so
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# (Only if libfoo.so.8 and libfoo.so exists on host system.)
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_brev_lib_symlinks() {
50549eaec302b98609b1238d4ad249a563998914helix [[ ! $1 ]] && return 0
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local fn="$1" orig="$(readlink -f "$1")" links=''
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
a707c875b46e3c7f5d039f46bedb4b44938069a8helix [[ ${fn} =~ .*\.so\..* ]] || return 1
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b until [[ ${fn##*.} == so ]]; do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fn="${fn%.*}"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung done
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b echo "${links}"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
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.
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helixinst_library() {
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung strstr "$1" "/" || return 1
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ -e $initdir/$_dest ]] && return 0
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [[ -L $_src ]]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung # install checksum files also
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
50549eaec302b98609b1238d4ad249a563998914helix _reallib=$(readlink -f "$_src")
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix inst_simple "$_reallib" "$_reallib"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst_dir "${_dest%/*}"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
a707c875b46e3c7f5d039f46bedb4b44938069a8helix ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix else
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix inst_simple "$_src" "$_dest"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix # Create additional symlinks. See rev_symlinks description.
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ ! -e $initdir/$_symlink ]] && {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b ddebug "Creating extra symlink: $_symlink"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung inst_symlink $_symlink
25f30f06d7227d2884083cdae329eef777e4e033luca_bruno }
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix}
2ef193a799a61a07638e23e09e615942512e1320dinhtrung
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.
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helixfind_binary() {
2ef193a799a61a07638e23e09e615942512e1320dinhtrung if [[ -z ${1##/*} ]]; then
a6497e78e9df7f139540c920875ba8fe622f9371cwebb if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b echo $1
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix return 0
2ef193a799a61a07638e23e09e615942512e1320dinhtrung fi
a6497e78e9df7f139540c920875ba8fe622f9371cwebb fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix type -P $1
2ef193a799a61a07638e23e09e615942512e1320dinhtrung}
a6497e78e9df7f139540c920875ba8fe622f9371cwebb
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# Same as above, but specialized to install binary executables.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# Install binary executable, and all shared library dependencies, if any.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_binst_binary() {
2ef193a799a61a07638e23e09e615942512e1320dinhtrung local _bin _target
a6497e78e9df7f139540c920875ba8fe622f9371cwebb _bin=$(find_binary "$1") || return 1
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b _target=${2:-$_bin}
a707c875b46e3c7f5d039f46bedb4b44938069a8helix [[ -e $initdir/$_target ]] && return 0
2ef193a799a61a07638e23e09e615942512e1320dinhtrung [[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local _file _line
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
50549eaec302b98609b1238d4ad249a563998914helix # I love bash!
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b [[ $_line = 'not a dynamic executable' ]] && break
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix if [[ $_line =~ $_so_regex ]]; then
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix _file=${BASH_REMATCH[1]}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b [[ -e ${initdir}/$_file ]] && continue
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b inst_library "$_file"
09c6a598c2b7cb18d7ab211e40024b1c11258af5dinhtrung continue
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if [[ $_line =~ not\ found ]]; then
50549eaec302b98609b1238d4ad249a563998914helix dfatal "Missing a shared library required by $_bin."
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix dfatal "Run \"ldd $_bin\" to find out what it is."
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b dfatal "$_line"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b dfatal "dracut cannot create an initrd."
a557f9b884ea0f9544ef5de2d531d20c2a49e50ehelix exit 1
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b inst_simple "$_bin" "$_target"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
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.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_binst_script() {
50549eaec302b98609b1238d4ad249a563998914helix local _bin
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix _bin=$(find_binary "$1") || return 1
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b shift
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung local _line _shebang_regex
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung read -r -n 80 _line <"$_bin"
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:]')
50549eaec302b98609b1238d4ad249a563998914helix _shebang_regex='(#! *)(/[^ ]+).*'
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix [[ $_line =~ $_shebang_regex ]] || return 1
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
a707c875b46e3c7f5d039f46bedb4b44938069a8helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix# same as above, but specialized for symlinks
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_binst_symlink() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b local _src=$1 _target=${2:-$1} _realsrc
50549eaec302b98609b1238d4ad249a563998914helix strstr "$1" "/" || return 1
2ef193a799a61a07638e23e09e615942512e1320dinhtrung [[ -L $1 ]] || return 1
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b [[ -L $initdir/$_target ]] && return 0
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b _realsrc=$(readlink -f "$_src")
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix if ! [[ -e $initdir/$_realsrc ]]; then
2ef193a799a61a07638e23e09e615942512e1320dinhtrung if [[ -d $_realsrc ]]; then
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst_dir "$_realsrc"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b else
a707c875b46e3c7f5d039f46bedb4b44938069a8helix inst "$_realsrc"
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b fi
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"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
a557f9b884ea0f9544ef5de2d531d20c2a49e50ehelix# attempt to install any programs specified in a udev rule
943e5e7c20a16ee1bb4bf6545629b338848fc600dinhtrunginst_rule_programs() {
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local _prog _bin
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then
a4663e18df03502152cd40ff2fbaf3cf747fab11dinhtrung for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b if [ -x /lib/udev/$_prog ]; then
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b _bin=/lib/udev/$_prog
a557f9b884ea0f9544ef5de2d531d20c2a49e50ehelix else
a4663e18df03502152cd40ff2fbaf3cf747fab11dinhtrung _bin=$(find_binary "$_prog") || {
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b continue;
50549eaec302b98609b1238d4ad249a563998914helix }
943e5e7c20a16ee1bb4bf6545629b338848fc600dinhtrung fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
50549eaec302b98609b1238d4ad249a563998914helix dracut_install "$_bin"
a4663e18df03502152cd40ff2fbaf3cf747fab11dinhtrung done
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
a707c875b46e3c7f5d039f46bedb4b44938069a8helix
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# udev rules always get installed in the same place, so
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# create a function to install them to make life simpler.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_binst_rules() {
50549eaec302b98609b1238d4ad249a563998914helix local _target=/etc/udev/rules.d _rule _found
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst_dir "/lib/udev/rules.d"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b inst_dir "$_target"
50549eaec302b98609b1238d4ad249a563998914helix for _rule in "$@"; do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [ "${rule#/}" = "$rule" ]; then
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b for r in /lib/udev/rules.d /etc/udev/rules.d; do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if [[ -f $r/$_rule ]]; then
50549eaec302b98609b1238d4ad249a563998914helix _found="$r/$_rule"
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung inst_simple "$_found"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst_rule_programs "$_found"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
a707c875b46e3c7f5d039f46bedb4b44938069a8helix done
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b for r in '' ./ $dracutbasedir/rules.d/; do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if [[ -f ${r}$_rule ]]; then
50549eaec302b98609b1238d4ad249a563998914helix _found="${r}$_rule"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix inst_simple "$_found" "$_target/${_found##*/}"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst_rule_programs "$_found"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix done
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix# general purpose installation function
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix# Same args as above.
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_binst() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b local _x
50549eaec302b98609b1238d4ad249a563998914helix
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix case $# in
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b 1) ;;
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;;
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b *) dfatal "inst only takes 1 or 2 or 3 arguments"
a707c875b46e3c7f5d039f46bedb4b44938069a8helix exit 1;;
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung esac
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b for _x in inst_symlink inst_script inst_binary inst_simple; do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b $_x "$@" && return 0
50549eaec302b98609b1238d4ad249a563998914helix done
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung return 1
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
a707c875b46e3c7f5d039f46bedb4b44938069a8helix# install any of listed files
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix#
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.
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b#
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# Example:
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung#
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung# inst_any -d /bin/foo /bin/bar /bin/baz
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b#
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
50549eaec302b98609b1238d4ad249a563998914helix# initramfs.
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrunginst_any() {
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local to f
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix [[ $1 = '-d' ]] && to="$2" && shift 2
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b for f in "$@"; do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if [[ -e $f ]]; then
50549eaec302b98609b1238d4ad249a563998914helix [[ $to ]] && inst "$f" "$to" && return 0
2ef193a799a61a07638e23e09e615942512e1320dinhtrung inst "$f" && return 0
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
50549eaec302b98609b1238d4ad249a563998914helix
2ef193a799a61a07638e23e09e615942512e1320dinhtrung return 1
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
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_bdracut_install() {
50549eaec302b98609b1238d4ad249a563998914helix local _optional=no
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung if [[ $1 = '-o' ]]; then
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b _optional=yes
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b shift
50549eaec302b98609b1238d4ad249a563998914helix fi
2ef193a799a61a07638e23e09e615942512e1320dinhtrung while (($# > 0)); do
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b if ! inst "$1" ; then
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if [[ $_optional = yes ]]; then
50549eaec302b98609b1238d4ad249a563998914helix dinfo "Skipping program $1 as it cannot be found and is" \
2ef193a799a61a07638e23e09e615942512e1320dinhtrung "flagged to be optional"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b else
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b dfatal "Failed to install $1"
50549eaec302b98609b1238d4ad249a563998914helix exit 1
50549eaec302b98609b1238d4ad249a563998914helix fi
50549eaec302b98609b1238d4ad249a563998914helix fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b shift
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b# Install a single kernel module along with any firmware it may require.
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# $1 = full path to kernel module to install
50549eaec302b98609b1238d4ad249a563998914helixinstall_kmod_with_fw() {
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung # no need to go further if the module is already installed
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ -e "${initdir}/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" ]] \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung && return 0
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ -e "$initdir/.kernelmodseen/${1##*/}" ]] && return 0
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [[ $omit_drivers ]]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung local _kmod=${1##*/}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung _kmod=${_kmod%.ko}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung _kmod=${_kmod/-/_}
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [[ "$_kmod" =~ $omit_drivers ]]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung dinfo "Omitting driver $_kmod"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung return 1
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix fi
50549eaec302b98609b1238d4ad249a563998914helix if [[ "${1##*/lib/modules/$KERNEL_VER/}" =~ $omit_drivers ]]; then
50549eaec302b98609b1238d4ad249a563998914helix dinfo "Omitting driver $_kmod"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b return 1
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
50549eaec302b98609b1238d4ad249a563998914helix fi
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b [ -d "$initdir/.kernelmodseen" ] && \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b > "$initdir/.kernelmodseen/${1##*/}"
50549eaec302b98609b1238d4ad249a563998914helix
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung inst_simple "$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b || return $?
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix local _modname=${1##*/} _fwdir _found _fw
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung _modname=${_modname%.ko*}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b for _fw in $(modinfo -k $KERNEL_VER -F firmware $1 2>/dev/null); do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b _found=''
50549eaec302b98609b1238d4ad249a563998914helix for _fwdir in $fw_dir; do
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b _found=yes
50549eaec302b98609b1238d4ad249a563998914helix fi
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung done
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b if [[ $_found != yes ]]; then
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if ! grep -qe "\<${_modname//-/_}\>" /proc/modules; then
50549eaec302b98609b1238d4ad249a563998914helix dinfo "Possible missing firmware \"${_fw}\" for kernel module" \
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung "\"${_modname}.ko\""
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b else
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b dwarn "Possible missing firmware \"${_fw}\" for kernel module" \
50549eaec302b98609b1238d4ad249a563998914helix "\"${_modname}.ko\""
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung fi
79f4234f1b5d0e3250d1feee19bbc0e51571ed24helix fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b done
50549eaec302b98609b1238d4ad249a563998914helix return 0
eb99432764fd5285381fc2b74b7b8ef5e1c6db54dinhtrung}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
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
50549eaec302b98609b1238d4ad249a563998914helixfor_each_kmod_dep() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b local _func=$1 _kmod=$2 _cmd _modpath _options _found=0
a707c875b46e3c7f5d039f46bedb4b44938069a8helix shift 2
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 $?
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung _found=1
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ $_found -eq 0 ]] && exit 1
50549eaec302b98609b1238d4ad249a563998914helix exit 0
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung )
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
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
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helixfilter_kernel_modules_by_path () (
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local _modname _filtercmd
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"'
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b _filtercmd+=' -o -name "*.ko.xz"'
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b _filtercmd+=' 2>/dev/null'
50549eaec302b98609b1238d4ad249a563998914helix else
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung _filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename '
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b _filtercmd+='-k $KERNEL_VER 2>/dev/null'
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
50549eaec302b98609b1238d4ad249a563998914helix for _modname in $(eval $_filtercmd); do
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung case $_modname in
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b *.ko) "$2" "$_modname" && echo "$_modname";;
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b *.ko.gz) gzip -dc "$_modname" > $initdir/$$.ko
50549eaec302b98609b1238d4ad249a563998914helix $2 $initdir/$$.ko && echo "$_modname"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix rm -f $initdir/$$.ko
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b ;;
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b *.ko.xz) xz -dc "$_modname" > $initdir/$$.ko
a707c875b46e3c7f5d039f46bedb4b44938069a8helix $2 $initdir/$$.ko && echo "$_modname"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung rm -f $initdir/$$.ko
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b ;;
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b esac
50549eaec302b98609b1238d4ad249a563998914helix done
2ef193a799a61a07638e23e09e615942512e1320dinhtrung)
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_bfind_kernel_modules_by_path () (
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
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b else
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b cut -d " " -f 1 </proc/modules \
a557f9b884ea0f9544ef5de2d531d20c2a49e50ehelix | xargs modinfo -F filename -k $KERNEL_VER 2>/dev/null
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b)
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helixfilter_kernel_modules () {
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung filter_kernel_modules_by_path drivers "$1"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helixfind_kernel_modules () {
eb99432764fd5285381fc2b74b7b8ef5e1c6db54dinhtrung find_kernel_modules_by_path drivers
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
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"
50549eaec302b98609b1238d4ad249a563998914helixinstmods() {
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix [[ $no_kernel = yes ]] && return
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b # called [sub]functions inherit _fderr
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b local _fderr=9
50549eaec302b98609b1238d4ad249a563998914helix local _check=no
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung if [[ $1 = '-c' ]]; then
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b _check=yes
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b shift
a707c875b46e3c7f5d039f46bedb4b44938069a8helix fi
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b function inst1mod() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b local _ret=0 _mod="$1"
50549eaec302b98609b1238d4ad249a563998914helix case $_mod in
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung =*)
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b if [ -f $KERNEL_MODS/modules.${_mod#=} ]; then
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b ( [[ "$_mpargs" ]] && echo $_mpargs
50549eaec302b98609b1238d4ad249a563998914helix cat "${KERNEL_MODS}/modules.${_mod#=}" ) \
2ef193a799a61a07638e23e09e615942512e1320dinhtrung | instmods
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b else
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b ( [[ "$_mpargs" ]] && echo $_mpargs
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung find "$KERNEL_MODS" -path "*/${_mod#=}/*" -printf '%f\n' ) \
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung | instmods
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b ;;
a707c875b46e3c7f5d039f46bedb4b44938069a8helix --*) _mpargs+=" $_mod" ;;
943e5e7c20a16ee1bb4bf6545629b338848fc600dinhtrung i2o_scsi) return ;; # Do not load this diagnostic-only module
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b *)
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b _mod=${_mod##*/}
a707c875b46e3c7f5d039f46bedb4b44938069a8helix # if we are already installed, skip this module and go on
a4663e18df03502152cd40ff2fbaf3cf747fab11dinhtrung # to the next one.
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b [[ -f "$initdir/.kernelmodseen/${_mod%.ko}.ko" ]] && return
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix if [[ $omit_drivers ]] && [[ "$1" =~ $omit_drivers ]]; then
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung dinfo "Omitting driver ${_mod##$KERNEL_MODS}"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b return
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
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 \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b && ! echo $add_drivers | grep -qe "\<${_mod}\>" \
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix && return
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung
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.
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung local _moddirname=${KERNEL_MODS%%/lib/modules/*}
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b [[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
50549eaec302b98609b1238d4ad249a563998914helix # ok, load the module, all its dependencies, and any firmware
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung # it may require
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b for_each_kmod_dep install_kmod_with_fw $_mod \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b --set-version $KERNEL_VER ${_moddirname} $_mpargs
50549eaec302b98609b1238d4ad249a563998914helix ((_ret+=$?))
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung ;;
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b esac
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b return $_ret
50549eaec302b98609b1238d4ad249a563998914helix }
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung
50549eaec302b98609b1238d4ad249a563998914helix function instmods_1() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b local _mod _mpargs
a707c875b46e3c7f5d039f46bedb4b44938069a8helix if (($# == 0)); then # filenames from stdin
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung while read _mod; do
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b inst1mod "${_mod%.ko*}" || {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b if [ "$_check" = "yes" ]; then
50549eaec302b98609b1238d4ad249a563998914helix dfatal "Failed to install $_mod"
8e93b18c725c29ca0902d98c944c2d2c98e473acdinhtrung return 1
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b }
50549eaec302b98609b1238d4ad249a563998914helix done
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung fi
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b while (($# > 0)); do # filenames as arguments
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b inst1mod ${1%.ko*} || {
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix if [ "$_check" = "yes" ]; then
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung dfatal "Failed to install $1"
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b return 1
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
50549eaec302b98609b1238d4ad249a563998914helix }
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung shift
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b return 0
50549eaec302b98609b1238d4ad249a563998914helix }
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b local _ret _filter_not_found='FATAL: Module .* not found.'
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b set -o pipefail
50549eaec302b98609b1238d4ad249a563998914helix # Capture all stderr from modprobe to _fderr. We could use {var}>...
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung # redirections, but that would make dracut require bash4 at least.
79f4234f1b5d0e3250d1feee19bbc0e51571ed24helix eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b | while read line; do [[ "$line" =~ $_filter_not_found ]] && echo $line || echo $line >&2 ;done | derror
50549eaec302b98609b1238d4ad249a563998914helix _ret=$?
50549eaec302b98609b1238d4ad249a563998914helix set +o pipefail
eb99432764fd5285381fc2b74b7b8ef5e1c6db54dinhtrung return $_ret
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
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
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_binst_libdir_file() {
a707c875b46e3c7f5d039f46bedb4b44938069a8helix if [[ "$1" == "-n" ]]; then
eb99432764fd5285381fc2b74b7b8ef5e1c6db54dinhtrung local _pattern=$1
a707c875b46e3c7f5d039f46bedb4b44938069a8helix shift 2
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b for _dir in $libdirs; do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung for _i in "$@"; do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung for _f in "$_dir"/$_i; do
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu [[ "$_i" =~ $_pattern ]] || continue
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ -e "$_i" ]] && dracut_install "$_i"
a557f9b884ea0f9544ef5de2d531d20c2a49e50ehelix done
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung done
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b else
a557f9b884ea0f9544ef5de2d531d20c2a49e50ehelix for _dir in $libdirs; do
3c60a84ec01cc697eaa48c4df51aa60c8483a7c1dinhtrung for _i in "$@"; do
50549eaec302b98609b1238d4ad249a563998914helix for _f in "$_dir"/$_i; do
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ -e "$_f" ]] && dracut_install "$_f"
50549eaec302b98609b1238d4ad249a563998914helix done
2ef193a799a61a07638e23e09e615942512e1320dinhtrung done
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu done
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
50549eaec302b98609b1238d4ad249a563998914helix}
2ef193a799a61a07638e23e09e615942512e1320dinhtrung
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqucheck_nspawn() {
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b [[ -d /sys/fs/cgroup/systemd ]]
50549eaec302b98609b1238d4ad249a563998914helix}
2ef193a799a61a07638e23e09e615942512e1320dinhtrung
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_bdo_test() {
50549eaec302b98609b1238d4ad249a563998914helix if [[ $UID != "0" ]]; then
2ef193a799a61a07638e23e09e615942512e1320dinhtrung echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b exit 0
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b# Detect lib paths
09c6a598c2b7cb18d7ab211e40024b1c11258af5dinhtrung [[ $libdir ]] || for libdir in /lib64 /lib; do
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu [[ -d $libdir ]] && libdirs+=" $libdir" && break
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung done
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung [[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung done
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung import_testdir
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung import_initdir
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung while (($# > 0)); do
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung case $1 in
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung --run)
c573cf21fec48b8494843de05a2c980241579639a_b echo "TEST RUN: $TEST_DESCRIPTION"
1272d5833b22e38838fbeb15124194b0d25ce5e2dinhtrung test_run
1272d5833b22e38838fbeb15124194b0d25ce5e2dinhtrung ret=$?
bd039494532bd2357f0ba00925350aef5d45bc6bmfloryan if [ $ret -eq 0 ]; then
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b echo "TEST RUN: $TEST_DESCRIPTION [OK]"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b else
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung echo "TEST RUN: $TEST_DESCRIPTION [FAILED]"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b fi
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix exit $ret;;
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b --setup)
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b echo "TEST SETUP: $TEST_DESCRIPTION"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b test_setup
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b exit $?;;
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b --clean)
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b echo "TEST CLEANUP: $TEST_DESCRIPTION"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung test_cleanup
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu rm -fr "$TESTDIR"
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix rm -f .testdir
50549eaec302b98609b1238d4ad249a563998914helix exit $?;;
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix --all)
ac2de0b006739c10b0ab8917e9c470200c06ee2dcmarqu echo -n "TEST: $TEST_DESCRIPTION ";
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b (
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung test_setup && test_run
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung ret=$?
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b test_cleanup
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung rm -fr "$TESTDIR"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung rm -f .testdir
50549eaec302b98609b1238d4ad249a563998914helix exit $ret
0ffaca14f817ec18008e13e5f55fe8bdf50b793fdinhtrung ) </dev/null >test.log 2>&1
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b ret=$?
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung if [ $ret -eq 0 ]; then
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung rm test.log
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung echo "[OK]"
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung else
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b echo "[FAILED]"
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b echo "see $(pwd)/test.log"
50549eaec302b98609b1238d4ad249a563998914helix fi
aae7d4ba8b026fa82bfd806d5d241cfdccc2e417helix exit $ret;;
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b *) break ;;
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b esac
50549eaec302b98609b1238d4ad249a563998914helix shift
e911f806217c1a0342b2784a191c680322ae1c4fdinhtrung done
84bf0dd3306786b80273a5abb30dd16288eb3d9fa_b}
f10fb5cad8d62a15b25367b76cc004a4d5e4c12aa_b