test-functions revision 898720b7e9cf3bdf7a93e435cbed5dd6942ecf9b
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
export PATH
[[ -e "${initdir}${prefix}/$d" ]] && continue
if [ -L "/$d" ]; then
inst_symlink "/$d" "${prefix}/$d"
else
mkdir -m 0755 -p "${initdir}${prefix}/$d"
fi
done
if [ -L "/$d" ]; then
inst_symlink "/$d"
else
fi
done
}
local _bin=$1
local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
if [[ $_line =~ $_so_regex ]]; then
_file=${BASH_REMATCH[1]}
continue
fi
dfatal "dracut cannot create an initrd."
exit 1
fi
done
}
STATEFILE=".testdir"
[[ -e $STATEFILE ]] && . $STATEFILE
export TESTDIR
fi
}
## @brief Converts numeric logging level to the first letter of level name.
#
# @param lvl Numeric logging level in range from 1 to 6.
# @retval 1 if @a lvl is out of range.
# @retval 0 if @a lvl is correct.
# @result Echoes first letter of level name.
1) echo F;;
2) echo E;;
3) echo W;;
4) echo I;;
5) echo D;;
6) echo T;;
*) return 1;;
esac
}
## @brief Internal helper function for _do_dlog()
#
# @param lvl Numeric logging level.
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
#
# @note This function is not supposed to be called manually. Please use
# dtrace(), ddebug(), or others instead which wrap this one.
#
# This function calls _do_dlog() either with parameter msg, or if
# none is given, it will read standard input and will use every line as
# a message.
#
# This enables:
# dwarn "This is a warning"
# echo "This is a warning" | dwarn
[ $1 -le $LOG_LEVEL ] || return 0
if [ $# -ge 1 ]; then
echo "$lvlc: $*"
else
while read line; do
done
fi
}
## @brief Logs message at TRACE level (6)
#
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
set +x
dlog 6 "$@"
}
## @brief Logs message at DEBUG level (5)
#
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
set +x
dlog 5 "$@"
}
## @brief Logs message at INFO level (4)
#
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
set +x
dlog 4 "$@"
}
## @brief Logs message at WARN level (3)
#
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
set +x
dlog 3 "$@"
}
## @brief Logs message at ERROR level (2)
#
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
set +x
dlog 2 "$@"
}
## @brief Logs message at FATAL level (1)
#
# @param msg Message.
# @retval 0 It's always returned, even if logging failed.
set +x
dlog 1 "$@"
}
# Generic substring function. If $2 is in $1, return 0.
# normalize_path <path>
# Prints the normalized path, where it removes any duplicated
# and trailing slashes.
# Example:
set -- "${1//+(\/)//}"
echo "${1%/}"
}
# convert_abs_rel <from> <to>
# Prints the relative path, when creating a symlink to <to> from <from>.
# Example:
# corner case #1 - self looping link
[[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
# corner case #2 - own dir link
[[ "${1%/*}" == "$2" ]] && { echo "."; return; }
__abssize=${#__absolute[@]}
__cursize=${#__current[@]}
while [[ ${__absolute[__level]} == ${__current[__level]} ]]
do
then
break
fi
done
do
then
fi
__newpath=$__newpath".."
done
do
if [[ -n $__newpath ]]
then
fi
done
echo "$__newpath"
}
# Install a directory, keeping symlinks as on the original system.
# and a symlink ${initdir}/lib -> lib64.
done
# iterate over parent directories
if [[ -L $_file ]]; then
else
# create directory
fi
done
}
# $1 = file to copy to ramdisk
# $2 (optional) Name for the file on the ramdisk
# Location of the image dir is assumed to be $initdir
# We never overwrite the target if it exists.
[[ -f "$1" ]] || return 1
fi
# install checksum files also
if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
fi
}
# find symlinks linked to given library file
# $1 = library file
# Function searches for symlinks by stripping version numbers appended to
# library filename, checks if it points to the same target and finally
# prints the list of symlinks to stdout.
#
# Example:
# rev_lib_symlinks libfoo.so.8.1
[[ ! $1 ]] && return 0
until [[ ${fn##*.} == so ]]; do
fn="${fn%.*}"
done
echo "${links}"
}
# Same as above, but specialized to handle dynamic libraries.
# It handles making symlinks according to how the original library
# is referenced.
if [[ -L $_src ]]; then
# install checksum files also
if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
fi
inst_dir "${_dest%/*}"
else
inst_simple "$_src" "$_dest"
fi
# Create additional symlinks. See rev_symlinks description.
}
done
}
# find a binary. If we were not passed the full path directly,
# search in the usual places to find the binary.
if [[ -z ${1##/*} ]]; then
echo $1
return 0
fi
fi
type -P $1
}
# Same as above, but specialized to install binary executables.
# Install binary executable, and all shared library dependencies, if any.
[[ -L $_bin ]] && inst_symlink $_bin $_target && return 0
local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
# I love bash!
if [[ $_line =~ $_so_regex ]]; then
_file=${BASH_REMATCH[1]}
continue
fi
dfatal "dracut cannot create an initrd."
exit 1
fi
done
inst_simple "$_bin" "$_target"
}
# same as above, except for shell scripts.
# If your shell script does not start with shebang, it is not a shell script.
local _bin
shift
local _line _shebang_regex
# If debug is set, clean unprintable chars to prevent messing up the term
_shebang_regex='(#! *)(/[^ ]+).*'
[[ $_line =~ $_shebang_regex ]] || return 1
}
# same as above, but specialized for symlinks
[[ -L $1 ]] || return 1
if [[ -d $_realsrc ]]; then
else
fi
fi
}
# attempt to install any programs specified in a udev rule
else
continue;
}
fi
#dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
done
fi
}
# udev rules always get installed in the same place, so
# create a function to install them to make life simpler.
if [[ -f $r/$_rule ]]; then
fi
done
fi
if [[ -f ${r}$_rule ]]; then
inst_simple "$_found" "$_target/${_found##*/}"
fi
done
done
}
# general purpose installation function
# Same args as above.
local _x
case $# in
1) ;;
[[ $initdir = $2 ]] && set $1;;
set $1 $3;;
*) dfatal "inst only takes 1 or 2 or 3 arguments"
exit 1;;
esac
for _x in inst_symlink inst_script inst_binary inst_simple; do
done
return 1
}
# install any of listed files
#
# If first argument is '-d' and second some destination path, first accessible
# source is installed into this path, otherwise it will installed in the same
# path as source. If none of listed files was installed, function return 1.
# On first successful installation it returns with 0 status.
#
# Example:
#
#
# initramfs.
local to f
if [[ -e $f ]]; then
fi
done
return 1
}
# dracut_install [-o ] <file> [<file> ... ]
# Install <file> to the initramfs image
# -o optionally install the <file> and don't fail, if it is not there
if [[ $1 = '-o' ]]; then
shift
fi
while (($# > 0)); do
if [[ $_optional = yes ]]; then
"flagged to be optional"
else
dfatal "Failed to install $1"
exit 1
fi
fi
shift
done
}
# inst_libdir_file [-n <pattern>] <file> [<file>...]
# Install a <file> located on a lib directory to the initramfs image
# -n <pattern> install non-matching files
if [[ "$1" == "-n" ]]; then
local _pattern=$1
shift 2
done
done
done
else
done
done
done
fi
}
# Detect lib paths
done
done
while (($# > 0)); do
case $1 in
--run)
echo "TEST RUN: $TEST_DESCRIPTION"
ret=$?
echo "TEST RUN: $TEST_DESCRIPTION [OK]"
else
echo "TEST RUN: $TEST_DESCRIPTION [FAILED]"
fi
exit $ret;;
--setup)
echo "TEST SETUP: $TEST_DESCRIPTION"
exit $?;;
--clean)
echo "TEST CLEANUP: $TEST_DESCRIPTION"
exit $?;;
--all)
(
ret=$?
exit $ret
ret=$?
echo "[OK]"
else
echo "[FAILED]"
fi
exit $ret;;
*) break ;;
esac
shift
done
}