test-functions revision c53158818d8cdaf46b3f1b5299b9bda118a1043f
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
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald HoyerKERNEL_VER=${KERNEL_VER-$(uname -r)}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald HoyerKERNEL_MODS="/lib/modules/$KERNEL_VER/"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyersetup_basic_dirs() {
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
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_qemu() {
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyer command -v qemu-kvm &>/dev/null && [[ -c /dev/kvm ]]
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyer}
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyer
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyercheck_nspawn() {
1ecf6a2b4960229ad1d06c591b4776ddf065e834Harald Hoyer [[ -d /sys/fs/cgroup/systemd ]]
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
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}