test-functions revision 1ecf6a2b4960229ad1d06c591b4776ddf065e834
2362N/A# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- 0N/A# ex: ts=8 sw=4 sts=4 et filetype=sh 2362N/A [[ -e "${initdir}${prefix}/$d" ]] && continue 0N/A if [ -L "/$d" ]; then 0N/A mkdir -m 0755 -p "${initdir}${prefix}/$d" 0N/A if [ -L "/$d" ]; then 0N/A [[ $_line = 'not a dynamic executable' ]] && break 0N/A## @brief Converts numeric logging level to the first letter of level name. 0N/A# @param lvl Numeric logging level in range from 1 to 6. 0N/A# @retval 1 if @a lvl is out of range. 0N/A# @retval 0 if @a lvl is correct. 0N/A# @result Echoes first letter of level name. 0N/A## @brief Internal helper function for _do_dlog() 0N/A# @param lvl Numeric logging level. 0N/A# @param msg Message. 0N/A# @retval 0 It's always returned, even if logging failed. 0N/A# @note This function is not supposed to be called manually. Please use 0N/A# dtrace(), ddebug(), or others instead which wrap this one. 0N/A# This function calls _do_dlog() either with parameter msg, or if 0N/A# none is given, it will read standard input and will use every line as 0N/A# dwarn "This is a warning" 0N/A# echo "This is a warning" | dwarn 0N/A## @brief Logs message at TRACE level (6) 0N/A# @param msg Message. 0N/A# @retval 0 It's always returned, even if logging failed. 0N/A## @brief Logs message at DEBUG level (5) 0N/A# @param msg Message. 0N/A# @retval 0 It's always returned, even if logging failed. 0N/A## @brief Logs message at INFO level (4) 0N/A# @param msg Message. 0N/A# @retval 0 It's always returned, even if logging failed. 0N/A## @brief Logs message at WARN level (3) 0N/A# @param msg Message. 0N/A# @retval 0 It's always returned, even if logging failed. 0N/A## @brief Logs message at ERROR level (2) 0N/A# @param msg Message. 0N/A# @retval 0 It's always returned, even if logging failed. [ -n "$debug" ] && set -x || : ## @brief Logs message at FATAL level (1) # @retval 0 It's always returned, even if logging failed. [ -n "$debug" ] && set -x || : # Generic substring function. If $2 is in $1, return 0. strstr() { [ "${1#*$2*}" != "$1" ]; } # Prints the normalized path, where it removes any duplicated # convert_abs_rel <from> <to> # Prints the relative path, when creating a symlink to <to> from <from>. # corner case #1 - self looping link [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; } # corner case #2 - own dir link [[ "${1%/*}" == "$2" ]] && { echo "."; return; } # Install a directory, keeping symlinks as on the original system. # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file" # will create ${initdir}/lib64, ${initdir}/lib64/file, # and a symlink ${initdir}/lib -> lib64. [[ -e ${initdir}/"$1" ]] && return 0 # already there while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do # iterate over parent directories [[ -e "${initdir}/$_file" ]] && continue # $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 [[ -d "${initdir}/${target%/*}" ]] || inst_dir "${target%/*}" # install checksum files also if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac" # find symlinks linked to given 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. [[ ${fn} =~ .*\.so\..* ]] || return 1 until [[ ${fn##*.} == so ]]; do # Same as above, but specialized to handle dynamic libraries. # It handles making symlinks according to how the original library # install checksum files also if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac" # Create additional symlinks. See rev_symlinks description. # 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 # Same as above, but specialized to install binary executables. # Install binary executable, and all shared library dependencies, if any. local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)' [[ $_line = 'not a dynamic executable' ]] && break dfatal "dracut cannot create an initrd." # same as above, except for shell scripts. # If your shell script does not start with shebang, it is not a shell script. # If debug is set, clean unprintable chars to prevent messing up the term # same as above, but specialized for symlinks # attempt to install any programs specified in a udev rule if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)" # udev rules always get installed in the same place, so # create a function to install them to make life simpler. if [ "${rule#/}" = "$rule" ]; then # general purpose installation function *) dfatal "inst only takes 1 or 2 or 3 arguments" # 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. # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in [[ $1 = '-d' ]] && to="$2" && shift 2 # 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 dinfo "Skipping program $1 as it cannot be found and is" \ # 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 if [[ $UID != "0" ]]; then