test-functions revision cb2f9d3f296bc80b55f09880d61dfdf47fc98212
341N/A#!/bin/bash
341N/A# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
341N/A# ex: ts=8 sw=4 sts=4 et filetype=sh
341N/APATH=/sbin:/bin:/usr/sbin:/usr/bin
1345N/Aexport PATH
341N/A
341N/ALOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes)
919N/AKERNEL_VER=${KERNEL_VER-$(uname -r)}
919N/AKERNEL_MODS="/lib/modules/$KERNEL_VER/"
919N/A
919N/Aif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
919N/A echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
919N/A ROOTLIBDIR=/usr/lib/systemd
919N/Afi
919N/A
919N/ABASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee"
919N/ADEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname"
919N/A
919N/Afunction find_qemu_bin() {
919N/A # SUSE and Red Hat call the binary qemu-kvm
919N/A # Debian and Gentoo call it kvm
919N/A [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
919N/A
919N/A [ "$ARCH" ] || ARCH=$(uname -m)
341N/A case $ARCH in
341N/A x86_64)
341N/A # QEMU's own build system calls it qemu-system-x86_64
341N/A [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
341N/A ;;
341N/A i*86)
341N/A # new i386 version of QEMU
341N/A [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
341N/A
341N/A # i386 version of QEMU
341N/A [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
341N/A ;;
341N/A esac
341N/A
341N/A if [ ! -e "$QEMU_BIN" ]; then
341N/A echo "Could not find a suitable QEMU binary" >&2
341N/A return 1
341N/A fi
341N/A}
341N/A
341N/Arun_qemu() {
341N/A if [ -f /etc/machine-id ]; then
341N/A read MACHINE_ID < /etc/machine-id
341N/A [ -z "$INITRD" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/initrd" ] \
341N/A && INITRD="/boot/$MACHINE_ID/$KERNEL_VER/initrd"
341N/A [ -z "$KERNEL_BIN" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/linux" ] \
341N/A && KERNEL_BIN="/boot/$MACHINE_ID/$KERNEL_VER/linux"
341N/A fi
341N/A
341N/A default_fedora_initrd=/boot/initramfs-${KERNEL_VER}.img
341N/A default_debian_initrd=/boot/initrd.img-${KERNEL_VER}
341N/A [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
341N/A [ "$INITRD" ] || { [ -e "$default_fedora_initrd" ] && INITRD=$default_fedora_initrd; }
341N/A [ "$INITRD" ] || { [ "$LOOKS_LIKE_DEBIAN" ] && [ -e "$default_debian_initrd" ] && INITRD=$default_debian_initrd; }
341N/A [ "$QEMU_SMP" ] || QEMU_SMP=1
341N/A
341N/A find_qemu_bin || return 1
341N/A
341N/A KERNEL_APPEND="root=/dev/sda1 \
341N/Asystemd.log_level=debug \
341N/Araid=noautodetect \
341N/Aloglevel=2 \
341N/Ainit=$ROOTLIBDIR/systemd \
341N/Aro \
341N/Aconsole=ttyS0 \
341N/Aselinux=0 \
341N/A$KERNEL_APPEND \
341N/A"
341N/A
341N/A QEMU_OPTIONS="-smp $QEMU_SMP \
341N/A-net none \
341N/A-m 512M \
341N/A-nographic \
341N/A-kernel $KERNEL_BIN \
341N/A"
341N/A
341N/A if [ "$INITRD" ]; then
341N/A QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
341N/A fi
341N/A
341N/A if [ -c /dev/kvm ]; then
341N/A QEMU_OPTIONS="$QEMU_OPTIONS -machine accel=kvm -enable-kvm -cpu host"
341N/A fi
341N/A
341N/A ( set -x
341N/A $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
341N/A}
341N/A
341N/Arun_nspawn() {
341N/A set -x
341N/A ../../systemd-nspawn --register=no --boot --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
341N/A}
341N/A
341N/Asetup_basic_environment() {
341N/A # create the basic filesystem layout
341N/A setup_basic_dirs
341N/A
341N/A install_systemd
341N/A install_missing_libraries
341N/A install_config_files
341N/A create_rc_local
341N/A install_basic_tools
341N/A install_libnss
341N/A install_pam
341N/A install_dbus
341N/A install_fonts
341N/A install_keymaps
341N/A install_terminfo
341N/A install_execs
341N/A install_plymouth
341N/A install_debug_tools
341N/A install_ld_so_conf
341N/A strip_binaries
341N/A install_depmod_files
341N/A generate_module_dependencies
341N/A}
341N/A
341N/Ainstall_valgrind() {
341N/A if ! type -p valgrind; then
341N/A dfatal "Failed to install valgrind"
341N/A exit 1
341N/A fi
341N/A
341N/A local _valgrind_bins=$(strace -e execve valgrind /bin/true 2>&1 >/dev/null | perl -lne 'print $1 if /^execve\("([^"]+)"/')
341N/A dracut_install $_valgrind_bins
341N/A
341N/A local _valgrind_libs=$(LD_DEBUG=files valgrind /bin/true 2>&1 >/dev/null | perl -lne 'print $1 if m{calling init: (/.*vgpreload_.*)}')
341N/A dracut_install $_valgrind_libs
341N/A
341N/A local _valgrind_dbg_and_supp=$(
341N/A strace -e open valgrind /bin/true 2>&1 >/dev/null |
341N/A perl -lne 'if (my ($fname) = /^open\("([^"]+).*= (?!-)\d+/) { print $fname if $fname =~ /debug|\.supp$/ }'
341N/A )
341N/A dracut_install $_valgrind_dbg_and_supp
341N/A}
341N/A
341N/Acreate_valgrind_wrapper() {
341N/A local _valgrind_wrapper=$initdir/$ROOTLIBDIR/systemd-under-valgrind
341N/A ddebug "Create $_valgrind_wrapper"
341N/A cat >$_valgrind_wrapper <<EOF
341N/A#!/bin/bash
341N/A
341N/Aexec valgrind --leak-check=full --log-file=/valgrind.out $ROOTLIBDIR/systemd "\$@"
341N/AEOF
341N/A chmod 0755 $_valgrind_wrapper
341N/A}
341N/A
341N/Ainstall_dmevent() {
341N/A instmods dm_crypt =crypto
341N/A type -P dmeventd >/dev/null && dracut_install dmeventd
341N/A inst_libdir_file "libdevmapper-event.so*"
341N/A inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
341N/A}
341N/A
341N/Ainstall_systemd() {
341N/A # install compiled files
341N/A (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
341N/A # remove unneeded documentation
341N/A rm -fr $initdir/usr/share/{man,doc}
341N/A # we strip binaries since debug symbols increase binaries size a lot
341N/A # and it could fill the available space
341N/A strip_binaries
341N/A}
341N/A
341N/Ainstall_missing_libraries() {
341N/A # install possible missing libraries
341N/A for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
341N/A inst_libs $i
341N/A done
341N/A}
341N/A
341N/Acreate_empty_image() {
341N/A rm -f "$TESTDIR/rootdisk.img"
341N/A # Create the blank file to use as a root filesystem
341N/A dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=400
341N/A LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
341N/A [ -b "$LOOPDEV" ] || return 1
341N/A echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
341N/A sfdisk "$LOOPDEV" <<EOF
341N/A,390M
341N/A,
341N/AEOF
341N/A
341N/A mkfs.ext3 -L systemd "${LOOPDEV}p1"
341N/A}
341N/A
341N/Acheck_result_nspawn() {
341N/A ret=1
341N/A [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
341N/A [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
341N/A cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
341N/A [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
341N/A ls -l $TESTDIR/journal/*/*.journal
341N/A test -s $TESTDIR/failed && ret=$(($ret+1))
341N/A return $ret
341N/A}
341N/A
341N/Astrip_binaries() {
341N/A ddebug "Strip binaries"
341N/A find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
341N/A}
341N/A
341N/Acreate_rc_local() {
341N/A mkdir -p $initdir/etc/rc.d
341N/A cat >$initdir/etc/rc.d/rc.local <<EOF
341N/A#!/bin/bash
341N/Aexit 0
341N/AEOF
341N/A chmod 0755 $initdir/etc/rc.d/rc.local
341N/A}
341N/A
341N/Ainstall_execs() {
341N/A ddebug "install any Execs from the service files"
341N/A (
341N/A export PKG_CONFIG_PATH=$TEST_BASE_DIR/../src/core/
341N/A systemdsystemunitdir=$(pkg-config --variable=systemdsystemunitdir systemd)
341N/A systemduserunitdir=$(pkg-config --variable=systemduserunitdir systemd)
341N/A egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/{$systemdsystemunitdir,$systemduserunitdir}/*.service \
341N/A | while read i; do
341N/A i=${i##Exec*=}; i=${i##-}
341N/A inst $i
341N/A done
341N/A )
341N/A}
341N/A
341N/Agenerate_module_dependencies() {
341N/A if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
341N/A ! depmod -a -b "$initdir" $KERNEL_VER; then
341N/A dfatal "\"depmod -a $KERNEL_VER\" failed."
341N/A exit 1
341N/A fi
341N/A}
341N/A
341N/Ainstall_depmod_files() {
341N/A inst /lib/modules/$KERNEL_VER/modules.order
341N/A inst /lib/modules/$KERNEL_VER/modules.builtin
341N/A}
341N/A
341N/Ainstall_plymouth() {
341N/A # install plymouth, if found... else remove plymouth service files
341N/A # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
341N/A # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
341N/A # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
341N/A # dracut_install plymouth plymouthd
341N/A # else
341N/A rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
341N/A # fi
341N/A}
341N/A
341N/Ainstall_ld_so_conf() {
341N/A cp -a /etc/ld.so.conf* $initdir/etc
341N/A ldconfig -r "$initdir"
341N/A}
341N/A
341N/Ainstall_config_files() {
341N/A inst /etc/sysconfig/init
341N/A inst /etc/passwd
341N/A inst /etc/shadow
341N/A inst /etc/login.defs
341N/A inst /etc/group
341N/A inst /etc/shells
341N/A inst /etc/nsswitch.conf
341N/A inst /etc/pam.conf
341N/A inst /etc/securetty
341N/A inst /etc/os-release
341N/A inst /etc/localtime
341N/A # we want an empty environment
341N/A > $initdir/etc/environment
341N/A > $initdir/etc/machine-id
341N/A # set the hostname
341N/A echo systemd-testsuite > $initdir/etc/hostname
341N/A # fstab
341N/A cat >$initdir/etc/fstab <<EOF
341N/ALABEL=systemd / ext3 rw 0 1
341N/AEOF
341N/A}
341N/A
341N/Ainstall_basic_tools() {
341N/A [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
341N/A dracut_install -o sushell
341N/A # in Debian ldconfig is just a shell script wrapper around ldconfig.real
341N/A dracut_install -o ldconfig.real
341N/A}
341N/A
341N/Ainstall_debug_tools() {
341N/A [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
341N/A}
341N/A
341N/Ainstall_libnss() {
341N/A # install libnss_files for login
341N/A NSS_LIBS=$(LD_DEBUG=files getent passwd 2>&1 >/dev/null |sed -n '/calling init: .*libnss_/ {s!^.* /!/!; p}')
341N/A dracut_install $NSS_LIBS
341N/A}
341N/A
341N/Ainstall_dbus() {
341N/A inst $ROOTLIBDIR/system/dbus.socket
341N/A inst $ROOTLIBDIR/system/dbus.service
341N/A
341N/A find \
341N/A /etc/dbus-1 /usr/share/dbus-1 -xtype f \
341N/A | while read file; do
341N/A inst $file
341N/A done
341N/A}
341N/A
341N/Ainstall_pam() {
341N/A (
341N/A [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null && find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
341N/A find \
341N/A /etc/pam.d \
341N/A /etc/security \
341N/A /lib64/security \
341N/A /lib/security -xtype f \
341N/A ) | while read file; do
341N/A inst $file
341N/A done
341N/A
341N/A [[ "$LOOKS_LIKE_DEBIAN" ]] &&
341N/A cp /etc/pam.d/systemd-user $initdir/etc/pam.d/
341N/A}
341N/A
341N/Ainstall_keymaps() {
341N/A for i in \
341N/A /usr/lib/kbd/keymaps/include/* \
341N/A /usr/lib/kbd/keymaps/i386/include/* \
341N/A /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
341N/A [[ -f $i ]] || continue
341N/A inst $i
341N/A done
341N/A}
341N/A
341N/Ainstall_fonts() {
341N/A for i in \
341N/A /usr/lib/kbd/consolefonts/eurlatgr* \
341N/A /usr/lib/kbd/consolefonts/latarcyrheb-sun16*; do
341N/A [[ -f $i ]] || continue
341N/A inst $i
341N/A done
341N/A}
341N/A
341N/Ainstall_terminfo() {
341N/A for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
341N/A [ -f ${_terminfodir}/l/linux ] && break
341N/A done
341N/A dracut_install -o ${_terminfodir}/l/linux
341N/A}
341N/A
341N/Asetup_testsuite() {
341N/A cp $TEST_BASE_DIR/testsuite.target $initdir/etc/systemd/system/
341N/A cp $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/
341N/A
341N/A mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
341N/A ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
341N/A ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
341N/A
341N/A # make the testsuite the default target
341N/A ln -fs testsuite.target $initdir/etc/systemd/system/default.target
341N/A}
341N/A
341N/Asetup_nspawn_root() {
341N/A rm -fr $TESTDIR/nspawn-root
341N/A ddebug "cp -ar $initdir $TESTDIR/nspawn-root"
341N/A cp -ar $initdir $TESTDIR/nspawn-root
341N/A # we don't mount in the nspawn root
341N/A rm -f $TESTDIR/nspawn-root/etc/fstab
341N/A}
341N/A
341N/Asetup_basic_dirs() {
341N/A mkdir -p $initdir/run
341N/A mkdir -p $initdir/etc/systemd/system
341N/A mkdir -p $initdir/var/log/journal
341N/A
341N/A 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
341N/A if [ -L "/$d" ]; then
341N/A inst_symlink "/$d"
341N/A else
341N/A inst_dir "/$d"
341N/A fi
341N/A done
341N/A
341N/A ln -sfn /run "$initdir/var/run"
341N/A ln -sfn /run/lock "$initdir/var/lock"
341N/A}
341N/A
341N/Ainst_libs() {
341N/A local _bin=$1
341N/A local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
341N/A local _file _line
341N/A
341N/A LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
341N/A [[ $_line = 'not a dynamic executable' ]] && break
341N/A
341N/A if [[ $_line =~ $_so_regex ]]; then
341N/A _file=${BASH_REMATCH[1]}
341N/A [[ -e ${initdir}/$_file ]] && continue
341N/A inst_library "$_file"
341N/A continue
341N/A fi
341N/A
341N/A if [[ $_line =~ not\ found ]]; then
341N/A dfatal "Missing a shared library required by $_bin."
341N/A dfatal "Run \"ldd $_bin\" to find out what it is."
341N/A dfatal "$_line"
341N/A dfatal "dracut cannot create an initrd."
341N/A exit 1
341N/A fi
341N/A done
341N/A}
341N/A
341N/Aimport_testdir() {
341N/A STATEFILE=".testdir"
341N/A [[ -e $STATEFILE ]] && . $STATEFILE
341N/A if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
341N/A TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
341N/A echo "TESTDIR=\"$TESTDIR\"" > $STATEFILE
341N/A export TESTDIR
341N/A fi
341N/A}
341N/A
341N/Aimport_initdir() {
341N/A initdir=$TESTDIR/root
341N/A export initdir
341N/A}
341N/A
341N/A## @brief Converts numeric logging level to the first letter of level name.
341N/A#
341N/A# @param lvl Numeric logging level in range from 1 to 6.
341N/A# @retval 1 if @a lvl is out of range.
341N/A# @retval 0 if @a lvl is correct.
341N/A# @result Echoes first letter of level name.
341N/A_lvl2char() {
341N/A case "$1" in
341N/A 1) echo F;;
341N/A 2) echo E;;
341N/A 3) echo W;;
341N/A 4) echo I;;
341N/A 5) echo D;;
341N/A 6) echo T;;
341N/A *) return 1;;
341N/A esac
341N/A}
341N/A
341N/A## @brief Internal helper function for _do_dlog()
341N/A#
341N/A# @param lvl Numeric logging level.
341N/A# @param msg Message.
341N/A# @retval 0 It's always returned, even if logging failed.
341N/A#
341N/A# @note This function is not supposed to be called manually. Please use
341N/A# dtrace(), ddebug(), or others instead which wrap this one.
341N/A#
341N/A# This function calls _do_dlog() either with parameter msg, or if
341N/A# none is given, it will read standard input and will use every line as
341N/A# a message.
341N/A#
341N/A# This enables:
341N/A# dwarn "This is a warning"
341N/A# echo "This is a warning" | dwarn
341N/ALOG_LEVEL=4
341N/A
341N/Adlog() {
341N/A [ -z "$LOG_LEVEL" ] && return 0
341N/A [ $1 -le $LOG_LEVEL ] || return 0
341N/A local lvl="$1"; shift
341N/A local lvlc=$(_lvl2char "$lvl") || return 0
341N/A
341N/A if [ $# -ge 1 ]; then
341N/A echo "$lvlc: $*"
341N/A else
341N/A while read line; do
341N/A echo "$lvlc: " "$line"
341N/A done
341N/A fi
341N/A}
341N/A
341N/A## @brief Logs message at TRACE level (6)
341N/A#
341N/A# @param msg Message.
341N/A# @retval 0 It's always returned, even if logging failed.
341N/Adtrace() {
341N/A set +x
341N/A dlog 6 "$@"
341N/A [ -n "$debug" ] && set -x || :
341N/A}
341N/A
341N/A## @brief Logs message at DEBUG level (5)
341N/A#
341N/A# @param msg Message.
341N/A# @retval 0 It's always returned, even if logging failed.
341N/Addebug() {
341N/A# set +x
341N/A dlog 5 "$@"
341N/A# [ -n "$debug" ] && set -x || :
341N/A}
341N/A
341N/A## @brief Logs message at INFO level (4)
341N/A#
341N/A# @param msg Message.
341N/A# @retval 0 It's always returned, even if logging failed.
341N/Adinfo() {
341N/A set +x
341N/A dlog 4 "$@"
341N/A [ -n "$debug" ] && set -x || :
341N/A}
341N/A
341N/A## @brief Logs message at WARN level (3)
341N/A#
341N/A# @param msg Message.
341N/A# @retval 0 It's always returned, even if logging failed.
341N/Adwarn() {
341N/A set +x
341N/A dlog 3 "$@"
341N/A [ -n "$debug" ] && set -x || :
341N/A}
341N/A
341N/A## @brief Logs message at ERROR level (2)
341N/A#
341N/A# @param msg Message.
341N/A# @retval 0 It's always returned, even if logging failed.
341N/Aderror() {
341N/A# set +x
341N/A dlog 2 "$@"
341N/A# [ -n "$debug" ] && set -x || :
341N/A}
341N/A
341N/A## @brief Logs message at FATAL level (1)
341N/A#
341N/A# @param msg Message.
341N/A# @retval 0 It's always returned, even if logging failed.
341N/Adfatal() {
341N/A set +x
341N/A dlog 1 "$@"
341N/A [ -n "$debug" ] && set -x || :
341N/A}
341N/A
341N/A
341N/A# Generic substring function. If $2 is in $1, return 0.
341N/Astrstr() { [ "${1#*$2*}" != "$1" ]; }
341N/A
341N/A# normalize_path <path>
341N/A# Prints the normalized path, where it removes any duplicated
341N/A# and trailing slashes.
341N/A# Example:
341N/A# $ normalize_path ///test/test//
341N/A# /test/test
341N/Anormalize_path() {
341N/A shopt -q -s extglob
341N/A set -- "${1//+(\/)//}"
341N/A shopt -q -u extglob
341N/A echo "${1%/}"
341N/A}
341N/A
341N/A# convert_abs_rel <from> <to>
341N/A# Prints the relative path, when creating a symlink to <to> from <from>.
341N/A# Example:
341N/A# $ convert_abs_rel /usr/bin/test /bin/test-2
341N/A# ../../bin/test-2
341N/A# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
341N/Aconvert_abs_rel() {
341N/A local __current __absolute __abssize __cursize __newpath
341N/A local -i __i __level
341N/A
341N/A set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
341N/A
341N/A # corner case #1 - self looping link
341N/A [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
341N/A
341N/A # corner case #2 - own dir link
341N/A [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
341N/A
341N/A IFS="/" __current=($1)
341N/A IFS="/" __absolute=($2)
341N/A
341N/A __abssize=${#__absolute[@]}
341N/A __cursize=${#__current[@]}
341N/A
341N/A while [[ ${__absolute[__level]} == ${__current[__level]} ]]
341N/A do
341N/A (( __level++ ))
341N/A if (( __level > __abssize || __level > __cursize ))
341N/A then
341N/A break
341N/A fi
341N/A done
341N/A
341N/A for ((__i = __level; __i < __cursize-1; __i++))
341N/A do
341N/A if ((__i > __level))
341N/A then
341N/A __newpath=$__newpath"/"
341N/A fi
341N/A __newpath=$__newpath".."
341N/A done
341N/A
341N/A for ((__i = __level; __i < __abssize; __i++))
341N/A do
341N/A if [[ -n $__newpath ]]
341N/A then
341N/A __newpath=$__newpath"/"
341N/A fi
341N/A __newpath=$__newpath${__absolute[__i]}
341N/A done
341N/A
341N/A echo "$__newpath"
341N/A}
341N/A
341N/A
341N/A# Install a directory, keeping symlinks as on the original system.
341N/A# Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
341N/A# will create ${initdir}/lib64, ${initdir}/lib64/file,
341N/A# and a symlink ${initdir}/lib -> lib64.
341N/Ainst_dir() {
341N/A [[ -e ${initdir}/"$1" ]] && return 0 # already there
341N/A
341N/A local _dir="$1" _part="${1%/*}" _file
341N/A while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
341N/A _dir="$_part $_dir"
341N/A _part=${_part%/*}
341N/A done
341N/A
341N/A # iterate over parent directories
341N/A for _file in $_dir; do
341N/A [[ -e "${initdir}/$_file" ]] && continue
341N/A if [[ -L $_file ]]; then
341N/A inst_symlink "$_file"
341N/A else
341N/A # create directory
341N/A mkdir -m 0755 -p "${initdir}/$_file" || return 1
341N/A [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
341N/A chmod u+w "${initdir}/$_file"
341N/A fi
341N/A done
341N/A}
341N/A
341N/A# $1 = file to copy to ramdisk
341N/A# $2 (optional) Name for the file on the ramdisk
341N/A# Location of the image dir is assumed to be $initdir
341N/A# We never overwrite the target if it exists.
341N/Ainst_simple() {
341N/A [[ -f "$1" ]] || return 1
341N/A strstr "$1" "/" || return 1
341N/A
341N/A local _src=$1 target="${2:-$1}"
341N/A if ! [[ -d ${initdir}/$target ]]; then
341N/A [[ -e ${initdir}/$target ]] && return 0
341N/A [[ -L ${initdir}/$target ]] && return 0
341N/A [[ -d "${initdir}/${target%/*}" ]] || inst_dir "${target%/*}"
341N/A fi
341N/A # install checksum files also
341N/A if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
341N/A inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
341N/A fi
341N/A ddebug "Installing $_src"
341N/A cp --sparse=always -pfL "$_src" "${initdir}/$target"
341N/A}
341N/A
341N/A# find symlinks linked to given library file
341N/A# $1 = library file
341N/A# Function searches for symlinks by stripping version numbers appended to
341N/A# library filename, checks if it points to the same target and finally
341N/A# prints the list of symlinks to stdout.
341N/A#
341N/A# Example:
341N/A# rev_lib_symlinks libfoo.so.8.1
341N/A# output: libfoo.so.8 libfoo.so
341N/A# (Only if libfoo.so.8 and libfoo.so exists on host system.)
341N/Arev_lib_symlinks() {
341N/A [[ ! $1 ]] && return 0
341N/A
341N/A local fn="$1" orig="$(readlink -f "$1")" links=''
341N/A
341N/A [[ ${fn} =~ .*\.so\..* ]] || return 1
341N/A
341N/A until [[ ${fn##*.} == so ]]; do
341N/A fn="${fn%.*}"
341N/A [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
341N/A done
341N/A
341N/A echo "${links}"
341N/A}
341N/A
341N/A# Same as above, but specialized to handle dynamic libraries.
341N/A# It handles making symlinks according to how the original library
341N/A# is referenced.
341N/Ainst_library() {
341N/A local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
341N/A strstr "$1" "/" || return 1
341N/A [[ -e $initdir/$_dest ]] && return 0
341N/A if [[ -L $_src ]]; then
341N/A # install checksum files also
341N/A if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
341N/A inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
341N/A fi
341N/A _reallib=$(readlink -f "$_src")
341N/A inst_simple "$_reallib" "$_reallib"
341N/A inst_dir "${_dest%/*}"
341N/A [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
341N/A ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}"
341N/A else
341N/A inst_simple "$_src" "$_dest"
341N/A fi
341N/A
341N/A # Create additional symlinks. See rev_symlinks description.
341N/A for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
341N/A [[ ! -e $initdir/$_symlink ]] && {
341N/A ddebug "Creating extra symlink: $_symlink"
341N/A inst_symlink $_symlink
341N/A }
341N/A done
341N/A}
341N/A
341N/A# find a binary. If we were not passed the full path directly,
341N/A# search in the usual places to find the binary.
341N/Afind_binary() {
341N/A if [[ -z ${1##/*} ]]; then
341N/A if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
341N/A echo $1
341N/A return 0
341N/A fi
341N/A fi
341N/A
341N/A type -P $1
341N/A}
341N/A
341N/A# Same as above, but specialized to install binary executables.
341N/A# Install binary executable, and all shared library dependencies, if any.
341N/Ainst_binary() {
341N/A local _bin _target
341N/A _bin=$(find_binary "$1") || return 1
341N/A _target=${2:-$_bin}
341N/A [[ -e $initdir/$_target ]] && return 0
341N/A [[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
341N/A local _file _line
341N/A local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
341N/A # I love bash!
341N/A LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
341N/A [[ $_line = 'not a dynamic executable' ]] && break
398N/A
341N/A if [[ $_line =~ $_so_regex ]]; then
341N/A _file=${BASH_REMATCH[1]}
341N/A [[ -e ${initdir}/$_file ]] && continue
341N/A inst_library "$_file"
341N/A continue
341N/A fi
341N/A
851N/A if [[ $_line =~ not\ found ]]; then
851N/A dfatal "Missing a shared library required by $_bin."
851N/A dfatal "Run \"ldd $_bin\" to find out what it is."
851N/A dfatal "$_line"
851N/A dfatal "dracut cannot create an initrd."
851N/A exit 1
1265N/A fi
1265N/A done
1265N/A inst_simple "$_bin" "$_target"
1265N/A}
1265N/A
341N/A# same as above, except for shell scripts.
341N/A# If your shell script does not start with shebang, it is not a shell script.
341N/Ainst_script() {
341N/A local _bin
341N/A _bin=$(find_binary "$1") || return 1
341N/A shift
341N/A local _line _shebang_regex
962N/A read -r -n 80 _line <"$_bin"
341N/A # If debug is set, clean unprintable chars to prevent messing up the term
341N/A [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
341N/A _shebang_regex='(#! *)(/[^ ]+).*'
341N/A [[ $_line =~ $_shebang_regex ]] || return 1
341N/A inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
341N/A}
341N/A
341N/A# same as above, but specialized for symlinks
341N/Ainst_symlink() {
851N/A local _src=$1 _target=${2:-$1} _realsrc
341N/A strstr "$1" "/" || return 1
341N/A [[ -L $1 ]] || return 1
341N/A [[ -L $initdir/$_target ]] && return 0
341N/A _realsrc=$(readlink -f "$_src")
341N/A if ! [[ -e $initdir/$_realsrc ]]; then
341N/A if [[ -d $_realsrc ]]; then
341N/A inst_dir "$_realsrc"
341N/A else
341N/A inst "$_realsrc"
341N/A fi
341N/A fi
341N/A [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
851N/A [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/}
341N/A ln -sfn $(convert_abs_rel "${_target}" "${_realsrc}") "$initdir/$_target"
341N/A}
341N/A
341N/A# attempt to install any programs specified in a udev rule
341N/Ainst_rule_programs() {
341N/A local _prog _bin
341N/A
341N/A if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then
341N/A for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
341N/A if [ -x /lib/udev/$_prog ]; then
341N/A _bin=/lib/udev/$_prog
341N/A else
341N/A _bin=$(find_binary "$_prog") || {
341N/A dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
341N/A continue;
341N/A }
341N/A fi
341N/A
341N/A #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
341N/A dracut_install "$_bin"
341N/A done
341N/A fi
341N/A}
341N/A
341N/A# udev rules always get installed in the same place, so
341N/A# create a function to install them to make life simpler.
341N/Ainst_rules() {
341N/A local _target=/etc/udev/rules.d _rule _found
341N/A
341N/A inst_dir "/lib/udev/rules.d"
341N/A inst_dir "$_target"
341N/A for _rule in "$@"; do
341N/A if [ "${rule#/}" = "$rule" ]; then
341N/A for r in /lib/udev/rules.d /etc/udev/rules.d; do
341N/A if [[ -f $r/$_rule ]]; then
341N/A _found="$r/$_rule"
341N/A inst_simple "$_found"
341N/A inst_rule_programs "$_found"
341N/A fi
341N/A done
341N/A fi
341N/A for r in '' ./ $dracutbasedir/rules.d/; do
341N/A if [[ -f ${r}$_rule ]]; then
341N/A _found="${r}$_rule"
341N/A inst_simple "$_found" "$_target/${_found##*/}"
341N/A inst_rule_programs "$_found"
341N/A fi
341N/A done
341N/A [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
341N/A done
341N/A}
341N/A
341N/A# general purpose installation function
341N/A# Same args as above.
341N/Ainst() {
341N/A local _x
341N/A
341N/A case $# in
341N/A 1) ;;
341N/A 2) [[ ! $initdir && -d $2 ]] && export initdir=$2
341N/A [[ $initdir = $2 ]] && set $1;;
341N/A 3) [[ -z $initdir ]] && export initdir=$2
341N/A set $1 $3;;
341N/A *) dfatal "inst only takes 1 or 2 or 3 arguments"
341N/A exit 1;;
341N/A esac
1345N/A for _x in inst_symlink inst_script inst_binary inst_simple; do
341N/A $_x "$@" && return 0
341N/A done
341N/A return 1
341N/A}
341N/A
341N/A# install any of listed files
341N/A#
341N/A# If first argument is '-d' and second some destination path, first accessible
341N/A# source is installed into this path, otherwise it will installed in the same
341N/A# path as source. If none of listed files was installed, function return 1.
341N/A# On first successful installation it returns with 0 status.
341N/A#
341N/A# Example:
341N/A#
341N/A# inst_any -d /bin/foo /bin/bar /bin/baz
341N/A#
341N/A# Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
341N/A# initramfs.
341N/Ainst_any() {
341N/A local to f
341N/A
341N/A [[ $1 = '-d' ]] && to="$2" && shift 2
341N/A
341N/A for f in "$@"; do
341N/A if [[ -e $f ]]; then
341N/A [[ $to ]] && inst "$f" "$to" && return 0
341N/A inst "$f" && return 0
341N/A fi
341N/A done
341N/A
341N/A return 1
341N/A}
341N/A
341N/A# dracut_install [-o ] <file> [<file> ... ]
341N/A# Install <file> to the initramfs image
341N/A# -o optionally install the <file> and don't fail, if it is not there
341N/Adracut_install() {
341N/A local _optional=no
341N/A if [[ $1 = '-o' ]]; then
341N/A _optional=yes
341N/A shift
341N/A fi
341N/A while (($# > 0)); do
341N/A if ! inst "$1" ; then
341N/A if [[ $_optional = yes ]]; then
341N/A dinfo "Skipping program $1 as it cannot be found and is" \
341N/A "flagged to be optional"
341N/A else
341N/A dfatal "Failed to install $1"
341N/A exit 1
341N/A fi
341N/A fi
341N/A shift
341N/A done
341N/A}
341N/A
341N/A# Install a single kernel module along with any firmware it may require.
341N/A# $1 = full path to kernel module to install
341N/Ainstall_kmod_with_fw() {
341N/A # no need to go further if the module is already installed
341N/A
341N/A [[ -e "${initdir}/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" ]] \
341N/A && return 0
341N/A
341N/A [[ -e "$initdir/.kernelmodseen/${1##*/}" ]] && return 0
341N/A
341N/A if [[ $omit_drivers ]]; then
341N/A local _kmod=${1##*/}
341N/A _kmod=${_kmod%.ko}
341N/A _kmod=${_kmod/-/_}
341N/A if [[ "$_kmod" =~ $omit_drivers ]]; then
341N/A dinfo "Omitting driver $_kmod"
341N/A return 1
341N/A fi
341N/A if [[ "${1##*/lib/modules/$KERNEL_VER/}" =~ $omit_drivers ]]; then
341N/A dinfo "Omitting driver $_kmod"
341N/A return 1
341N/A fi
341N/A fi
341N/A
341N/A [ -d "$initdir/.kernelmodseen" ] && \
341N/A > "$initdir/.kernelmodseen/${1##*/}"
341N/A
341N/A inst_simple "$1" "/lib/modules/$KERNEL_VER/${1##*/lib/modules/$KERNEL_VER/}" \
341N/A || return $?
341N/A
341N/A local _modname=${1##*/} _fwdir _found _fw
341N/A _modname=${_modname%.ko*}
341N/A for _fw in $(modinfo -k $KERNEL_VER -F firmware $1 2>/dev/null); do
341N/A _found=''
341N/A for _fwdir in $fw_dir; do
341N/A if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
341N/A inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
341N/A _found=yes
341N/A fi
341N/A done
341N/A if [[ $_found != yes ]]; then
341N/A if ! grep -qe "\<${_modname//-/_}\>" /proc/modules; then
341N/A dinfo "Possible missing firmware \"${_fw}\" for kernel module" \
341N/A "\"${_modname}.ko\""
341N/A else
341N/A dwarn "Possible missing firmware \"${_fw}\" for kernel module" \
341N/A "\"${_modname}.ko\""
341N/A fi
341N/A fi
341N/A done
341N/A return 0
341N/A}
341N/A
341N/A# Do something with all the dependencies of a kernel module.
341N/A# Note that kernel modules depend on themselves using the technique we use
341N/A# $1 = function to call for each dependency we find
341N/A# It will be passed the full path to the found kernel module
341N/A# $2 = module to get dependencies for
341N/A# rest of args = arguments to modprobe
341N/A# _fderr specifies FD passed from surrounding scope
341N/Afor_each_kmod_dep() {
688N/A local _func=$1 _kmod=$2 _cmd _modpath _options _found=0
341N/A shift 2
341N/A modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | (
341N/A while read _cmd _modpath _options; do
341N/A [[ $_cmd = insmod ]] || continue
341N/A $_func ${_modpath} || exit $?
341N/A _found=1
341N/A done
341N/A [[ $_found -eq 0 ]] && exit 1
341N/A exit 0
341N/A )
341N/A}
341N/A
341N/A# filter kernel modules to install certain modules that meet specific
341N/A# requirements.
341N/A# $1 = search only in subdirectory of /kernel/$1
341N/A# $2 = function to call with module name to filter.
341N/A# This function will be passed the full path to the module to test.
341N/A# The behavior of this function can vary depending on whether $hostonly is set.
341N/A# If it is, we will only look at modules that are already in memory.
341N/A# If it is not, we will look at all kernel modules
341N/A# This function returns the full filenames of modules that match $1
341N/Afilter_kernel_modules_by_path () (
341N/A local _modname _filtercmd
341N/A if ! [[ $hostonly ]]; then
341N/A _filtercmd='find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra"'
341N/A _filtercmd+=' "$KERNEL_MODS/weak-updates" -name "*.ko" -o -name "*.ko.gz"'
341N/A _filtercmd+=' -o -name "*.ko.xz"'
341N/A _filtercmd+=' 2>/dev/null'
341N/A else
341N/A _filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename '
341N/A _filtercmd+='-k $KERNEL_VER 2>/dev/null'
341N/A fi
341N/A for _modname in $(eval $_filtercmd); do
341N/A case $_modname in
341N/A *.ko) "$2" "$_modname" && echo "$_modname";;
341N/A *.ko.gz) gzip -dc "$_modname" > $initdir/$$.ko
341N/A $2 $initdir/$$.ko && echo "$_modname"
341N/A rm -f $initdir/$$.ko
341N/A ;;
341N/A *.ko.xz) xz -dc "$_modname" > $initdir/$$.ko
341N/A $2 $initdir/$$.ko && echo "$_modname"
341N/A rm -f $initdir/$$.ko
341N/A ;;
341N/A esac
341N/A done
341N/A)
341N/Afind_kernel_modules_by_path () (
341N/A if ! [[ $hostonly ]]; then
341N/A find "$KERNEL_MODS/kernel/$1" "$KERNEL_MODS/extra" "$KERNEL_MODS/weak-updates" \
341N/A -name "*.ko" -o -name "*.ko.gz" -o -name "*.ko.xz" 2>/dev/null
341N/A else
341N/A cut -d " " -f 1 </proc/modules \
341N/A | xargs modinfo -F filename -k $KERNEL_VER 2>/dev/null
341N/A fi
341N/A)
341N/A
341N/Afilter_kernel_modules () {
341N/A filter_kernel_modules_by_path drivers "$1"
341N/A}
341N/A
341N/Afind_kernel_modules () {
341N/A find_kernel_modules_by_path drivers
341N/A}
341N/A
# instmods [-c] <kernel module> [<kernel module> ... ]
# instmods [-c] <kernel subsystem>
# install kernel modules along with all their dependencies.
# <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
instmods() {
[[ $no_kernel = yes ]] && return
# called [sub]functions inherit _fderr
local _fderr=9
local _check=no
if [[ $1 = '-c' ]]; then
_check=yes
shift
fi
function inst1mod() {
local _ret=0 _mod="$1"
case $_mod in
=*)
if [ -f $KERNEL_MODS/modules.${_mod#=} ]; then
( [[ "$_mpargs" ]] && echo $_mpargs
cat "${KERNEL_MODS}/modules.${_mod#=}" ) \
| instmods
else
( [[ "$_mpargs" ]] && echo $_mpargs
find "$KERNEL_MODS" -path "*/${_mod#=}/*" -printf '%f\n' ) \
| instmods
fi
;;
--*) _mpargs+=" $_mod" ;;
i2o_scsi) return ;; # Do not load this diagnostic-only module
*)
_mod=${_mod##*/}
# if we are already installed, skip this module and go on
# to the next one.
[[ -f "$initdir/.kernelmodseen/${_mod%.ko}.ko" ]] && return
if [[ $omit_drivers ]] && [[ "$1" =~ $omit_drivers ]]; then
dinfo "Omitting driver ${_mod##$KERNEL_MODS}"
return
fi
# If we are building a host-specific initramfs and this
# module is not already loaded, move on to the next one.
[[ $hostonly ]] && ! grep -qe "\<${_mod//-/_}\>" /proc/modules \
&& ! echo $add_drivers | grep -qe "\<${_mod}\>" \
&& return
# We use '-d' option in modprobe only if modules prefix path
# differs from default '/'. This allows us to use Dracut with
# old version of modprobe which doesn't have '-d' option.
local _moddirname=${KERNEL_MODS%%/lib/modules/*}
[[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/"
# ok, load the module, all its dependencies, and any firmware
# it may require
for_each_kmod_dep install_kmod_with_fw $_mod \
--set-version $KERNEL_VER ${_moddirname} $_mpargs
((_ret+=$?))
;;
esac
return $_ret
}
function instmods_1() {
local _mod _mpargs
if (($# == 0)); then # filenames from stdin
while read _mod; do
inst1mod "${_mod%.ko*}" || {
if [ "$_check" = "yes" ]; then
dfatal "Failed to install $_mod"
return 1
fi
}
done
fi
while (($# > 0)); do # filenames as arguments
inst1mod ${1%.ko*} || {
if [ "$_check" = "yes" ]; then
dfatal "Failed to install $1"
return 1
fi
}
shift
done
return 0
}
local _ret _filter_not_found='FATAL: Module .* not found.'
set -o pipefail
# Capture all stderr from modprobe to _fderr. We could use {var}>...
# redirections, but that would make dracut require bash4 at least.
eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
| while read line; do [[ "$line" =~ $_filter_not_found ]] && echo $line || echo $line >&2 ;done | derror
_ret=$?
set +o pipefail
return $_ret
}
# inst_libdir_file [-n <pattern>] <file> [<file>...]
# Install a <file> located on a lib directory to the initramfs image
# -n <pattern> install non-matching files
inst_libdir_file() {
if [[ "$1" == "-n" ]]; then
local _pattern=$1
shift 2
for _dir in $libdirs; do
for _i in "$@"; do
for _f in "$_dir"/$_i; do
[[ "$_i" =~ $_pattern ]] || continue
[[ -e "$_i" ]] && dracut_install "$_i"
done
done
done
else
for _dir in $libdirs; do
for _i in "$@"; do
for _f in "$_dir"/$_i; do
[[ -e "$_f" ]] && dracut_install "$_f"
done
done
done
fi
}
check_nspawn() {
[[ -d /run/systemd/system ]]
}
do_test() {
if [[ $UID != "0" ]]; then
echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2
exit 0
fi
# Detect lib paths
[[ $libdir ]] || for libdir in /lib64 /lib; do
[[ -d $libdir ]] && libdirs+=" $libdir" && break
done
[[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
[[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break
done
import_testdir
import_initdir
while (($# > 0)); do
case $1 in
--run)
echo "TEST RUN: $TEST_DESCRIPTION"
test_run
ret=$?
if [ $ret -eq 0 ]; then
echo "TEST RUN: $TEST_DESCRIPTION [OK]"
else
echo "TEST RUN: $TEST_DESCRIPTION [FAILED]"
fi
exit $ret;;
--setup)
echo "TEST SETUP: $TEST_DESCRIPTION"
test_setup
exit $?;;
--clean)
echo "TEST CLEANUP: $TEST_DESCRIPTION"
test_cleanup
rm -fr "$TESTDIR"
rm -f .testdir
exit $?;;
--all)
echo -n "TEST: $TEST_DESCRIPTION ";
(
test_setup && test_run
ret=$?
test_cleanup
rm -fr "$TESTDIR"
rm -f .testdir
exit $ret
) </dev/null >test.log 2>&1
ret=$?
if [ $ret -eq 0 ]; then
rm test.log
echo "[OK]"
else
echo "[FAILED]"
echo "see $(pwd)/test.log"
fi
exit $ret;;
*) break ;;
esac
shift
done
}