898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#!/bin/bash
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
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerPATH=/sbin:/bin:/usr/sbin:/usr/bin
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerexport PATH
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny VereshchaginLOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes)
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald HoyerKERNEL_VER=${KERNEL_VER-$(uname -r)}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald HoyerKERNEL_MODS="/lib/modules/$KERNEL_VER/"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pittif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt ROOTLIBDIR=/usr/lib/systemd
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pittfi
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt
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"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierfunction find_qemu_bin() {
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier # SUSE and Red Hat call the binary qemu-kvm
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier # Debian and Gentoo call it kvm
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$ARCH" ] || ARCH=$(uname -m)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier case $ARCH in
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier x86_64)
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 ;;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier i*86)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier # new i386 version of QEMU
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier # i386 version of QEMU
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier ;;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier esac
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if [ ! -e "$QEMU_BIN" ]; then
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier echo "Could not find a suitable QEMU binary" >&2
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return 1
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier fi
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier}
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierrun_qemu() {
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer if [ -f /etc/machine-id ]; then
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer read MACHINE_ID < /etc/machine-id
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"
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer fi
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer
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 Chevalier [ "$QEMU_SMP" ] || QEMU_SMP=1
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier find_qemu_bin || return 1
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier KERNEL_APPEND="root=/dev/sda1 \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevaliersystemd.log_level=debug \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierraid=noautodetect \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierloglevel=2 \
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pittinit=$ROOTLIBDIR/systemd \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierro \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierconsole=ttyS0 \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierselinux=0 \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier$KERNEL_APPEND \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack QEMU_OPTIONS="-smp $QEMU_SMP \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier-net none \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier-m 512M \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier-nographic \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier-kernel $KERNEL_BIN \
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if [ "$INITRD" ]; then
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier fi
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack if [ -c /dev/kvm ]; then
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack QEMU_OPTIONS="$QEMU_OPTIONS -machine accel=kvm -enable-kvm -cpu host"
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack fi
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek ( set -x
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierrun_nspawn() {
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek set -x
24be78d72b931b0175f08cee12fd23d631c024bfEvgeny Vereshchagin ../../systemd-nspawn --register=no --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliersetup_basic_environment() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # create the basic filesystem layout
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier setup_basic_dirs
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_systemd
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_missing_libraries
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_config_files
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier create_rc_local
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_basic_tools
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_libnss
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_pam
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_dbus
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_fonts
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_keymaps
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_terminfo
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_execs
9974ff63b182e67bf3d3d9262e2bfa84f0a1378bEvgeny Vereshchagin install_fsck
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_plymouth
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_debug_tools
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_ld_so_conf
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin setup_selinux
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strip_binaries
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier install_depmod_files
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier generate_module_dependencies
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchaginsetup_selinux() {
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin # don't forget KERNEL_APPEND='... selinux=1 ...'
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin if [[ "$SETUP_SELINUX" != "yes" ]]; then
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin ddebug "Don't setup SELinux"
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin return 0
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin fi
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin ddebug "Setup SELinux"
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin local _conf_dir=/etc/selinux
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin local _fixfiles_tools="bash uname cat sort uniq awk grep egrep head expr find rm secon setfiles"
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin rm -rf $initdir/$_conf_dir
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin if ! cp -ar $_conf_dir $initdir/$_conf_dir; then
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin dfatal "Failed to copy $_conf_dir"
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin exit 1
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin fi
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin cat <<EOF >$initdir/etc/systemd/system/autorelabel.service
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin[Unit]
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 Vereshchagin
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin[Service]
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && fixfiles -f -F relabel && rm /.autorelabel && systemctl --force reboot'
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginType=oneshot
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginTimeoutSec=0
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginRemainAfterExit=yes
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny VereshchaginEOF
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin touch $initdir/.autorelabel
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
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin dracut_install $_fixfiles_tools
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin dracut_install fixfiles
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin dracut_install sestatus
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin}
e3ce42e70504922f0ea7149f90fc80b549844e93Evgeny Vereshchagin
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagininstall_valgrind() {
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin if ! type -p valgrind; then
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin dfatal "Failed to install valgrind"
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin exit 1
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin fi
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin local _valgrind_bins=$(strace -e execve valgrind /bin/true 2>&1 >/dev/null | perl -lne 'print $1 if /^execve\("([^"]+)"/')
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin dracut_install $_valgrind_bins
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin
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 dracut_install $_valgrind_libs
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin local _valgrind_dbg_and_supp=$(
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$/ }'
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin )
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin dracut_install $_valgrind_dbg_and_supp
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin}
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagincreate_valgrind_wrapper() {
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin local _valgrind_wrapper=$initdir/$ROOTLIBDIR/systemd-under-valgrind
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin ddebug "Create $_valgrind_wrapper"
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin cat >$_valgrind_wrapper <<EOF
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin#!/bin/bash
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchaginexec valgrind --leak-check=full --log-file=/valgrind.out $ROOTLIBDIR/systemd "\$@"
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny VereshchaginEOF
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin chmod 0755 $_valgrind_wrapper
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin}
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin
9974ff63b182e67bf3d3d9262e2bfa84f0a1378bEvgeny Vereshchagininstall_fsck() {
9974ff63b182e67bf3d3d9262e2bfa84f0a1378bEvgeny Vereshchagin dracut_install /sbin/fsck*
9974ff63b182e67bf3d3d9262e2bfa84f0a1378bEvgeny Vereshchagin dracut_install -o /bin/fsck*
9974ff63b182e67bf3d3d9262e2bfa84f0a1378bEvgeny Vereshchagin}
9974ff63b182e67bf3d3d9262e2bfa84f0a1378bEvgeny Vereshchagin
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_dmevent() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier instmods dm_crypt =crypto
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier type -P dmeventd >/dev/null && dracut_install dmeventd
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst_libdir_file "libdevmapper-event.so*"
ac289ce3f5eb3f13806f7c631c6b23cee18b26daEvgeny Vereshchagin if [[ "$LOOKS_LIKE_DEBIAN" ]]; then
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 else
ac289ce3f5eb3f13806f7c631c6b23cee18b26daEvgeny Vereshchagin inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
ac289ce3f5eb3f13806f7c631c6b23cee18b26daEvgeny Vereshchagin fi
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_systemd() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # install compiled files
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # remove unneeded documentation
2375607039517c88df51ef16ddbb624ec1c10654Kay Sievers rm -fr $initdir/usr/share/{man,doc}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # we strip binaries since debug symbols increase binaries size a lot
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # and it could fill the available space
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strip_binaries
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_missing_libraries() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # install possible missing libraries
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst_libs $i
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier done
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliercreate_empty_image() {
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek rm -f "$TESTDIR/rootdisk.img"
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 [ -b "$LOOPDEV" ] || return 1
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
edbced8a151c1b7ded685e2ec644950d2adec5f5Harald Hoyer sfdisk "$LOOPDEV" <<EOF
1b1eae69ce52ef6c89a1200e8d3758549b291991Daniel Mack,390M
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier,
889a90422dd47284dffa32b9234a6e58991b000cRonny ChevalierEOF
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek mkfs.ext3 -L systemd "${LOOPDEV}p1"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliercheck_result_nspawn() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ret=1
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 ls -l $TESTDIR/journal/*/*.journal
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier test -s $TESTDIR/failed && ret=$(($ret+1))
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return $ret
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierstrip_binaries() {
5a613464fa15c0960b418322f592a24b9e0f7455Evgeny Vereshchagin if [[ "$STRIP_BINARIES" = "no" ]]; then
5a613464fa15c0960b418322f592a24b9e0f7455Evgeny Vereshchagin ddebug "Don't strip binaries"
5a613464fa15c0960b418322f592a24b9e0f7455Evgeny Vereshchagin return 0
5a613464fa15c0960b418322f592a24b9e0f7455Evgeny Vereshchagin fi
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ddebug "Strip binaries"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliercreate_rc_local() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier mkdir -p $initdir/etc/rc.d
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier cat >$initdir/etc/rc.d/rc.local <<EOF
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier#!/bin/bash
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierexit 0
889a90422dd47284dffa32b9234a6e58991b000cRonny ChevalierEOF
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier chmod 0755 $initdir/etc/rc.d/rc.local
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_execs() {
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin ddebug "install any Execs from the service files"
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin (
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
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin i=${i##Exec*=}; i=${i##-}
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin inst $i
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin done
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin )
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliergenerate_module_dependencies() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ! depmod -a -b "$initdir" $KERNEL_VER; then
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier dfatal "\"depmod -a $KERNEL_VER\" failed."
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier exit 1
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier fi
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_depmod_files() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /lib/modules/$KERNEL_VER/modules.order
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /lib/modules/$KERNEL_VER/modules.builtin
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_plymouth() {
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 # dracut_install plymouth plymouthd
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # else
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # fi
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_ld_so_conf() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier cp -a /etc/ld.so.conf* $initdir/etc
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ldconfig -r "$initdir"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_config_files() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/sysconfig/init
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/passwd
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/shadow
bf3a947cb44f31359bba313e0252cbcc0dc95b03Evgeny Vereshchagin inst /etc/login.defs
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/group
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/shells
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/nsswitch.conf
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/pam.conf
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/securetty
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/os-release
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst /etc/localtime
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # we want an empty environment
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier > $initdir/etc/environment
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier > $initdir/etc/machine-id
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # set the hostname
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier echo systemd-testsuite > $initdir/etc/hostname
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # fstab
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier cat >$initdir/etc/fstab <<EOF
889a90422dd47284dffa32b9234a6e58991b000cRonny ChevalierLABEL=systemd / ext3 rw 0 1
889a90422dd47284dffa32b9234a6e58991b000cRonny ChevalierEOF
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_basic_tools() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
4be4833ece2856e0cacc09f8f8b2c02b320751faMartin Pitt dracut_install -o sushell
7d023341c765c205068e33d23d63a4000ec211dfMartin Pitt # in Debian ldconfig is just a shell script wrapper around ldconfig.real
7d023341c765c205068e33d23d63a4000ec211dfMartin Pitt dracut_install -o ldconfig.real
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_debug_tools() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_libnss() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # install libnss_files for login
cffae62bcb6912fbaf1b7b282d9d170c9d308897Martin Pitt NSS_LIBS=$(LD_DEBUG=files getent passwd 2>&1 >/dev/null |sed -n '/calling init: .*libnss_/ {s!^.* /!/!; p}')
99877b7e3782a51b31bf191825f0335500f52fe5Harald Hoyer dracut_install $NSS_LIBS
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_dbus() {
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt inst $ROOTLIBDIR/system/dbus.socket
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt inst $ROOTLIBDIR/system/dbus.service
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier find \
e63b61be5350dbe92ea12e1eeb96dde251ed9292Evgeny Vereshchagin /etc/dbus-1 /usr/share/dbus-1 -xtype f \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier | while read file; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst $file
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier done
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_pam() {
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin (
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null && find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier find \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /etc/pam.d \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /etc/security \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /lib64/security \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /lib/security -xtype f \
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin ) | while read file; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst $file
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier done
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin
d5172c79136fceaac6324fd1896efe1e576fd71dEvgeny Vereshchagin # pam_unix depends on unix_chkpwd.
d5172c79136fceaac6324fd1896efe1e576fd71dEvgeny Vereshchagin # see http://www.linux-pam.org/Linux-PAM-html/sag-pam_unix.html
d5172c79136fceaac6324fd1896efe1e576fd71dEvgeny Vereshchagin dracut_install -o unix_chkpwd
d5172c79136fceaac6324fd1896efe1e576fd71dEvgeny Vereshchagin
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin [[ "$LOOKS_LIKE_DEBIAN" ]] &&
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin cp /etc/pam.d/systemd-user $initdir/etc/pam.d/
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_keymaps() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier for i in \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /usr/lib/kbd/keymaps/include/* \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /usr/lib/kbd/keymaps/i386/include/* \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -f $i ]] || continue
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst $i
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier done
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_fonts() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier for i in \
25b47f96d9601ff566257b2a31bfb5f4bd25d661Marko Myllynen /usr/lib/kbd/consolefonts/eurlatgr* \
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /usr/lib/kbd/consolefonts/latarcyrheb-sun16*; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -f $i ]] || continue
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier inst $i
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier done
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierinstall_terminfo() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [ -f ${_terminfodir}/l/linux ] && break
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier done
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier dracut_install -o ${_terminfodir}/l/linux
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliersetup_testsuite() {
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
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
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # make the testsuite the default target
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ln -fs testsuite.target $initdir/etc/systemd/system/default.target
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliersetup_nspawn_root() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier rm -fr $TESTDIR/nspawn-root
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ddebug "cp -ar $initdir $TESTDIR/nspawn-root"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier cp -ar $initdir $TESTDIR/nspawn-root
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier # we don't mount in the nspawn root
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier rm -f $TESTDIR/nspawn-root/etc/fstab
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyersetup_basic_dirs() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier mkdir -p $initdir/run
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier mkdir -p $initdir/etc/systemd/system
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier mkdir -p $initdir/var/log/journal
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
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 if [ -L "/$d" ]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_symlink "/$d"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer inst_dir "/$d"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ln -sfn /run "$initdir/var/run"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ln -sfn /run/lock "$initdir/var/lock"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerinst_libs() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _bin=$1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _file _line
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $_line = 'not a dynamic executable' ]] && break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $_line =~ $_so_regex ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _file=${BASH_REMATCH[1]}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e ${initdir}/$_file ]] && continue
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_library "$_file"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer continue
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 dfatal "$_line"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dfatal "dracut cannot create an initrd."
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerimport_testdir() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer STATEFILE=".testdir"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e $STATEFILE ]] && . $STATEFILE
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "TESTDIR=\"$TESTDIR\"" > $STATEFILE
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer export TESTDIR
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierimport_initdir() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier initdir=$TESTDIR/root
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier export initdir
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Converts numeric logging level to the first letter of level name.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
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_lvl2char() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case "$1" in
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 1) echo F;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 2) echo E;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 3) echo W;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 4) echo I;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 5) echo D;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 6) echo T;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *) return 1;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer esac
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Internal helper function for _do_dlog()
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
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#
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#
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# a message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# This enables:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# dwarn "This is a warning"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# echo "This is a warning" | dwarn
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerLOG_LEVEL=4
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerdlog() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [ -z "$LOG_LEVEL" ] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [ $1 -le $LOG_LEVEL ] || return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local lvl="$1"; shift
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local lvlc=$(_lvl2char "$lvl") || return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [ $# -ge 1 ]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "$lvlc: $*"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer while read line; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "$lvlc: " "$line"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at TRACE level (6)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerdtrace() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer set +x
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dlog 6 "$@"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [ -n "$debug" ] && set -x || :
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at DEBUG level (5)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerddebug() {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# set +x
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dlog 5 "$@"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# [ -n "$debug" ] && set -x || :
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at INFO level (4)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerdinfo() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer set +x
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dlog 4 "$@"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [ -n "$debug" ] && set -x || :
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at WARN level (3)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerdwarn() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer set +x
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dlog 3 "$@"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [ -n "$debug" ] && set -x || :
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at ERROR level (2)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerderror() {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# set +x
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dlog 2 "$@"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer# [ -n "$debug" ] && set -x || :
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer## @brief Logs message at FATAL level (1)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @param msg Message.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# @retval 0 It's always returned, even if logging failed.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerdfatal() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer set +x
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dlog 1 "$@"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [ -n "$debug" ] && set -x || :
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Generic substring function. If $2 is in $1, return 0.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstrstr() { [ "${1#*$2*}" != "$1" ]; }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# normalize_path <path>
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Prints the normalized path, where it removes any duplicated
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# and trailing slashes.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Example:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $ normalize_path ///test/test//
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# /test/test
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyernormalize_path() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer shopt -q -s extglob
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer set -- "${1//+(\/)//}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer shopt -q -u extglob
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "${1%/}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# convert_abs_rel <from> <to>
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Prints the relative path, when creating a symlink to <to> from <from>.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Example:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $ convert_abs_rel /usr/bin/test /bin/test-2
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# ../../bin/test-2
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerconvert_abs_rel() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local __current __absolute __abssize __cursize __newpath
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local -i __i __level
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # corner case #1 - self looping link
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # corner case #2 - own dir link
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer IFS="/" __current=($1)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer IFS="/" __absolute=($2)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer __abssize=${#__absolute[@]}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer __cursize=${#__current[@]}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer while [[ ${__absolute[__level]} == ${__current[__level]} ]]
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer (( __level++ ))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (( __level > __abssize || __level > __cursize ))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for ((__i = __level; __i < __cursize-1; __i++))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if ((__i > __level))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer __newpath=$__newpath"/"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer __newpath=$__newpath".."
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for ((__i = __level; __i < __abssize; __i++))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -n $__newpath ]]
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer __newpath=$__newpath"/"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer __newpath=$__newpath${__absolute[__i]}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "$__newpath"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 Hoyerinst_dir() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e ${initdir}/"$1" ]] && return 0 # already there
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _dir="$1" _part="${1%/*}" _file
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _dir="$_part $_dir"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _part=${_part%/*}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # iterate over parent directories
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _file in $_dir; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e "${initdir}/$_file" ]] && continue
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -L $_file ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_symlink "$_file"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # create directory
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mkdir -m 0755 -p "${initdir}/$_file" || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer chmod u+w "${initdir}/$_file"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 Hoyerinst_simple() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -f "$1" ]] || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer strstr "$1" "/" || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _src=$1 target="${2:-$1}"
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 fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # install checksum files also
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ddebug "Installing $_src"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer cp --sparse=always -pfL "$_src" "${initdir}/$target"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Example:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# rev_lib_symlinks libfoo.so.8.1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# output: libfoo.so.8 libfoo.so
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# (Only if libfoo.so.8 and libfoo.so exists on host system.)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerrev_lib_symlinks() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ ! $1 ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local fn="$1" orig="$(readlink -f "$1")" links=''
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ ${fn} =~ .*\.so\..* ]] || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer until [[ ${fn##*.} == so ]]; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fn="${fn%.*}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "${links}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 Hoyerinst_library() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer strstr "$1" "/" || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e $initdir/$_dest ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -L $_src ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # install checksum files also
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _reallib=$(readlink -f "$_src")
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_simple "$_reallib" "$_reallib"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_dir "${_dest%/*}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_simple "$_src" "$_dest"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 [[ ! -e $initdir/$_symlink ]] && {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ddebug "Creating extra symlink: $_symlink"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_symlink $_symlink
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 Hoyerfind_binary() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -z ${1##/*} ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo $1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer type -P $1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Same as above, but specialized to install binary executables.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Install binary executable, and all shared library dependencies, if any.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerinst_binary() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _bin _target
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _bin=$(find_binary "$1") || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _target=${2:-$_bin}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e $initdir/$_target ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _file _line
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # I love bash!
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $_line = 'not a dynamic executable' ]] && break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $_line =~ $_so_regex ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _file=${BASH_REMATCH[1]}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e ${initdir}/$_file ]] && continue
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_library "$_file"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer continue
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 dfatal "$_line"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dfatal "dracut cannot create an initrd."
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_simple "$_bin" "$_target"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 Hoyerinst_script() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _bin
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _bin=$(find_binary "$1") || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer shift
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _line _shebang_regex
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer read -r -n 80 _line <"$_bin"
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 _shebang_regex='(#! *)(/[^ ]+).*'
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $_line =~ $_shebang_regex ]] || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# same as above, but specialized for symlinks
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerinst_symlink() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _src=$1 _target=${2:-$1} _realsrc
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer strstr "$1" "/" || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L $1 ]] || return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -L $initdir/$_target ]] && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _realsrc=$(readlink -f "$_src")
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if ! [[ -e $initdir/$_realsrc ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -d $_realsrc ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_dir "$_realsrc"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst "$_realsrc"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
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}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# attempt to install any programs specified in a udev rule
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerinst_rule_programs() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _prog _bin
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then
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 _bin=/lib/udev/$_prog
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _bin=$(find_binary "$_prog") || {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer continue;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dracut_install "$_bin"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 Hoyerinst_rules() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _target=/etc/udev/rules.d _rule _found
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_dir "/lib/udev/rules.d"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_dir "$_target"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _rule in "$@"; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [ "${rule#/}" = "$rule" ]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for r in /lib/udev/rules.d /etc/udev/rules.d; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -f $r/$_rule ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _found="$r/$_rule"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_simple "$_found"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_rule_programs "$_found"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for r in '' ./ $dracutbasedir/rules.d/; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -f ${r}$_rule ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _found="${r}$_rule"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_simple "$_found" "$_target/${_found##*/}"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst_rule_programs "$_found"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# general purpose installation function
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Same args as above.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerinst() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _x
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case $# in
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer 1) ;;
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 set $1 $3;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *) dfatal "inst only takes 1 or 2 or 3 arguments"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit 1;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer esac
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _x in inst_symlink inst_script inst_binary inst_simple; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer $_x "$@" && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# install any of listed files
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
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#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Example:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# inst_any -d /bin/foo /bin/bar /bin/baz
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# initramfs.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerinst_any() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local to f
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $1 = '-d' ]] && to="$2" && shift 2
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for f in "$@"; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ -e $f ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $to ]] && inst "$f" "$to" && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer inst "$f" && return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 Hoyerdracut_install() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _optional=no
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $1 = '-o' ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _optional=yes
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer shift
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer while (($# > 0)); do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if ! inst "$1" ; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ $_optional = yes ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dinfo "Skipping program $1 as it cannot be found and is" \
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer "flagged to be optional"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer dfatal "Failed to install $1"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit 1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer shift
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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 Hoyerinstall_kmod_with_fw() {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # no need to go further if the module is already installed
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ -e "${initdir}/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" ]] \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer && return 0
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ -e "$initdir/.kernelmodseen/${1##*/}" ]] && return 0
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ $omit_drivers ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _kmod=${1##*/}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _kmod=${_kmod%.ko}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _kmod=${_kmod/-/_}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ "$_kmod" =~ $omit_drivers ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dinfo "Omitting driver $_kmod"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return 1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ "${1##*/lib/modules/$KERNEL_VER/}" =~ $omit_drivers ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dinfo "Omitting driver $_kmod"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return 1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [ -d "$initdir/.kernelmodseen" ] && \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer > "$initdir/.kernelmodseen/${1##*/}"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer inst_simple "$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer || return $?
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _modname=${1##*/} _fwdir _found _fw
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _modname=${_modname%.ko*}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer for _fw in $(modinfo -k $KERNEL_VER -F firmware $1 2>/dev/null); do
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _found=''
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer for _fwdir in $fw_dir; do
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _found=yes
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer done
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 "\"${_modname}.ko\""
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer else
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dwarn "Possible missing firmware \"${_fw}\" for kernel module" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer "\"${_modname}.ko\""
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer done
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return 0
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
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 Hoyerfor_each_kmod_dep() {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _func=$1 _kmod=$2 _cmd _modpath _options _found=0
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer shift 2
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 $_func ${_modpath} || exit $?
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _found=1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer done
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ $_found -eq 0 ]] && exit 1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer exit 0
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer )
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
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 Hoyerfilter_kernel_modules_by_path () (
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _modname _filtercmd
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+=' -o -name "*.ko.xz"'
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _filtercmd+=' 2>/dev/null'
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer else
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename '
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _filtercmd+='-k $KERNEL_VER 2>/dev/null'
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer for _modname in $(eval $_filtercmd); do
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer case $_modname in
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer *.ko) "$2" "$_modname" && echo "$_modname";;
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer *.ko.gz) gzip -dc "$_modname" > $initdir/$$.ko
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer $2 $initdir/$$.ko && echo "$_modname"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer rm -f $initdir/$$.ko
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ;;
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer *.ko.xz) xz -dc "$_modname" > $initdir/$$.ko
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer $2 $initdir/$$.ko && echo "$_modname"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer rm -f $initdir/$$.ko
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ;;
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer esac
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer done
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer)
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyerfind_kernel_modules_by_path () (
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 else
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer cut -d " " -f 1 </proc/modules \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer | xargs modinfo -F filename -k $KERNEL_VER 2>/dev/null
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer)
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyerfilter_kernel_modules () {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer filter_kernel_modules_by_path drivers "$1"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyerfind_kernel_modules () {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer find_kernel_modules_by_path drivers
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
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 Hoyerinstmods() {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ $no_kernel = yes ]] && return
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # called [sub]functions inherit _fderr
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _fderr=9
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _check=no
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ $1 = '-c' ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _check=yes
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer shift
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer function inst1mod() {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _ret=0 _mod="$1"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer case $_mod in
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer =*)
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [ -f $KERNEL_MODS/modules.${_mod#=} ]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ( [[ "$_mpargs" ]] && echo $_mpargs
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer cat "${KERNEL_MODS}/modules.${_mod#=}" ) \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer | instmods
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer else
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ( [[ "$_mpargs" ]] && echo $_mpargs
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer find "$KERNEL_MODS" -path "*/${_mod#=}/*" -printf '%f\n' ) \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer | instmods
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ;;
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer --*) _mpargs+=" $_mod" ;;
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer i2o_scsi) return ;; # Do not load this diagnostic-only module
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer *)
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _mod=${_mod##*/}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # if we are already installed, skip this module and go on
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # to the next one.
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer [[ -f "$initdir/.kernelmodseen/${_mod%.ko}.ko" ]] && return
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [[ $omit_drivers ]] && [[ "$1" =~ $omit_drivers ]]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dinfo "Omitting driver ${_mod##$KERNEL_MODS}"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
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 && return
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
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
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # ok, load the module, all its dependencies, and any firmware
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer # it may require
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer for_each_kmod_dep install_kmod_with_fw $_mod \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer --set-version $KERNEL_VER ${_moddirname} $_mpargs
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ((_ret+=$?))
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ;;
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer esac
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return $_ret
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer }
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer function instmods_1() {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _mod _mpargs
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if (($# == 0)); then # filenames from stdin
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer while read _mod; do
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer inst1mod "${_mod%.ko*}" || {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [ "$_check" = "yes" ]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dfatal "Failed to install $_mod"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return 1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer }
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer done
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer while (($# > 0)); do # filenames as arguments
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer inst1mod ${1%.ko*} || {
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if [ "$_check" = "yes" ]; then
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dfatal "Failed to install $1"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return 1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer }
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer shift
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer done
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return 0
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer }
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer local _ret _filter_not_found='FATAL: Module .* not found.'
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer set -o pipefail
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 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer | while read line; do [[ "$line" =~ $_filter_not_found ]] && echo $line || echo $line >&2 ;done | derror
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _ret=$?
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer set +o pipefail
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer return $_ret
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
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
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerinst_libdir_file() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [[ "$1" == "-n" ]]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer local _pattern=$1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer shift 2
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _dir in $libdirs; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _i in "$@"; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _f in "$_dir"/$_i; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ "$_i" =~ $_pattern ]] || continue
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e "$_i" ]] && dracut_install "$_i"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _dir in $libdirs; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _i in "$@"; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for _f in "$_dir"/$_i; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e "$_f" ]] && dracut_install "$_f"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyercheck_nspawn() {
2c393ed7611a586ef5665aa62453ec57c0f5fef6Evgeny Vereshchagin [[ -d /run/systemd/system ]]
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyer}
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyer
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerdo_test() {
33a5e20ffaa2cbb2853f14265566bac66a7f9026Harald Hoyer if [[ $UID != "0" ]]; then
33a5e20ffaa2cbb2853f14265566bac66a7f9026Harald Hoyer echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2
33a5e20ffaa2cbb2853f14265566bac66a7f9026Harald Hoyer exit 0
33a5e20ffaa2cbb2853f14265566bac66a7f9026Harald Hoyer fi
33a5e20ffaa2cbb2853f14265566bac66a7f9026Harald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# Detect lib paths
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $libdir ]] || for libdir in /lib64 /lib; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -d $libdir ]] && libdirs+=" $libdir" && break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer import_testdir
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier import_initdir
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer while (($# > 0)); do
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case $1 in
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer --run)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "TEST RUN: $TEST_DESCRIPTION"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer test_run
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ret=$?
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [ $ret -eq 0 ]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "TEST RUN: $TEST_DESCRIPTION [OK]"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "TEST RUN: $TEST_DESCRIPTION [FAILED]"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit $ret;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer --setup)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "TEST SETUP: $TEST_DESCRIPTION"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer test_setup
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit $?;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer --clean)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "TEST CLEANUP: $TEST_DESCRIPTION"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer test_cleanup
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer rm -fr "$TESTDIR"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer rm -f .testdir
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit $?;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer --all)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo -n "TEST: $TEST_DESCRIPTION ";
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer (
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer test_setup && test_run
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ret=$?
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer test_cleanup
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer rm -fr "$TESTDIR"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer rm -f .testdir
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit $ret
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ) </dev/null >test.log 2>&1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ret=$?
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if [ $ret -eq 0 ]; then
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer rm test.log
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "[OK]"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "[FAILED]"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer echo "see $(pwd)/test.log"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer fi
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer exit $ret;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *) break ;;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer esac
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer shift
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer done
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}