test-functions revision cffae62bcb6912fbaf1b7b282d9d170c9d308897
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringif ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
d4205751d4643c272059a3728045929dd0e5e800Lennart PoetteringBASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe"
d4205751d4643c272059a3728045929dd0e5e800Lennart PoetteringDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering # SUSE and Red Hat call the binary qemu-kvm
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering # QEMU's own build system calls it qemu-system-x86_64
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-x86_64 2>/dev/null | grep '^/' -m1)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu-system-i386 2>/dev/null | grep '^/' -m1)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a qemu 2>/dev/null | grep '^/' -m1)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering echo "Could not find a suitable QEMU binary" >&2
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [ "$KERNEL_BIN" ] || KERNEL_BIN=/boot/vmlinuz-$KERNEL_VER
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [ "$INITRD" ] || INITRD=/boot/initramfs-${KERNEL_VER}.img
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringraid=noautodetect \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poetteringconsole=ttyS0 \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering $QEMU_BIN $QEMU_OPTIONS -append "$KERNEL_APPEND" $TESTDIR/rootdisk.img ) || return 1
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering ../../systemd-nspawn --boot --directory=$TESTDIR/nspawn-root $ROOTLIBDIR/systemd $KERNEL_APPEND
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering ln -fs /proc/self/mounts $initdir/etc/mtab
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering type -P dmeventd >/dev/null && dracut_install dmeventd
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering inst_libdir_file "libdevmapper-event.so*"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek (cd $TEST_BASE_DIR/..; set -x; make DESTDIR=$initdir install)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering rm -fr $initdir/usr/share/{man,doc,gtk-doc}
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering # we strip binaries since debug symbols increase binaries size a lot
e3b9d9c8027a7c4c55cf1614e0fe9423fad69e8fZbigniew Jędrzejewski-Szmek # and it could fill the available space
e3b9d9c8027a7c4c55cf1614e0fe9423fad69e8fZbigniew Jędrzejewski-Szmek # install possible missing libraries
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek # Create the blank file to use as a root filesystem
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek dd if=/dev/null of="$TESTDIR/rootdisk.img" bs=1M seek=300
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek echo "LOOPDEV=$LOOPDEV" >> $STATEFILE
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek sfdisk -C 9600 -H 2 -S 32 -L "$LOOPDEV" <<EOF
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek mkfs.ext3 -L systemd "${LOOPDEV}p1"
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek [[ -f $TESTDIR/nspawn-root/failed ]] && cp -a $TESTDIR/nspawn-root/failed $TESTDIR
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek ls -l $TESTDIR/journal/*/*.journal
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek test -s $TESTDIR/failed && ret=$(($ret+1))
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | xargs strip --strip-unneeded | ddebug
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek cat >$initdir/etc/rc.d/rc.local <<EOF
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek chmod 0755 $initdir/etc/rc.d/rc.local
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek # install any Execs from the service files
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek | while read i; do
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmekgenerate_module_dependencies() {
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek ! depmod -a -b "$initdir" $KERNEL_VER; then
baf167ee0a2953f98e4e7d4c35752ef737832674Zbigniew Jędrzejewski-Szmek dfatal "\"depmod -a $KERNEL_VER\" failed."
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek inst /lib/modules/$KERNEL_VER/modules.order
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering inst /lib/modules/$KERNEL_VER/modules.builtin
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering # install plymouth, if found... else remove plymouth service files
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek cp -a /etc/ld.so.conf* $initdir/etc
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering echo systemd-testsuite > $initdir/etc/hostname
d4205751d4643c272059a3728045929dd0e5e800Lennart PoetteringLABEL=systemd / ext3 rw 0 1
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ $BASICTOOLS ]] && dracut_install $BASICTOOLS
18cd5fe99f70a55a2d6f2303d6ee0624942695b1Zbigniew Jędrzejewski-Szmek [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering NSS_LIBS=$(LD_DEBUG=files getent passwd 2>&1 >/dev/null |sed -n '/calling init: .*libnss_/ {s!^.* /!/!; p}')
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek inst $ROOTLIBDIR/system/dbus.service
97b11eedff9d2e17101ad453caf9e48b73246719David Herrmann | while read file; do
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering | while read file; do
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -f $i ]] || continue
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering /usr/lib/kbd/consolefonts/latarcyrheb-sun16*; do
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -f $i ]] || continue
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [ -f ${_terminfodir}/l/linux ] && break
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering dracut_install -o ${_terminfodir}/l/linux
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering cp $TEST_BASE_DIR/testsuite.target $initdir/etc/systemd/system/
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering sed "s#@SYSTEMCTL@#$(type -P systemctl)#g" $TEST_BASE_DIR/end.service.in > $initdir/etc/systemd/system/end.service
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering ln -fs testsuite.target $initdir/etc/systemd/system/default.target
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering ddebug "cp -ar $initdir $TESTDIR/nspawn-root"
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek mkdir -p $initdir/etc/systemd/system
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek 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
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek ln -sfn /run "$initdir/var/run"
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek ln -sfn /run/lock "$initdir/var/lock"
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek [[ $_line = 'not a dynamic executable' ]] && break
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek if [[ $_line =~ $_so_regex ]]; then
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek [[ -e ${initdir}/$_file ]] && continue
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek if [[ $_line =~ not\ found ]]; then
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek dfatal "Missing a shared library required by $_bin."
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek dfatal "Run \"ldd $_bin\" to find out what it is."
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek dfatal "dracut cannot create an initrd."
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek [[ -e $STATEFILE ]] && . $STATEFILE
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek## @brief Converts numeric logging level to the first letter of level name.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek# @param lvl Numeric logging level in range from 1 to 6.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek# @retval 1 if @a lvl is out of range.
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering# @retval 0 if @a lvl is correct.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek# @result Echoes first letter of level name.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering## @brief Internal helper function for _do_dlog()
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @param lvl Numeric logging level.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek# @param msg Message.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek# @retval 0 It's always returned, even if logging failed.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @note This function is not supposed to be called manually. Please use
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# dtrace(), ddebug(), or others instead which wrap this one.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek# This function calls _do_dlog() either with parameter msg, or if
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# none is given, it will read standard input and will use every line as
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# This enables:
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# dwarn "This is a warning"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# echo "This is a warning" | dwarn
e3b9d9c8027a7c4c55cf1614e0fe9423fad69e8fZbigniew Jędrzejewski-Szmek [ $1 -le $LOG_LEVEL ] || return 0
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering local lvlc=$(_lvl2char "$lvl") || return 0
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if [ $# -ge 1 ]; then
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering## @brief Logs message at TRACE level (6)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @param msg Message.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @retval 0 It's always returned, even if logging failed.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering## @brief Logs message at DEBUG level (5)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @param msg Message.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @retval 0 It's always returned, even if logging failed.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek# [ -n "$debug" ] && set -x || :
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek## @brief Logs message at INFO level (4)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @param msg Message.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @retval 0 It's always returned, even if logging failed.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek## @brief Logs message at WARN level (3)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @param msg Message.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @retval 0 It's always returned, even if logging failed.
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek## @brief Logs message at ERROR level (2)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @param msg Message.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @retval 0 It's always returned, even if logging failed.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# [ -n "$debug" ] && set -x || :
03e334a1c7dc8c20c38902aa039440763acc9b17Lennart Poettering## @brief Logs message at FATAL level (1)
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @param msg Message.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# @retval 0 It's always returned, even if logging failed.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# Generic substring function. If $2 is in $1, return 0.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# normalize_path <path>
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poettering# Prints the normalized path, where it removes any duplicated
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poettering# and trailing slashes.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# $ normalize_path ///test/test//
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# convert_abs_rel <from> <to>
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# Prints the relative path, when creating a symlink to <to> from <from>.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# $ convert_abs_rel /usr/bin/test /bin/test-2
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering local __current __absolute __abssize __cursize __newpath
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering while [[ ${__absolute[__level]} == ${__current[__level]} ]]
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (( __level > __abssize || __level > __cursize ))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for ((__i = __level; __i < __cursize-1; __i++))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for ((__i = __level; __i < __abssize; __i++))
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# Install a directory, keeping symlinks as on the original system.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# will create ${initdir}/lib64, ${initdir}/lib64/file,
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# and a symlink ${initdir}/lib -> lib64.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -e ${initdir}/"$1" ]] && return 0 # already there
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if [[ -L $_file ]]; then
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering mkdir -m 0755 -p "${initdir}/$_file" || return 1
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# $1 = file to copy to ramdisk
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# $2 (optional) Name for the file on the ramdisk
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# Location of the image dir is assumed to be $initdir
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# We never overwrite the target if it exists.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if ! [[ -d ${initdir}/$target ]]; then
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -e ${initdir}/$target ]] && return 0
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -L ${initdir}/$target ]] && return 0
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -d "${initdir}/${target%/*}" ]] || inst_dir "${target%/*}"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek cp --sparse=always -pfL "$_src" "${initdir}/$target"
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# find symlinks linked to given library file
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# $1 = library file
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# Function searches for symlinks by stripping version numbers appended to
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# library filename, checks if it points to the same target and finally
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# prints the list of symlinks to stdout.
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# rev_lib_symlinks libfoo.so.8.1
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# (Only if libfoo.so.8 and libfoo.so exists on host system.)
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek [[ ! $1 ]] && return 0
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek local fn="$1" orig="$(readlink -f "$1")" links=''
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ ${fn} =~ .*\.so\..* ]] || return 1
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# Same as above, but specialized to handle dynamic libraries.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# It handles making symlinks according to how the original library
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering# is referenced.
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poettering local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poettering [[ -e $initdir/$_dest ]] && return 0
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if [[ -L $_src ]]; then
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}/${_dest}"
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering # Create additional symlinks. See rev_symlinks description.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek ddebug "Creating extra symlink: $_symlink"
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# find a binary. If we were not passed the full path directly,
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# search in the usual places to find the binary.
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek# Same as above, but specialized to install binary executables.
e53fc357a9bb9d0a5362ccc4246d598cb0febd5eLennart Poettering# Install binary executable, and all shared library dependencies, if any.
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek _bin=$(find_binary "$1") || return 1
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek [[ -e $initdir/$_target ]] && return 0
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek [[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek [[ $_line = 'not a dynamic executable' ]] && break
if [[ $_line =~ $_so_regex ]]; then
_file=${BASH_REMATCH[1]}
local _bin
local _line _shebang_regex
[[ $_line =~ $_shebang_regex ]] || return 1
if [[ -d $_realsrc ]]; then
if [[ -f $r/$_rule ]]; then
if [[ -f ${r}$_rule ]]; then
local _x
case $# in
[[ $initdir = $2 ]] && set $1;;
for _x in inst_symlink inst_script inst_binary inst_simple; do
local to f
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;;