test-functions revision e63b61be5350dbe92ea12e1eeb96dde251ed9292
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# ex: ts=8 sw=4 sts=4 et filetype=sh
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
32a4456cc252689f51f383d150d34ed636bfec4dMichal SchmidtBASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe"
32a4456cc252689f51f383d150d34ed636bfec4dMichal SchmidtDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt # QEMU's own build system calls it qemu-system-x86_64
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt echo "Could not find a suitable QEMU binary" >&2
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [ -f /etc/machine-id ]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ -z "$INITRD" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/initrd" ] \
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt && INITRD="/boot/$MACHINE_ID/$KERNEL_VER/initrd"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ -z "$KERNEL_BIN" ] && [ -e "/boot/$MACHINE_ID/$KERNEL_VER/linux" ] \
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt && KERNEL_BIN="/boot/$MACHINE_ID/$KERNEL_VER/linux"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ "$INITRD" ] || INITRD=/boot/initramfs-${KERNEL_VER}.img
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtraid=noautodetect \
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtconsole=ttyS0 \
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt ../../systemd-nspawn --boot --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt type -P dmeventd >/dev/null && dracut_install dmeventd
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt # we strip binaries since debug symbols increase binaries size a lot
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt # Create the blank file to use as a root filesystem
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=300
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt | while read i; do
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt inst /lib/modules/$KERNEL_VER/modules.builtin
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt # install plymouth, if found... else remove plymouth service files
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt echo systemd-testsuite > $initdir/etc/hostname
32a4456cc252689f51f383d150d34ed636bfec4dMichal SchmidtLABEL=systemd / ext3 rw 0 1
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt # in Debian ldconfig is just a shell script wrapper around ldconfig.real
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt NSS_LIBS=$(LD_DEBUG=files getent passwd 2>&1 >/dev/null |sed -n '/calling init: .*libnss_/ {s!^.* /!/!; p}')
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt | while read file; do
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt | while read file; do
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ -f $i ]] || continue
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt /usr/lib/kbd/consolefonts/latarcyrheb-sun16*; do
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ -f $i ]] || continue
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [ -f ${_terminfodir}/l/linux ] && break
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt cp $TEST_BASE_DIR/testsuite.target $initdir/etc/systemd/system/
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt sed "s#@SYSTEMCTL@#$(type -P systemctl)#g" $TEST_BASE_DIR/end.service.in > $initdir/etc/systemd/system/end.service
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt ln -fs testsuite.target $initdir/etc/systemd/system/default.target
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt ddebug "cp -ar $initdir $TESTDIR/nspawn-root"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt 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
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ $_line = 'not a dynamic executable' ]] && break
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ $_line =~ $_so_regex ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -e ${initdir}/$_file ]] && continue
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ $_line =~ not\ found ]]; then
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt dfatal "Missing a shared library required by $_bin."
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt dfatal "Run \"ldd $_bin\" to find out what it is."
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt## @brief Converts numeric logging level to the first letter of level name.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @param lvl Numeric logging level in range from 1 to 6.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @retval 1 if @a lvl is out of range.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @retval 0 if @a lvl is correct.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @result Echoes first letter of level name.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt *) return 1;;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt## @brief Internal helper function for _do_dlog()
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @param lvl Numeric logging level.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @param msg Message.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @retval 0 It's always returned, even if logging failed.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @note This function is not supposed to be called manually. Please use
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# dtrace(), ddebug(), or others instead which wrap this one.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# This function calls _do_dlog() either with parameter msg, or if
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# none is given, it will read standard input and will use every line as
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# This enables:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# dwarn "This is a warning"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# echo "This is a warning" | dwarn
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [ $1 -le $LOG_LEVEL ] || return 0
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [ $# -ge 1 ]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while read line; do
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt## @brief Logs message at TRACE level (6)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# @param msg Message.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# @retval 0 It's always returned, even if logging failed.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt## @brief Logs message at DEBUG level (5)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# @param msg Message.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# @retval 0 It's always returned, even if logging failed.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# [ -n "$debug" ] && set -x || :
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt## @brief Logs message at INFO level (4)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# @param msg Message.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# @retval 0 It's always returned, even if logging failed.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt## @brief Logs message at WARN level (3)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# @param msg Message.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# @retval 0 It's always returned, even if logging failed.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt## @brief Logs message at ERROR level (2)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @param msg Message.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @retval 0 It's always returned, even if logging failed.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# [ -n "$debug" ] && set -x || :
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt## @brief Logs message at FATAL level (1)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @param msg Message.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# @retval 0 It's always returned, even if logging failed.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# Generic substring function. If $2 is in $1, return 0.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# normalize_path <path>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# Prints the normalized path, where it removes any duplicated
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# and trailing slashes.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# $ normalize_path ///test/test//
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# convert_abs_rel <from> <to>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# Prints the relative path, when creating a symlink to <to> from <from>.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# $ convert_abs_rel /usr/bin/test /bin/test-2
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt local __current __absolute __abssize __cursize __newpath
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while [[ ${__absolute[__level]} == ${__current[__level]} ]]
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (( __level > __abssize || __level > __cursize ))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt for ((__i = __level; __i < __cursize-1; __i++))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt for ((__i = __level; __i < __abssize; __i++))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# Install a directory, keeping symlinks as on the original system.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# will create ${initdir}/lib64, ${initdir}/lib64/file,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# and a symlink ${initdir}/lib -> lib64.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -e ${initdir}/"$1" ]] && return 0 # already there
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ -L $_file ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt mkdir -m 0755 -p "${initdir}/$_file" || return 1
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# $1 = file to copy to ramdisk
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# $2 (optional) Name for the file on the ramdisk
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# Location of the image dir is assumed to be $initdir
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# We never overwrite the target if it exists.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if ! [[ -d ${initdir}/$target ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -e ${initdir}/$target ]] && return 0
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -L ${initdir}/$target ]] && return 0
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -d "${initdir}/${target%/*}" ]] || inst_dir "${target%/*}"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt cp --sparse=always -pfL "$_src" "${initdir}/$target"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# find symlinks linked to given library file
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# $1 = library file
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# Function searches for symlinks by stripping version numbers appended to
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# library filename, checks if it points to the same target and finally
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# prints the list of symlinks to stdout.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# rev_lib_symlinks libfoo.so.8.1
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# (Only if libfoo.so.8 and libfoo.so exists on host system.)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ ! $1 ]] && return 0
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt local fn="$1" orig="$(readlink -f "$1")" links=''
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ ${fn} =~ .*\.so\..* ]] || return 1
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# Same as above, but specialized to handle dynamic libraries.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# It handles making symlinks according to how the original library
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# is referenced.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ -e $initdir/$_dest ]] && return 0
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if [[ -L $_src ]]; then
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt # Create additional symlinks. See rev_symlinks description.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# find a binary. If we were not passed the full path directly,
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# search in the usual places to find the binary.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# Same as above, but specialized to install binary executables.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# Install binary executable, and all shared library dependencies, if any.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -e $initdir/$_target ]] && return 0
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ $_line = 'not a dynamic executable' ]] && break
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if [[ $_line =~ $_so_regex ]]; then
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ -e ${initdir}/$_file ]] && continue
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if [[ $_line =~ not\ found ]]; then
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt dfatal "Missing a shared library required by $_bin."
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt dfatal "Run \"ldd $_bin\" to find out what it is."
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# same as above, except for shell scripts.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# If your shell script does not start with shebang, it is not a shell script.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt # If debug is set, clean unprintable chars to prevent messing up the term
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt [[ $_line =~ $_shebang_regex ]] || return 1
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# same as above, but specialized for symlinks
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt local _src=$1 _target=${2:-$1} _realsrc
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -L $1 ]] || return 1
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -L $initdir/$_target ]] && return 0
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if ! [[ -e $initdir/$_realsrc ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ -d $_realsrc ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt ln -sfn $(convert_abs_rel "${_target}" "${_realsrc}") "$initdir/$_target"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# attempt to install any programs specified in a udev rule
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [ -x /lib/udev/$_prog ]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# udev rules always get installed in the same place, so
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# create a function to install them to make life simpler.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt for r in /lib/udev/rules.d /etc/udev/rules.d; do
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ -f $r/$_rule ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ -f ${r}$_rule ]]; then
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt inst_simple "$_found" "$_target/${_found##*/}"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt# general purpose installation function
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt# Same args as above.
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt 2) [[ ! $initdir && -d $2 ]] && export initdir=$2
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt [[ $initdir = $2 ]] && set $1;;
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt 3) [[ -z $initdir ]] && export initdir=$2
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt *) dfatal "inst only takes 1 or 2 or 3 arguments"
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt for _x in inst_symlink inst_script inst_binary inst_simple; do
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# install any of listed files
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# If first argument is '-d' and second some destination path, first accessible
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# source is installed into this path, otherwise it will installed in the same
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# path as source. If none of listed files was installed, function return 1.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# On first successful installation it returns with 0 status.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt# inst_any -d /bin/foo /bin/bar /bin/baz
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt# Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if [[ -e $f ]]; then
if [[ $_optional = yes ]]; then
if [[ $omit_drivers ]]; then
_found=1
local _modname _filtercmd
if ! [[ $hostonly ]]; then
if ! [[ $hostonly ]]; then
[[ $no_kernel = yes ]] && return
local _fderr=9
| instmods
| instmods
local _moddirname=${KERNEL_MODS%%/lib/modules/*}
--set-version $KERNEL_VER ${_moddirname} $_mpargs
return $_ret
while read _mod; do
set -o pipefail
| while read line; do [[ "$line" =~ $_filter_not_found ]] && echo $line || echo $line >&2 ;done | derror
_ret=$?
set +o pipefail
return $_ret
local _pattern=$1
case $1 in
--run)
ret=$?
exit $ret;;
--setup)
--clean)
--all)
ret=$?
exit $ret
ret=$?
exit $ret;;