images+=($@)
dinfo "Using base image $baseimage"
-cat "$baseimage" > "$outfile"
+cat -- "$baseimage" > "$outfile"
for i in "${images[@]}"; do
dinfo "Appending $i"
- cat "$i" >> "$outfile"
+ cat -- "$i" >> "$outfile"
done
dinfo "Created $outfile"
# search in the usual places to find the binary.
find_binary() {
if [[ -z ${1##/*} ]]; then
- if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
- echo $1
+ if [[ -x $1 ]] || { [[ "$1" == *.so* ]] && ldd "$1" &>/dev/null; }; then
+ printf "%s\n" "$1"
return 0
fi
fi
- type -P ${1##*/}
+ type -P "${1##*/}"
}
if ! [[ $dracutbasedir ]]; then
# Detect lib paths
if ! [[ $libdirs ]] ; then
- if strstr "$(ldd /bin/sh)" "/lib64/" &>/dev/null \
+ if [[ "$(ldd /bin/sh)" == */lib64/* ]] &>/dev/null \
&& [[ -d /lib64 ]]; then
libdirs+=" /lib64"
[[ -d /usr/lib64 ]] && libdirs+=" /usr/lib64"
srcmods="/lib/modules/$kernel/"
[[ $drivers_dir ]] && {
- if vercmp $(modprobe --version | cut -d' ' -f3) lt 3.7; then
+ if vercmp "$(modprobe --version | cut -d' ' -f3)" lt 3.7; then
dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
exit 1
fi
}
dracut_module_included() {
- strstr "$mods_to_load $modules_loaded" "$@"
+ [[ "$mods_to_load $modules_loaded" == *$@* ]]
}
# Create all subdirectories for given path without creating the last element.
# $1 = path
-mksubdirs() { [[ -e ${1%/*} ]] || mkdir -m 0755 -p ${1%/*}; }
+mksubdirs() {
+ [[ -e ${1%/*} ]] || mkdir -m 0755 -p -- "${1%/*}"
+}
# Version comparision function. Assumes Linux style version scheme.
# $1 = version a
# $2 = comparision op (gt, ge, eq, le, lt, ne)
# $3 = version b
vercmp() {
- local _n1=(${1//./ }) _op=$2 _n2=(${3//./ }) _i _res
+ local _n1=${1//./ } _op=$2 _n2=${3//./ } _i _res
for ((_i=0; ; _i++))
do
# is_func <command>
# Check whether $1 is a function.
is_func() {
- [[ $(type -t $1) = "function" ]]
+ [[ "$(type -t "$1")" = "function" ]]
}
# Function prints global variables in format name=value line by line.
print_vars() {
local _var _value
- for _var in $@
+ for _var in "$@"
do
- _value=$(eval echo \$$_var)
- [[ ${_value} ]] && echo "${_var}=\"${_value}\""
+ eval printf -v _value "%s" "\$$_var"
+ [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
done
}
__abssize=${#__absolute[@]}
__cursize=${#__current[@]}
- while [[ ${__absolute[__level]} == ${__current[__level]} ]]
+ while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
do
(( __level++ ))
if (( __level > __abssize || __level > __cursize ))
echo "$__newpath"
}
-if strstr "$(ln --help)" "--relative"; then
+if [[ "$(ln --help)" == *--relative* ]]; then
ln_r() {
ln -sfnr "${initdir}/$1" "${initdir}/$2"
}
local _source=$1
local _dest=$2
[[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
- ln -sfn $(convert_abs_rel "${_dest}" "${_source}") "${initdir}/${_dest}"
+ ln -sfn -- "$(convert_abs_rel "${_dest}" "${_source}")" "${initdir}/${_dest}"
}
fi
[[ $i == /dev/mapper/mpath* ]] && continue
_tmp=$(udevadm info --query=name --name="$i" 2>/dev/null)
if [ "$_tmp" = "$_dev" ]; then
- echo $i
+ printf -- "%s" "$i"
return
fi
done
}
# get_fs_env <device>
-# Get and set the ID_FS_TYPE and ID_FS_UUID variable from udev for a device.
+# Get and set the ID_FS_TYPE variable from udev for a device.
# Example:
-# $ get_fs_env /dev/sda2; echo $ID_FS_TYPE; echo $ID_FS_UUID
+# $ get_fs_env /dev/sda2; echo $ID_FS_TYPE
# ext4
-# 551a39aa-4ae9-4e70-a262-ef665cadb574
get_fs_env() {
local evalstr
local found
[[ $1 ]] || return
unset ID_FS_TYPE
- unset ID_FS_UUID
- if evalstr=$(udevadm info --query=env --name=$1 \
+ if ID_FS_TYPE=$(udevadm info --query=env --name="$1" \
| { while read line; do
- strstr "$line" "DEVPATH" && found=1;
- strstr "$line" "ID_FS_TYPE=" && { echo $line; exit 0;}
+ [[ "$line" == DEVPATH\=* ]] && found=1;
+ if [[ "$line" == ID_FS_TYPE\=* ]]; then
+ printf "%s" "${line#ID_FS_TYPE=}";
+ exit 0;
+ fi
done; [[ $found ]] && exit 0; exit 1; }) ; then
- eval $evalstr
- [[ $ID_FS_TYPE ]] && return 0
+ if [[ $ID_FS_TYPE ]]; then
+ printf "%s" "$ID_FS_TYPE"
+ return 0
+ fi
return 1
fi
# Fallback, if we don't have udev information
if find_binary blkid >/dev/null; then
- eval $(blkid -o udev $1 \
+ ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \
| while read line; do
- strstr "$line" "ID_FS_TYPE=" && echo $line;
+ if [[ "$line" == TYPE\=* ]]; then
+ printf "%s" "${line#TYPE=}";
+ exit 0;
+ fi
done)
- [[ $ID_FS_TYPE ]] && return 0
+ if [[ $ID_FS_TYPE ]]; then
+ printf "%s" "$ID_FS_TYPE"
+ return 0
+ fi
fi
return 1
}
# $ get_maj_min /dev/sda2
# 8:2
get_maj_min() {
- local _dev
- _dev=$(stat -L -c '$((0x%t)):$((0x%T))' "$1" 2>/dev/null)
- _dev=$(eval "echo $_dev")
- echo $_dev
+ local _maj _min
+ read _maj _min < <(stat -L -c '%t %T' "$1" 2>/dev/null)
+ printf "%s" "$((0x$_maj)):$((0x$_min))"
}
# find_block_device <mountpoint>
# We never overwrite the target if it exists.
inst_simple() {
[[ -f "$1" ]] || return 1
- strstr "$1" "/" || return 1
+ [[ "$1" == */* ]] || return 1
local _src=$1 _target="${2:-$1}"
[[ -L $_src ]] && { inst_symlink $_src $_target; return $?; }
# same as above, but specialized for symlinks
inst_symlink() {
local _src=$1 _target=${2:-$1} _realsrc
- strstr "$1" "/" || return 1
+ [[ "$1" == */* ]] || return 1
[[ -L $1 ]] || return 1
[[ -L $initdir/$_target ]] && return 0
_realsrc=$(readlink -f "$_src")
# is referenced.
inst_library() {
local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
- strstr "$1" "/" || return 1
+ [[ "$1" == */* ]] || return 1
[[ -e $initdir/$_dest ]] && return 0
if [[ -L $_src ]]; then
if [[ $DRACUT_FIPS_MODE ]]; then
continue
fi
- if [[ $_line =~ not\ found ]]; then
+ if [[ $_line == *not\ found* ]]; then
dfatal "Missing a shared library required by $_bin."
dfatal "Run \"ldd $_bin\" to find out what it is."
dfatal "$_line"
local fn="$1" orig="$(readlink -f "$1")" links=''
- [[ ${fn} =~ .*\.so\..* ]] || return 1
+ [[ ${fn} == *.so.* ]] || return 1
until [[ ${fn##*.} == so ]]; do
fn="${fn%.*}"
dfatal "Cannot install a hook ($3) that does not exist."
dfatal "Aborting initrd creation."
exit 1
- elif ! strstr "$hookdirs" "$1"; then
+ elif ! [[ "$hookdirs" == *$1* ]]; then
dfatal "No such hook type $1. Aborting initrd creation."
exit 1
fi
_ret=$?
else
unset check depends install installkernel
+ check() { true; }
. $_moddir/module-setup.sh
is_func check || return 0
[ $_forced -ne 0 ] && unset hostonly
_ret=$?
else
unset check depends install installkernel
+ check() { false; }
. $_moddir/module-setup.sh
- is_func check || return 1
check 0
_ret=$?
unset check depends install installkernel
return $?
else
unset check depends install installkernel
+ depends() { true; }
. $_moddir/module-setup.sh
- is_func depends || return 0
depends
_ret=$?
unset check depends install installkernel
return $?
else
unset check depends install installkernel
+ install() { true; }
. $_moddir/module-setup.sh
- is_func install || return 0
install
_ret=$?
unset check depends install installkernel
return $?
else
unset check depends install installkernel
- . $_moddir/module-setup.sh
- is_func installkernel || return 0
+ installkernel() { true; }
+ . $_moddir/module-setup.sh
installkernel
_ret=$?
unset check depends install installkernel
[ "${#host_fs_types[*]}" -le 0 ] && return 1
# If we are already scheduled to be loaded, no need to check again.
- strstr " $mods_to_load " " $_mod " && return 0
- strstr " $mods_checked_as_dep " " $_mod " && return 1
+ [[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
+ [[ " $mods_checked_as_dep " == *\ $_mod\ * ]] && return 1
# This should never happen, but...
[[ -d $_moddir ]] || return 1
[[ $2 ]] || mods_checked_as_dep+=" $_mod "
- if strstr " $omit_dracutmodules " " $_mod "; then
+ if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then
dinfo "dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
return 1
fi
- if strstr " $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
+ if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
module_check_mount $_mod; ret=$?
# explicit module, so also accept ret=255
for _moddep in $(module_depends $_mod); do
# handle deps as if they were manually added
- strstr " $add_dracutmodules " " $_moddep " || \
+ [[ " $add_dracutmodules " == *\ $_moddep\ * ]] || \
add_dracutmodules+=" $_moddep "
- strstr " $force_add_dracutmodules " " $_moddep " || \
+ [[ " $force_add_dracutmodules " == *\ $_moddep\ * ]] || \
force_add_dracutmodules+=" $_moddep "
# if a module we depend on fail, fail also
if ! check_module $_moddep; then
fi
done
- strstr " $mods_to_load " " $_mod " || \
+ [[ " $mods_to_load " == *\ $_mod\ * ]] || \
mods_to_load+=" $_mod "
return 0
local _ret
local _moddep
# If we are already scheduled to be loaded, no need to check again.
- strstr " $mods_to_load " " $_mod " && return 0
- strstr " $mods_checked_as_dep " " $_mod " && return 1
+ [[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
+ [[ " $mods_checked_as_dep " == *\ $_mod\ * ]] && return 1
# This should never happen, but...
[[ -d $_moddir ]] || return 1
[[ $2 ]] || mods_checked_as_dep+=" $_mod "
- if strstr " $omit_dracutmodules " " $_mod "; then
+ if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then
dinfo "dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
return 1
fi
- if strstr " $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
- if strstr " $force_add_dracutmodules" " $_mod"; then
+ if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
+ if [[ " $force_add_dracutmodules " == *\ $_mod\ * ]]; then
module_check $_mod 1; ret=$?
else
module_check $_mod 0; ret=$?
for _moddep in $(module_depends $_mod); do
# handle deps as if they were manually added
- strstr " $add_dracutmodules " " $_moddep " || \
+ [[ " $add_dracutmodules " == *\ $_moddep\ * ]] || \
add_dracutmodules+=" $_moddep "
- strstr " $force_add_dracutmodules " " $_moddep " || \
+ [[ " $force_add_dracutmodules " == *\ $_moddep\ * ]] || \
force_add_dracutmodules+=" $_moddep "
# if a module we depend on fail, fail also
if ! check_module $_moddep; then
fi
done
- strstr " $mods_to_load " " $_mod " || \
+ [[ " $mods_to_load " == *\ $_mod\ * ]] || \
mods_to_load+=" $_mod "
return 0
_modcheck="$add_dracutmodules $force_add_dracutmodules"
[[ $dracutmodules != all ]] && _modcheck="$m $dracutmodules"
for _mod in $_modcheck; do
- strstr "$mods_to_load" "$_mod" && continue
- strstr "$omit_dracutmodules" "$_mod" && continue
+ [[ " $mods_to_load " == *\ $_mod\ * ]] && continue
+ [[ " $omit_dracutmodules " == *\ $_mod\ * ]] && continue
derror "dracut module '$_mod' cannot be found or installed."
done
}
[[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
}
-module_is_host_only() (
+module_is_host_only() { (
local _mod=$1
_mod=${_mod##*/}
_mod=${_mod%.ko}
- [[ "$add_drivers" =~ " ${_mod} " ]] && return 0
+ [[ " $add_drivers " == *\ ${_mod}\ * ]] && return 0
# check if module is loaded
- [[ -d $(echo /sys/module/${_mod//-/_}|{ read a b; echo $a; }) ]] && return 0
+ for i in /sys/module/${_mod//-/_}; do
+ [[ -d $i ]] && return 0
+ done
# check if module is loadable on the current kernel
# this covers the case, where a new module is introduced
modinfo -F filename "$_mod" &>/dev/null || return 0
return 1
-)
+ )
+}
-find_kernel_modules_by_path () (
+find_kernel_modules_by_path () {
local _OLDIFS
- [[ -f $srcmods/modules.dep ]] || return 0
+ [[ -f "$srcmods/modules.dep" ]] || return 0
_OLDIFS=$IFS
IFS=:
while read a rest; do
[[ $a = */$1/* ]] || continue
- echo $srcmods/$a
- done < $srcmods/modules.dep
+ printf "%s\n" "$srcmods/$a"
+ done < "$srcmods/modules.dep"
IFS=$_OLDIFS
return 0
-)
+}
find_kernel_modules () {
find_kernel_modules_by_path drivers
if [[ "$__resultvar" ]]; then
eval $__resultvar="'$_value'"
else
- echo "$_value"
+ printf "%s" "$_value"
fi
eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
return 0
fi
}
-
dropindirs_sort()
{
- suffix=$1; shift
- args=("$@")
- files=$(
- while (( $# > 0 )); do
- for i in ${1}/*${suffix}; do
- [[ -f $i ]] && echo ${i##*/}
+ local suffix=$1; shift
+ local -a files
+ local f d
+
+ readarray -t files < <(
+ for d in "$@"; do
+ for i in "$d/"*"$suffix"; do
+ if [[ -e "$i" ]]; then
+ printf "%s" "${i##*/}"
+ fi
done
- shift
done | sort -Vu
)
- for f in $files; do
- for d in "${args[@]}"; do
- if [[ -f "$d/$f" ]]; then
- echo "$d/$f"
+ for f in "${files[@]}"; do
+ for d in "$@"; do
+ if [[ -e "$d/$f" ]]; then
+ printf "%s" "$d/$f"
continue 2
fi
done
-q|--quiet) ((verbosity_mod_l--));;
-l|--local)
allowlocal="yes"
- [[ -f "$(readlink -f ${0%/*})/dracut-functions.sh" ]] \
- && dracutbasedir="$(readlink -f ${0%/*})"
+ [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \
+ && dracutbasedir="$(readlink -f "${0%/*}")"
;;
-H|--hostonly|--host-only)
hostonly_l="yes" ;;
if [[ $regenerate_all == "yes" ]]; then
ret=0
if [[ $kernel ]]; then
- echo "--regenerate-all cannot be called with a kernel version" >&2
+ printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
exit 1
fi
if [[ $outfile ]]; then
- echo "--regenerate-all cannot be called with a image file" >&2
+ printf -- "--regenerate-all cannot be called with a image file\n" >&2
exit 1
fi
cd /lib/modules
for i in *; do
[[ -f $i/modules.builtin ]] || continue
- dracut --kver=$i "${dracut_args[@]}"
+ dracut --kver="$i" "${dracut_args[@]}"
((ret+=$?))
done
exit $ret
# if we were not passed a config file, try the default one
if [[ ! -f $conffile ]]; then
- [[ $allowlocal ]] && conffile="$dracutbasedir/dracut.conf" || \
+ if [[ $allowlocal ]]; then
+ conffile="$dracutbasedir/dracut.conf"
+ else
conffile="/etc/dracut.conf"
+ fi
fi
if [[ ! -d $confdir ]]; then
- [[ $allowlocal ]] && confdir="$dracutbasedir/dracut.conf.d" || \
+ if [[ $allowlocal ]]; then
+ confdir="$dracutbasedir/dracut.conf.d"
+ else
confdir="/etc/dracut.conf.d"
+ fi
fi
# source our config file
bzip2) compress="bzip2 -9";;
lzma) compress="lzma -9";;
xz) compress="xz --check=crc32 --lzma2=dict=1MiB";;
- gzip) command -v pigz > /dev/null 2>&1 && compress="pigz -9" || \
- compress="gzip -9";;
+ gzip) compress="gzip -9"; command -v pigz > /dev/null 2>&1 && compress="pigz -9";;
esac
if [[ $_no_compress_l = "cat" ]]; then
compress="cat"
[[ $hostonly != "-h" ]] && unset hostonly
readonly TMPDIR="$tmpdir"
-readonly initdir=$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)
+readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
[ -d "$initdir" ] || {
- echo "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
+ printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
exit 1
}
# clean up after ourselves no matter how we die.
-trap 'ret=$?;[[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f -- "$outfile.$$";[[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir";exit $ret; };' EXIT
+trap 'ret=$?;[[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f -- "$outfile.$$";[[ $keep ]] && printf "%s\n" "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir";exit $ret; };' EXIT
# clean up after ourselves no matter how we die.
trap 'exit 1;' SIGINT
if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
. $dracutbasedir/dracut-functions.sh
else
- echo "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
- echo "dracut: Are you running from a git checkout?" >&2
- echo "dracut: Try passing -l as an argument to $0" >&2
+ printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
+ printf "%s\n" "dracut: Are you running from a git checkout?" >&2
+ printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
exit 1
fi
fi
# Verify bash version, current minimum is 3.1
-if (( ${BASH_VERSINFO[0]} < 3 ||
- ( ${BASH_VERSINFO[0]} == 3 && ${BASH_VERSINFO[1]} < 1 ) )); then
- dfatal 'You need at least Bash 3.1 to use dracut, sorry.'
+if (( BASH_VERSINFO[0] < 4 )); then
+ dfatal 'You need at least Bash 4 to use dracut, sorry.'
exit 1
fi
omit_drivers_corrected=""
for d in $omit_drivers; do
- strstr " $drivers $add_drivers " " $d " && continue
+ [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue
omit_drivers_corrected+="$d|"
done
omit_drivers="${omit_drivers_corrected%|}"
# prepare args for logging
for ((i=0; i < ${#dracut_args[@]}; i++)); do
- strstr "${dracut_args[$i]}" " " && \
+ [[ "${dracut_args[$i]}" == *\ * ]] && \
dracut_args[$i]="\"${dracut_args[$i]}\""
#" keep vim happy
done
[[ -d $mod ]] || continue;
[[ -e $mod/install || -e $mod/installkernel || \
-e $mod/module-setup.sh ]] || continue
- echo ${mod##*/??}
+ printf "%s\n" "${mod##*/??}"
done
exit 0
}
done
for f in $add_fstab; do
- [ -e $f ] || continue
+ [[ -e $f ]] || continue
while read dev rest; do
- push host_devs $dev
- done < $f
+ push host_devs "$dev"
+ done < "$f"
+done
+
+for dev in $add_device; do
+ push host_devs "$dev"
done
if (( ${#add_device_l[@]} )); then
while pop add_device_l val; do
add_device+=" $val "
+ push host_devs "$val"
done
fi
-for dev in $add_device; do
- push host_devs $dev
-done
-
if [[ $hostonly ]]; then
# in hostonly mode, determine all devices, which have to be accessed
# and examine them for filesystem types
"/boot";
do
mountpoint "$mp" >/dev/null 2>&1 || continue
- push host_devs $(readlink -f "/dev/block/$(find_block_device "$mp")")
+ push host_devs "$(readlink -f "/dev/block/$(find_block_device "$mp")")"
done
while read dev type rest; do
[[ $_o == *swap* ]] && continue 2
done < /etc/crypttab
- push host_devs $(readlink -f $dev)
+ push host_devs "$(readlink -f "$dev")"
break
done < /etc/fstab
done < /proc/swaps
fi
-_get_fs_type() (
+_get_fs_type() { (
[[ $1 ]] || return
- if [[ -b $1 ]] && get_fs_env $1; then
- echo "$(readlink -f $1) $ID_FS_TYPE"
+ if [[ -b /dev/block/$1 ]] && ID_FS_TYPE=$(get_fs_env "/dev/block/$1"); then
+ printf "%s\n" "$(readlink -f "/dev/block/$1")" "$ID_FS_TYPE"
return 1
fi
- if [[ -b /dev/block/$1 ]] && get_fs_env /dev/block/$1; then
- echo "$(readlink -f /dev/block/$1) $ID_FS_TYPE"
+ if [[ -b $1 ]] && ID_FS_TYPE=$(get_fs_env "$1"); then
+ printf "%s\n" "$(readlink -f "$1")" "$ID_FS_TYPE"
return 1
fi
- if fstype=$(find_dev_fstype $1); then
- echo "$1 $fstype"
+ if fstype=$(find_dev_fstype "$1"); then
+ printf "%s\n" "$1" "$fstype"
return 1
fi
return 1
-)
+) }
for dev in "${host_devs[@]}"; do
- while read key val; do
+ while read key; do
+ read val
host_fs_types["$key"]="$val"
done < <(
- _get_fs_type $dev
- check_block_and_slaves_all _get_fs_type $(get_maj_min $dev)
+ _get_fs_type "$dev"
+ check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
)
done
[[ -d $udevdir ]] \
- || udevdir=$(pkg-config udev --variable=udevdir 2>/dev/null)
+ || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
if ! [[ -d "$udevdir" ]]; then
[[ -d /lib/udev ]] && udevdir=/lib/udev
[[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
if [[ $prefix ]]; then
for d in bin etc lib sbin tmp usr var $libdirs; do
- strstr "$d" "/" && continue
+ [[ "$d" == */* ]] && continue
ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
done
fi
for_each_module_dir check_module
for_each_module_dir check_mount
-strstr "$mods_to_load" "fips" && export DRACUT_FIPS_MODE=1
+[[ "$mods_to_load " == *01fips\ * ]] && export DRACUT_FIPS_MODE=1
_isize=0 #initramfs size
modules_loaded=" "
# source our modules.
for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
_d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
- if strstr "$mods_to_load" " $_d_mod "; then
- [[ $show_modules = yes ]] && echo "$_d_mod" || \
+ if [[ "$mods_to_load" == *\ $_d_mod\ * ]]; then
+ if [[ $show_modules = yes ]]; then
+ printf "%s\n" "$_d_mod"
+ else
dinfo "*** Including module: $_d_mod ***"
- if [[ $kernel_only = yes ]]; then
- module_installkernel $_d_mod || {
+ fi
+ if [[ $kernel_only == yes ]]; then
+ module_installkernel "$_d_mod" || {
dfatal "installkernel failed in module $_d_mod"
exit 1
}
else
- module_install $_d_mod
+ module_install "$_d_mod"
if [[ $no_kernel != yes ]]; then
- module_installkernel $_d_mod || {
+ module_installkernel "$_d_mod" || {
dfatal "installkernel failed in module $_d_mod"
exit 1
}
#print the module install size
if [ -n "$printsize" ]; then
_isize_new=$(du -sk ${initdir}|cut -f1)
- _isize_delta=$(($_isize_new - $_isize))
- echo "$_d_mod install size: ${_isize_delta}k"
+ _isize_delta=$((_isize_new - _isize))
+ printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
_isize=$_isize_new
fi
fi
for i in $modules_loaded; do
mkdir -p $initdir/lib/dracut
- echo "$i" >> $initdir/lib/dracut/modules.txt
+ printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt
done
dinfo "*** Including modules done ***"
fi
if [[ $kernel_only != yes ]]; then
- (( ${#install_items[@]} > 0 )) && dracut_install ${install_items[@]}
+ (( ${#install_items[@]} > 0 )) && dracut_install ${install_items[@]}
- [[ $kernel_cmdline ]] && echo "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
+ [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
while pop fstab_lines line; do
- echo "$line 0 0" >> "${initdir}/etc/fstab"
+ printf "%s\n" "$line 0 0" >> "${initdir}/etc/fstab"
done
for f in $add_fstab; do
- cat $f >> "${initdir}/etc/fstab"
+ cat "$f" >> "${initdir}/etc/fstab"
done
if [ -d ${initdir}/$systemdutildir ]; then
mkdir -p ${initdir}/etc/conf.d
{
- echo "systemdutildir=\"$systemdutildir\""
- echo "systemdsystemunitdir=\"$systemdsystemunitdir\""
- echo "systemdsystemconfdir=\"$systemdsystemconfdir\""
+ printf "%s\n" "systemdutildir=\"$systemdutildir\""
+ printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
+ printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
} > ${initdir}/etc/conf.d/systemd.conf
fi
find "$initdir" -type f \
'(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
-not -path '*.ko' -print0 \
- | xargs -r -0 $DRACUT_INSTALL ${initdir+-D "$initdir"} -R ${DRACUT_FIPS_MODE+-H}
+ | xargs -r -0 $DRACUT_INSTALL ${initdir+-D "$initdir"} -R ${DRACUT_FIPS_MODE+-H} --
dinfo "*** Resolving executable dependencies done***"
fi
fi
fi
fi
-if (($maxloglvl >= 5)); then
+if (( maxloglvl >= 5 )); then
ddebug "Listing sizes of included files:"
du -c "$initdir" | sort -n | ddebug
fi
-PRELINK_BIN=$(command -v prelink)
+PRELINK_BIN="$(command -v prelink)"
if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
if [[ $DRACUT_FIPS_MODE ]]; then
dinfo "*** Installing prelink files ***"
else
dinfo "*** Pre-linking files ***"
dracut_install -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf
- chroot "$initdir" $PRELINK_BIN -a
- rm -f -- "$initdir"/$PRELINK_BIN
+ chroot "$initdir" "$PRELINK_BIN" -a
+ rm -f -- "$initdir/$PRELINK_BIN"
rm -fr -- "$initdir"/etc/prelink.*
dinfo "*** Pre-linking files done ***"
fi
&& ! [[ -e "/lib64/hmaccalc/${f##*/}.hmac" ]] \
&& ! [[ -e "/lib/fipscheck/${f##*/}.hmac" ]] \
&& ! [[ -e "/lib64/fipscheck/${f##*/}.hmac" ]]; then
- echo -n "$f"; echo -n -e "\000"
+ printf "%s\000" "$f";
fi
done | xargs -r -0 strip -g 2>/dev/null
else
find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
| while read -r -d $'\0' f; do
SIG=$(tail -c 28 "$f")
- [[ $SIG == '~Module signature appended~' ]] || { echo -n "$f"; echo -n -e "\000"; }
+ [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
done | xargs -r -0 strip -g
dinfo "*** Stripping files done ***"
rm -f -- "$outfile"
dinfo "*** Creating image file ***"
-if ! ( umask 077; cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet| \
+if ! ( umask 077; cd "$initdir"; find . | cpio -R 0:0 -H newc -o --quiet | \
$compress > "$outfile.$$"; ); then
dfatal "dracut: creation of $outfile.$$ failed"
exit 1
fi
-mv $outfile.$$ $outfile
+mv -- "$outfile.$$" "$outfile"
dinfo "*** Creating image file done ***"
dinfo "Wrote $outfile:"
for f in ${!filenames[@]}; do
[[ $nofileinfo ]] || echo "initramfs:/$f"
[[ $nofileinfo ]] || echo "========================================================================"
- $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null
+ $CAT -- $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null
((ret+=$?))
[[ $nofileinfo ]] || echo "========================================================================"
[[ $nofileinfo ]] || echo
else
echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)"
echo "========================================================================"
- version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout '*lib/dracut/dracut-*' 2>/dev/null)
+ version=$($CAT -- "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/dracut-*' 2>/dev/null)
((ret+=$?))
echo "$version with dracut modules:"
- $CAT "$image" | cpio --extract --verbose --quiet --to-stdout 'usr/lib/dracut/modules.txt' 2>/dev/null
+ $CAT -- "$image" | cpio --extract --verbose --quiet --to-stdout -- 'usr/lib/dracut/modules.txt' 2>/dev/null
((ret+=$?))
echo "========================================================================"
if [ "$sorted" -eq 1 ]; then
- $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5
+ $CAT -- "$image" | cpio --extract --verbose --quiet --list | sort -n -k5
else
- $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9
+ $CAT -- "$image" | cpio --extract --verbose --quiet --list | sort -k9
fi
((ret+=$?))
echo "========================================================================"
bcast=$new_broadcast_address
gw=${new_routers%%,*}
domain=$new_domain_name
- search=$(printf "$new_domain_search")
+ search=$(printf -- "$new_domain_search")
namesrv=$new_domain_name_servers
hostname=$new_host_name
local handler="$(get_url_handler $url)"
[ -n "$handler" ] || return 254
[ -n "$url" ] || return 255
- $handler "$url" "$outloc"
+ "$handler" "$url" "$outloc"
}
# get_url_handler URL
local url="$1" outloc="$2"
echo "$url" > /proc/self/fd/0
if [ -n "$outloc" ]; then
- curl $curl_args --output "$outloc" "$url" || return $?
+ curl $curl_args --output "$outloc" -- "$url" || return $?
else
local outdir="$(mkuniqdir /tmp curl_fetch_url)"
( cd "$outdir"; curl $curl_args --remote-name "$url" || return $? )
local filepath="${path%/*}" filename="${path##*/}" mntdir=""
# skip mount if server:/filepath is already mounted
- mntdir=$(nfs_already_mounted $server $path)
+ mntdir=$(nfs_already_mounted "$server" "$path")
if [ -z "$mntdir" ]; then
local mntdir="$(mkuniqdir /run nfs_mnt)"
- mount_nfs $nfs:$server:$filepath${options:+:$options} $mntdir
+ mount_nfs "$nfs:$server:$filepath${options:+:$options}" "$mntdir"
# lazy unmount during pre-pivot hook
- inst_hook --hook pre-pivot --name 99url-lib-umount-nfs umount -l $mntdir
+ inst_hook --hook pre-pivot --name 99url-lib-umount-nfs umount -l -- "$mntdir"
fi
if [ -z "$outloc" ]; then
outloc="$mntdir/$filename"
else
- cp -f "$mntdir/$filename" "$outloc" || return $?
+ cp -f -- "$mntdir/$filename" "$outloc" || return $?
fi
[ -f "$outloc" ] || return 253
if [ -z "$2" ]; then echo "$outloc" ; fi
eval $(udevadm info --query=property --name=$1 | egrep '(DM_VG_NAME|DM_LV_NAME|DM_UDEV_DISABLE_DISK_RULES_FLAG)=')
[[ "$DM_UDEV_DISABLE_DISK_RULES_FLAG" = "1" ]] && return 1
[[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 1
- if ! strstr " ${_activated[*]} " " ${DM_VG_NAME}/${DM_LV_NAME} "; then
+ if ! [[ " ${_activated[*]} " == *\ ${DM_VG_NAME}/${DM_LV_NAME}\ * ]]; then
if ! [[ $kernel_only ]]; then
echo " rd.lvm.lv=${DM_VG_NAME}/${DM_LV_NAME} " >> "${initdir}/etc/cmdline.d/90lvm.conf"
fi
for dasd_arg in $(getargs rd.dasd= -d rd_DASD= DASD=); do
(
IFS=","
- set $dasd_arg
+ set -- $dasd_arg
echo "$@" | normalize_dasd_arg >> /etc/dasd.conf
)
done
# If hostonly was requested, fail the check if we are not actually
# booting from root.
- is_iscsi() (
+ is_iscsi() {
local _dev=$1
- [[ -L /sys/dev/block/$_dev ]] || return
- cd "$(readlink -f /sys/dev/block/$_dev)"
+ [[ -L "/sys/dev/block/$_dev" ]] || return
+ cd "$(readlink -f "/sys/dev/block/$_dev")"
until [[ -d sys || -d iscsi_session ]]; do
cd ..
done
[[ -d iscsi_session ]]
- )
+ }
[[ $hostonly ]] || [[ $mount_needs ]] && {
+ pushd . >/dev/null
for_each_host_dev_and_slaves is_iscsi || return 1
+ popd >/dev/null
}
return 0
}
# exit 1
# fi
- if strstr "$prefix" "/run/"; then
+ if [[ "$prefix" == /run/* ]]; then
dfatal "systemd does not work with a prefix, which contains \"/run\"!!"
exit 1
fi
case $_pid in
*[!0-9]*) continue;;
esac
- [ -e /proc/$_pid/exe ] || continue
- [ -e /proc/$_pid/root ] || continue
- strstr "$(ls -l /proc/$_pid /proc/$_pid/fd 2>/dev/null)" "$1" && kill -9 $_pid
+ [ -e "/proc/$_pid/exe" ] || continue
+ [ -e "/proc/$_pid/root" ] || continue
+ strstr "$(ls -l -- '/proc/$_pid' '/proc/$_pid/fd' 2>/dev/null)" "$1" && kill -9 "$_pid"
done
}
continue
fi
- _val=${_o#*=};
+ _val="${_o#*=}"
_doecho=1
fi
done
_deprecated=0
shift 2;;
*) if [ -z "$_newoption" ]; then
- _newoption=$1
+ _newoption="$1"
fi
if _dogetarg $1; then
if [ "$_deprecated" = "1" ]; then
local _b
unset _b
local _default
- _default=$1; shift
+ _default="$1"; shift
_b=$(getarg "$@")
- [ $? -ne 0 -a -z "$_b" ] && _b=$_default
+ [ $? -ne 0 -a -z "$_b" ] && _b="$_default"
if [ -n "$_b" ]; then
[ $_b = "0" ] && return 1
[ $_b = "no" ] && return 1
local _b
unset _b
local _default _min _max
- _default=$1; shift
- _min=$1; shift
- _max=$1; shift
+ _default="$1"; shift
+ _min="$1"; shift
+ _max="$1"; shift
_b=$(getarg "$1")
[ $? -ne 0 -a -z "$_b" ] && _b=$_default
if [ -n "$_b" ]; then
isdigit "$_b" && _b=$(($_b)) && \
- [ $_b -ge $_min ] && [ $_b -le $_max ] && echo $_b && return
+ [ $_b -ge $_min ] && [ $_b -le $_max ] && echo $_b && return
fi
echo $_default
}
unset _o
unset _found
_getcmdline
- _key=$1
+ _key="$1"
set --
for _o in $CMDLINE; do
if [ "$_o" = "$_key" ]; then
check_finished() {
local f
- for f in $hookdir/initqueue/finished/*.sh; do
+ for f in $hookdir/initqueue/finished/*.sh; do
[ "$f" = "$hookdir/initqueue/finished/*.sh" ] && return 0
{ [ -e "$f" ] && ( . "$f" ) ; } || return 1
done
echo "warn dracut: FATAL: \"$*\"";
echo "warn dracut: Refusing to continue";
} >> $hookdir/emergency/01-die.sh
- [ -d /run/initramfs ] || mkdir -p /run/initramfs
+ [ -d /run/initramfs ] || mkdir -p -- /run/initramfs
> /run/initramfs/.die
emergency_shell
exit 1
UUID=*)
printf 'ENV{ID_FS_UUID}=="%s*"' "${1#*=}"
;;
- /dev/?*) printf 'KERNEL=="%s"' "${1#/dev/}" ;;
+ /dev/?*) printf -- 'KERNEL=="%s"' "${1#/dev/}" ;;
*) return 255 ;;
esac
}
_helpers="$fscks"
fi
- if strstr "$_helpers" e2fsck && [ -e /etc/e2fsck.conf ]; then
+ if [[ "$_helpers" == *e2fsck* ]] && [ -e /etc/e2fsck.conf ]; then
inst_simple /etc/e2fsck.conf
fi
#!/bin/bash
TEST_DESCRIPTION="root filesystem on a ext3 filesystem"
-KVERSION=${KVERSION-$(uname -r)}
+KVERSION="${KVERSION-$(uname -r)}"
# Uncomment this to debug failures
#DEBUGFAIL="rd.shell"
export KVERSION=${KVERSION-$(uname -r)}
# Uncomment this to debug failures
-DEBUGFAIL="rd.shell rd.break"
+#DEBUGFAIL="rd.shell rd.break"
#DEBUGFAIL="rd.shell"
#DEBUGOUT="quiet systemd.log_level=debug systemd.log_target=console loglevel=77 rd.info rd.debug"
DEBUGOUT="loglevel=0 "
#!/bin/sh
-[ -b /dev/mapper/$2 ] && exit 0
+[ -b "/dev/mapper/$2" ] && exit 0
echo -n test >/keyfile
-/sbin/cryptsetup luksOpen $1 $2 </keyfile
-
+/sbin/cryptsetup luksOpen "$1" "$2" </keyfile
#!/bin/bash
TEST_DESCRIPTION="root filesystem on a LiveCD dmsquash filesystem"
-KVERSION=${KVERSION-$(uname -r)}
+KVERSION="${KVERSION-$(uname -r)}"
# Uncomment this to debug failures
#DEBUGFAIL="rd.shell rd.break"
}
test_run() {
- $testdir/run-qemu \
+ "$testdir"/run-qemu \
-boot order=d \
- -cdrom $TESTDIR/livecd.iso \
- -hda $TESTDIR/root.img \
+ -cdrom "$TESTDIR"/livecd.iso \
+ -hda "$TESTDIR"/root.img \
-m 256M -smp 2 -nographic \
- -net none -kernel /boot/vmlinuz-$KVERSION \
+ -net none -kernel /boot/vmlinuz-"$KVERSION" \
-append "root=live:CDLABEL=LiveCD live rw quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL" \
- -initrd $TESTDIR/initramfs.testing
- grep -F -m 1 -q dracut-root-block-success $TESTDIR/root.img || return 1
+ -initrd "$TESTDIR"/initramfs.testing
+ grep -F -m 1 -q dracut-root-block-success -- "$TESTDIR"/root.img || return 1
}
test_setup() {
- mkdir -p $TESTDIR/overlay
+ mkdir -p -- "$TESTDIR"/overlay
(
- export initdir=$TESTDIR/overlay
- . $basedir/dracut-functions.sh
+ export initdir="$TESTDIR"/overlay
+ . "$basedir"/dracut-functions.sh
dracut_install poweroff shutdown
inst_hook emergency 000 ./hard-off.sh
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
)
- dd if=/dev/zero of=$TESTDIR/root.img count=100
+ dd if=/dev/zero of="$TESTDIR"/root.img count=100
- sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
+ sudo $basedir/dracut.sh -l -i "$TESTDIR"/overlay / \
-a "debug dmsquash-live" \
-d "piix ide-gd_mod ata_piix ext3 sd_mod" \
- -f $TESTDIR/initramfs.testing $KVERSION || return 1
+ -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
- mkdir -p $TESTDIR/root-source
- kernel=$KVERSION
+ mkdir -p -- "$TESTDIR"/root-source
+ kernel="$KVERSION"
# Create what will eventually be our root filesystem onto an overlay
(
- export initdir=$TESTDIR/root-source
- . $basedir/dracut-functions.sh
+ export initdir="$TESTDIR"/root-source
+ . "$basedir"/dracut-functions.sh
dracut_install sh df free ls shutdown poweroff stty cat ps ln ip route \
mount dmesg ifconfig dhclient mkdir cp ping dhclient \
umount strace less
for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
- [ -f ${_terminfodir}/l/linux ] && break
+ [[ -f ${_terminfodir}/l/linux ]] && break
done
- dracut_install -o ${_terminfodir}/l/linux
+ dracut_install -o "${_terminfodir}"/l/linux
inst "$basedir/modules.d/40network/dhclient-script.sh" "/sbin/dhclient-script"
inst "$basedir/modules.d/40network/ifup.sh" "/sbin/ifup"
dracut_install grep syslinux isohybrid
done
inst_simple /etc/os-release
inst ./test-init.sh /sbin/init
- inst $TESTDIR/initramfs.testing "/boot/initramfs-$KVERSION.img"
- inst /boot/vmlinuz-$KVERSION
+ inst "$TESTDIR"/initramfs.testing "/boot/initramfs-$KVERSION.img"
+ inst /boot/vmlinuz-"$KVERSION"
find_binary plymouth >/dev/null && dracut_install plymouth
- (cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
- cp -a /etc/ld.so.conf* $initdir/etc
- sudo ldconfig -r "$initdir"
+ (cd "$initdir"; mkdir -p -- dev sys proc etc var/run tmp )
+ cp -a -- /etc/ld.so.conf* "$initdir"/etc
+ sudo ldconfig -r -- "$initdir"
)
python create.py -d -c livecd-fedora-minimal.ks
return 0
return 0
}
-. $testdir/test-functions
+. "$testdir"/test-functions
# Start server first
echo "MULTINIC TEST SETUP: Starting DHCP/NFS server"
- fsck -a $TESTDIR/server.ext3 || return 1
+ fsck -a "$TESTDIR"/server.ext3 || return 1
$testdir/run-qemu \
- -hda $TESTDIR/server.ext3 \
+ -hda "$TESTDIR"/server.ext3 \
-m 512M -smp 2 \
-display none \
-net socket,listen=127.0.0.1:12350 \
-net nic,macaddr=52:54:01:12:34:56,model=e1000 \
- ${SERIAL+-serial $SERIAL} \
+ ${SERIAL+-serial "$SERIAL"} \
-watchdog i6300esb -watchdog-action poweroff \
- -kernel /boot/vmlinuz-$KVERSION \
+ -kernel /boot/vmlinuz-"$KVERSION" \
-append "loglevel=7 root=/dev/sda rootfstype=ext3 rw console=ttyS0,115200n81 selinux=0" \
- -initrd $TESTDIR/initramfs.server \
- -pidfile $TESTDIR/server.pid -daemonize || return 1
- sudo chmod 644 $TESTDIR/server.pid || return 1
+ -initrd "$TESTDIR"/initramfs.server \
+ -pidfile "$TESTDIR"/server.pid -daemonize || return 1
+ sudo chmod 644 -- "$TESTDIR"/server.pid || return 1
# Cleanup the terminal if we have one
tty -s && stty sane
echo "CLIENT TEST START: $test_name"
# Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
- if ! dd if=/dev/zero of=$TESTDIR/client.img bs=1M count=1; then
+ if ! dd if=/dev/zero of="$TESTDIR"/client.img bs=1M count=1; then
echo "Unable to make client sda image" 1>&2
return 1
fi
- $testdir/run-qemu -hda $TESTDIR/client.img -m 512M -smp 2 -nographic \
+ $testdir/run-qemu -hda "$TESTDIR"/client.img -m 512M -smp 2 -nographic \
-net socket,connect=127.0.0.1:12350 \
-net nic,macaddr=52:54:00:12:34:$mac1,model=e1000 \
-net nic,macaddr=52:54:00:12:34:$mac2,model=e1000 \
-net nic,macaddr=52:54:00:12:34:$mac3,model=e1000 \
-watchdog i6300esb -watchdog-action poweroff \
- -kernel /boot/vmlinuz-$KVERSION \
+ -kernel /boot/vmlinuz-"$KVERSION" \
-append "$cmdline $DEBUGFAIL rd.retry=5 ro console=ttyS0,115200n81 selinux=0 init=/sbin/init rd.debug systemd.log_target=console loglevel=7" \
- -initrd $TESTDIR/initramfs.testing
+ -initrd "$TESTDIR"/initramfs.testing
- if [[ $? -ne 0 ]] || ! grep -F -m 1 -q OK $TESTDIR/client.img; then
+ if [[ $? -ne 0 ]] || ! grep -F -m 1 -q OK -- "$TESTDIR"/client.img; then
echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
return 1
fi
for i in $check ; do
echo $i
- if ! grep -F -m 1 -q $i $TESTDIR/client.img; then
+ if ! grep -F -m 1 -q $i -- "$TESTDIR"/client.img; then
echo "CLIENT TEST END: $test_name [FAILED - BAD IF]"
return 1
fi
test_setup() {
# Make server root
- dd if=/dev/null of=$TESTDIR/server.ext3 bs=1M seek=60
- mke2fs -j -F $TESTDIR/server.ext3
- mkdir $TESTDIR/mnt
- sudo mount -o loop $TESTDIR/server.ext3 $TESTDIR/mnt
+ dd if=/dev/null of="$TESTDIR"/server.ext3 bs=1M seek=60
+ mke2fs -j -F -- "$TESTDIR"/server.ext3
+ mkdir -- "$TESTDIR"/mnt
+ sudo mount -o loop -- "$TESTDIR"/server.ext3 "$TESTDIR"/mnt
(
- export initdir=$TESTDIR/mnt
- . $basedir/dracut-functions.sh
+ export initdir="$TESTDIR"/mnt
+ . "$basedir"/dracut-functions.sh
(
cd "$initdir";
- mkdir -p dev sys proc run etc var/run tmp var/lib/{dhcpd,rpcbind}
- mkdir -p var/lib/nfs/{v4recovery,rpc_pipefs}
- chmod 777 var/lib/rpcbind var/lib/nfs
+ mkdir -p -- dev sys proc run etc var/run tmp var/lib/{dhcpd,rpcbind}
+ mkdir -p -- var/lib/nfs/{v4recovery,rpc_pipefs}
+ chmod 777 -- var/lib/rpcbind var/lib/nfs
)
for _f in modules.builtin.bin modules.builtin; do
modprobe rpc.nfsd rpc.mountd showmount tcpdump \
/etc/services sleep mount chmod
for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
- [ -f ${_terminfodir}/l/linux ] && break
+ [ -f "${_terminfodir}"/l/linux ] && break
done
- dracut_install -o ${_terminfodir}/l/linux
+ dracut_install -o "${_terminfodir}"/l/linux
type -P portmap >/dev/null && dracut_install portmap
type -P rpcbind >/dev/null && dracut_install rpcbind
[ -f /etc/netconfig ] && dracut_install /etc/netconfig
inst /etc/passwd /etc/passwd
inst /etc/group /etc/group
- cp -a /etc/ld.so.conf* $initdir/etc
- sudo ldconfig -r "$initdir"
+ cp -a -- /etc/ld.so.conf* "$initdir"/etc
+ sudo ldconfig -r -- "$initdir"
dracut_kernel_post
)
# Make client root inside server root
(
- export initdir=$TESTDIR/mnt/nfs/client
- . $basedir/dracut-functions.sh
+ export initdir="$TESTDIR"/mnt/nfs/client
+ . "$basedir"/dracut-functions.sh
dracut_install sh shutdown poweroff stty cat ps ln ip \
mount dmesg mkdir cp ping grep ls
for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
- [ -f ${_terminfodir}/l/linux ] && break
+ [[ -f ${_terminfodir}/l/linux ]] && break
done
- dracut_install -o ${_terminfodir}/l/linux
+ dracut_install -o "${_terminfodir}"/l/linux
inst_simple /etc/os-release
inst ./client-init.sh /sbin/init
(
cd "$initdir"
- mkdir -p dev sys proc etc run
- mkdir -p var/lib/nfs/rpc_pipefs
+ mkdir -p -- dev sys proc etc run
+ mkdir -p -- var/lib/nfs/rpc_pipefs
)
inst /etc/nsswitch.conf /etc/nsswitch.conf
inst /etc/passwd /etc/passwd
inst_libdir_file 'libnfsidmap/*.so*'
inst_libdir_file 'libnfsidmap*.so*'
- _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \
+ _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' -- /etc/nsswitch.conf \
| tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
_nsslibs=${_nsslibs#|}
_nsslibs=${_nsslibs%|}
inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
- cp -a /etc/ld.so.conf* $initdir/etc
+ cp -a -- /etc/ld.so.conf* "$initdir"/etc
sudo ldconfig -r "$initdir"
)
- sudo umount $TESTDIR/mnt
- rm -fr -- $TESTDIR/mnt
+ sudo umount "$TESTDIR"/mnt
+ rm -fr -- "$TESTDIR"/mnt
# Make an overlay with needed tools for the test harness
(
- export initdir=$TESTDIR/overlay
- . $basedir/dracut-functions.sh
+ export initdir="$TESTDIR"/overlay
+ . "$basedir"/dracut-functions.sh
dracut_install poweroff shutdown
inst_hook emergency 000 ./hard-off.sh
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
)
# Make server's dracut image
- $basedir/dracut.sh -l -i $TESTDIR/overlay / \
+ $basedir/dracut.sh -l -i "$TESTDIR"/overlay / \
-m "dash udev-rules base rootfs-block debug kernel-modules watchdog" \
-d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files nfsd e1000 i6300esb ib700wdt" \
- -f $TESTDIR/initramfs.server $KVERSION || return 1
+ -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1
# Make client's dracut image
- $basedir/dracut.sh -l -i $TESTDIR/overlay / \
+ $basedir/dracut.sh -l -i "$TESTDIR"/overlay / \
-o "plymouth" \
-a "debug" \
-d "af_packet piix sd_mod sr_mod ata_piix ide-gd_mod e1000 nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files sunrpc i6300esb ib700wdt" \
- -f $TESTDIR/initramfs.testing $KVERSION || return 1
+ -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
}
kill_server() {
- if [[ -s $TESTDIR/server.pid ]]; then
- sudo kill -TERM $(cat $TESTDIR/server.pid)
- rm -f -- $TESTDIR/server.pid
+ if [[ -s "$TESTDIR"/server.pid ]]; then
+ sudo kill -TERM -- $(cat "$TESTDIR"/server.pid)
+ rm -f -- "$TESTDIR"/server.pid
fi
}
kill_server
}
-. $testdir/test-functions
+. "$testdir"/test-functions