export DRACUT_SYSTEMD
export NEWROOT
if [ -n "$NEWROOT" ]; then
- [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
+ [ -d "$NEWROOT" ] || mkdir -p -m 0755 "$NEWROOT"
fi
+# shellcheck disable=SC2153
if [ -z "$PREFIX" ]; then
if ! [ -d /run/initramfs ]; then
mkdir -p -m 0755 /run/initramfs/log
info() {
check_quiet
echo "<30>dracut: $*" > /dev/kmsg
- [ "$DRACUT_QUIET" != "yes" ] \
- && echo "dracut: $*" >&2 || :
+ if [ "$DRACUT_QUIET" != "yes" ]; then
+ echo "dracut: $*" >&2
+ fi
}
else
fi
vwarn() {
- while read line || [ -n "$line" ]; do
- warn $line
+ while read -r line || [ -n "$line" ]; do
+ warn "$line"
done
}
vinfo() {
- while read line || [ -n "$line" ]; do
- info $line
+ while read -r line || [ -n "$line" ]; do
+ info "$line"
done
}
killall_proc_mountpoint() {
local _pid
- local _t
local _killed=0
for _pid in /proc/*; do
_pid=${_pid##/proc/}
-y)
if dracut-getarg "$2" > /dev/null; then
if [ "$_deprecated" = "1" ]; then
- [ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption' instead." || warn "Option '$2' is deprecated."
+ if [ -n "$_newoption" ]; then
+ warn "Kernel command line option '$2' is deprecated, use '$_newoption' instead."
+ else
+ warn "Option '$2' is deprecated."
+ fi
fi
echo 1
debug_on
if dracut-getarg "$2" > /dev/null; then
echo 0
if [ "$_deprecated" = "1" ]; then
- [ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption=0' instead." || warn "Option '$2' is deprecated."
+ if [ -n "$_newoption" ]; then
+ warn "Kernel command line option '$2' is deprecated, use '$_newoption=0' instead."
+ else
+ warn "Option '$2' is deprecated."
+ fi
fi
debug_on
return 1
fi
if dracut-getarg "$1"; then
if [ "$_deprecated" = "1" ]; then
- [ -n "$_newoption" ] && warn "Kernel command line option '$1' is deprecated, use '$_newoption' instead." || warn "Option '$1' is deprecated."
+ if [ -n "$_newoption" ]; then
+ warn "Kernel command line option '$1' is deprecated, use '$_newoption' instead."
+ else
+ warn "Option '$1' is deprecated."
+ fi
fi
debug_on
return 0
local _default
_default="$1"
shift
- _b=$(getarg "$@")
- [ $? -ne 0 -a -z "$_b" ] && _b="$_default"
+ _b=$(getarg "$@") || _b=${_b:-"$_default"}
if [ -n "$_b" ]; then
- [ $_b = "0" ] && return 1
- [ $_b = "no" ] && return 1
- [ $_b = "off" ] && return 1
+ [ "$_b" = "0" ] && return 1
+ [ "$_b" = "no" ] && return 1
+ [ "$_b" = "off" ] && return 1
fi
return 0
}
shift
_max="$1"
shift
- _b=$(getarg "$1")
- [ $? -ne 0 -a -z "$_b" ] && _b=$_default
+ _b=$(getarg "$1") || _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
+ echo "$_default"
}
getargs() {
+ debug_off
CMDLINE=$(getcmdline)
export CMDLINE
- debug_off
- local _val _i _args _gfound _deprecated
+ local _val _i _gfound _deprecated
unset _val
unset _gfound
_newoption="$1"
- _args="$@"
- set --
- for _i in $_args; do
+ for _i in "$@"; do
if [ "$_i" = "-d" ]; then
_deprecated=1
continue
fi
- _val="$(dracut-getargs "$_i")"
- if [ $? -eq 0 ]; then
+
+ if _val="$(dracut-getargs "$_i")"; then
if [ "$_deprecated" = "1" ]; then
- [ -n "$_newoption" ] && warn "Option '$_i' is deprecated, use '$_newoption' instead." || warn "Option $_i is deprecated!"
+ if [ -n "$_newoption" ]; then
+ warn "Option '$_i' is deprecated, use '$_newoption' instead."
+ else
+ warn "Option $_i is deprecated!"
+ fi
+ fi
+ if [ -n "$_val" ]; then
+ printf '%s\n' "$_val"
fi
_gfound=1
fi
- [ -n "$_val" ] && set -- "$@" "$_val"
_deprecated=0
done
if [ -n "$_gfound" ]; then
- if [ $# -gt 0 ]; then
- printf '%s' "$*"
- fi
debug_on
return 0
fi
_dir=$1
shift
[ "$_dir" ] && [ -d "/$_dir" ] || return
- for f in "/$_dir"/*.sh; do [ -e "$f" ] && . "$f" "$@"; done
+ for f in "/$_dir"/*.sh; do
+ if [ -e "$f" ]; then
+ # dash can't source with parameters
+ if [ -z "$BASH" ] && [ $# -gt 0 ]; then
+ [ -x "$f" ] || chmod 0755 "$f"
+ "$f" "$@"
+ else
+ # shellcheck disable=SC1090
+ # shellcheck disable=SC2240
+ . "$f" "$@"
+ fi
+ fi
+ done
}
hookdir=/lib/dracut/hooks
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
+ # shellcheck disable=SC1090
{ [ -e "$f" ] && (. "$f"); } || return 1
done
return 0
source_conf() {
local f
[ "$1" ] && [ -d "/$1" ] || return
+ # shellcheck disable=SC1090
for f in "/$1"/*.conf; do [ -e "$f" ] && . "$f"; done
}
} >> $hookdir/emergency/01-die.sh
[ -d /run/initramfs ] || mkdir -p -- /run/initramfs
- > /run/initramfs/.die
+ : > /run/initramfs/.die
if getargbool 0 "rd.shell"; then
emergency_shell
getargbool 0 rd.debug -d -y rdinitdebug && DRACUT_QUIET="no"
getarg quiet || DRACUT_QUIET="yes"
a=$(getarg loglevel=)
- [ -n "$a" ] && [ $a -ge 28 ] && DRACUT_QUIET="yes"
+ [ -n "$a" ] && [ "$a" -ge 28 ] && DRACUT_QUIET="yes"
export DRACUT_QUIET
fi
}
count=$((count + 1))
done
- [ $count -eq $expected ]
+ [ $count -eq "$expected" ]
}
incol2() {
debug_off
- local dummy check
+ local check
local file="$1"
local str="$2"
[ -z "$file" ] && return 1
[ -z "$str" ] && return 1
- while read dummy check restofline || [ -n "$check" ]; do
+ while read -r _ check _ || [ -n "$check" ]; do
if [ "$check" = "$str" ]; then
debug_on
return 0
fi
- done < $file
+ done < "$file"
debug_on
return 1
}
udevsettle() {
- [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
-
- if [ $UDEVVERSION -ge 143 ]; then
- udevadm settle --exit-if-exists=$hookdir/initqueue/work $settle_exit_if_exists
- else
- udevadm settle --timeout=30
- fi
+ # shellcheck disable=SC2086
+ udevadm settle --exit-if-exists=$hookdir/initqueue/work $settle_exit_if_exists
}
udevproperty() {
- [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
-
- if [ $UDEVVERSION -ge 143 ]; then
- for i in "$@"; do udevadm control --property=$i; done
- else
- for i in "$@"; do udevadm control --env=$i; done
- fi
+ for i in "$@"; do
+ udevadm control --property="$i"
+ done
}
find_mount() {
- local dev mnt etc wanted_dev
- wanted_dev="$(readlink -e -q $1)"
- while read dev mnt etc || [ -n "$dev" ]; do
+ local dev wanted_dev
+ wanted_dev="$(readlink -e -q "$1")"
+ while read -r dev _ || [ -n "$dev" ]; do
[ "$dev" = "$wanted_dev" ] && echo "$dev" && return 0
done < /proc/mounts
return 1
return 1
fi
- while read a m a || [ -n "$m" ]; do
+ while read -r _ m _ || [ -n "$m" ]; do
[ "$m" = "$1" ] && return 0
done < /proc/mounts
return 1
# copytree SRC DEST
copytree() {
local src="$1" dest="$2"
- mkdir -p "$dest"
- dest=$(readlink -e -q "$dest")
+ [ -d "$src" ] || return 1
+ mkdir -p "$dest" || return 1
+ dest=$(readlink -e -q "$dest") || return 1
(
- cd "$src"
+ cd "$src" || exit 1
cp -af . -t "$dest"
)
}
# foreach_uuid_until "mount -U \$___ /mnt; echo OK; umount /mnt" \
# "01234 f512 a235567f-12a3-c123-a1b1-01234567abcb"
foreach_uuid_until() (
- cd /dev/disk/by-uuid
+ cd /dev/disk/by-uuid || return 1
[ "$1" = -p ] && local prefix="$2" && shift 2
local cmd="$1"
[ -n "${cmd}" ] || return 1
for uuid in ${uuids_list:-*}; do
- for full_uuid in ${uuid}*; do
+ for full_uuid in "${uuid}"*; do
[ -e "${full_uuid}" ] || continue
+ # shellcheck disable=SC2034
___="${prefix}${full_uuid}"
- eval ${cmd} && return 0
+ eval "${cmd}" && return 0
done
done
case "$dev" in
UUID=*)
+ # shellcheck disable=SC2016
dev="$(foreach_uuid_until '! blkid -U $___' "${dev#UUID=}")" \
&& return 255
[ -z "$dev" ] && return 255
_exe=$1
shift
- [ -x "$_exe" ] || _exe=$(command -v $_exe)
+ [ -x "$_exe" ] || _exe=$(command -v "$_exe")
if [ -n "$onetime" ]; then
{
+ # shellcheck disable=SC2016
echo '[ -e "$_job" ] && rm -f -- "$_job"'
echo "$_exe $*"
} > "/tmp/$$-${_job}.sh"
# which executes <script> as soon as <mountpoint> is mounted.
inst_mount_hook() {
local _prio="$2" _jobname="$3" _script="$4"
- local _hookname="mount-$(str_replace "$1" '/' '\\x2f')"
+ local _hookname
+ _hookname="mount-$(str_replace "$1" '/' '\\x2f')"
[ -d "$hookdir/${_hookname}" ] || mkdir -p "$hookdir/${_hookname}"
inst_hook --hook "$_hookname" --unique --name "${_prio}-${_jobname}" "$_script"
}
-# add_mount_point <dev> <mountpoint> <filesystem> <fsopts>
-#
-# Mount <dev> on <mountpoint> with <filesystem> and <fsopts>
-# and call any mount hooks, as soon, as it is mounted
-add_mount_point() {
- local _dev="$1" _mp="$2" _fs="$3" _fsopts="$4"
- local _hookname="mount-$(str_replace "$2" '/' '\\x2f')"
- local _devname="dev-$(str_replace "$1" '/' '\\x2f')"
- echo "$_dev $_mp $_fs $_fsopts 0 0" >> /etc/fstab
-
- exec 7> /etc/udev/rules.d/99-mount-${_devname}.rules
- echo 'SUBSYSTEM!="block", GOTO="mount_end"' >&7
- echo 'ACTION!="add|change", GOTO="mount_end"' >&7
- if [ -n "$_dev" ]; then
- udevmatch "$_dev" >&7 || {
- warn "add_mount_point dev=$_dev incorrect!"
- return 1
- }
- printf ', ' >&7
- fi
-
- {
- printf -- 'RUN+="%s --unique --onetime ' $(command -v initqueue)
- printf -- '--name mount-%%k '
- printf -- '%s %s"\n' "$(command -v mount_hook)" "${_mp}"
- } >&7
- echo 'LABEL="mount_end"' >&7
- exec 7>&-
-}
-
# wait_for_mount <mountpoint>
#
# Installs a initqueue-finished script,
wait_for_mount() {
local _name
_name="$(str_replace "$1" '/' '\\x2f')"
- printf '. /lib/dracut-lib.sh\nismounted "%s"\n' $1 \
+ printf '. /lib/dracut-lib.sh\nismounted "%s"\n' "$1" \
>> "$hookdir/initqueue/finished/ismounted-${_name}.sh"
{
- printf 'ismounted "%s" || ' $1
- printf 'warn "\"%s\" is not mounted"\n' $1
+ printf 'ismounted "%s" || ' "$1"
+ printf 'warn "\"%s\" is not mounted"\n' "$1"
} >> "$hookdir/emergency/90-${_name}.sh"
}
dev="${1%%/}"
dev="${dev##/}"
+ # shellcheck disable=SC1003
dev="$(str_replace "$dev" '\' '\x5c')"
dev="$(str_replace "$dev" '-' '\x2d')"
if [ "${dev##.}" != "$dev" ]; then
if [ -n "$DRACUT_SYSTEMD" ]; then
_name=$(dev_unit_name "$1")
- if ! [ -L ${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device ]; then
- [ -d ${PREFIX}/etc/systemd/system/initrd.target.wants ] || mkdir -p ${PREFIX}/etc/systemd/system/initrd.target.wants
- ln -s ../${_name}.device ${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device
- type mark_hostonly > /dev/null 2>&1 && mark_hostonly /etc/systemd/system/initrd.target.wants/${_name}.device
+ if ! [ -L "${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device" ]; then
+ [ -d "${PREFIX}"/etc/systemd/system/initrd.target.wants ] || mkdir -p "${PREFIX}"/etc/systemd/system/initrd.target.wants
+ ln -s ../"${_name}".device "${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device"
+ type mark_hostonly > /dev/null 2>&1 && mark_hostonly /etc/systemd/system/initrd.target.wants/"${_name}".device
_needreload=1
fi
- if ! [ -f ${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf ]; then
- mkdir -p ${PREFIX}/etc/systemd/system/${_name}.device.d
+ if ! [ -f "${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf" ]; then
+ mkdir -p "${PREFIX}/etc/systemd/system/${_name}.device.d"
{
echo "[Unit]"
echo "JobTimeoutSec=$_timeout"
echo "JobRunningTimeoutSec=$_timeout"
- } > ${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf
- type mark_hostonly > /dev/null 2>&1 && mark_hostonly /etc/systemd/system/${_name}.device.d/timeout.conf
+ } > "${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf"
+ type mark_hostonly > /dev/null 2>&1 && mark_hostonly /etc/systemd/system/"${_name}".device.d/timeout.conf
_needreload=1
fi
printf 'warn "\"%s\" does not exist"\n' "$1"
} >> "${PREFIX}$hookdir/emergency/80-${_name}.sh"
- set_systemd_timeout_for_dev $_noreload $1
+ set_systemd_timeout_for_dev $_noreload "$1"
}
cancel_wait_for_dev() {
rm -f -- "$hookdir/emergency/80-${_name}.sh"
if [ -n "$DRACUT_SYSTEMD" ]; then
_name=$(dev_unit_name "$1")
- rm -f -- ${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device
- rm -f -- ${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf
+ rm -f -- "${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device"
+ rm -f -- "${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf"
/sbin/initqueue --onetime --unique --name daemon-reload systemctl daemon-reload
fi
}
killproc() {
debug_off
- local _exe="$(command -v $1)"
+ local _exe
+ _exe="$(command -v "$1")"
local _sig=$2
local _i
[ -x "$_exe" ] || return 1
for _i in /proc/[0-9]*; do
[ "$_i" = "/proc/1" ] && continue
if [ -e "$_i"/_exe ] && [ "$_i/_exe" -ef "$_exe" ]; then
- kill $_sig ${_i##*/}
+ kill "$_sig" "${_i##*/}"
fi
done
debug_on
}
need_shutdown() {
- > /run/initramfs/.need_shutdown
+ : > /run/initramfs/.need_shutdown
}
wait_for_loginit() {
if [ $i -eq 10 ]; then
kill %1 > /dev/null 2>&1
- kill $(while read line || [ -n "$line" ]; do echo $line; done < /run/initramfs/loginit.pid)
+ kill "$(while read -r line || [ -n "$line" ]; do echo "$line"; done < /run/initramfs/loginit.pid)"
fi
setdebug
[ "${_rl%/$_cmd}" != "$_rl" ] || continue
fi
i=${i%/exe}
- echo ${i##/proc/}
+ echo "${i##/proc/}"
_ret=0
done
debug_on
_emergency_shell() {
local _name="$1"
if [ -n "$DRACUT_SYSTEMD" ]; then
- > /.console_lock
+ : > /.console_lock
echo "PS1=\"$_name:\\\${PWD}# \"" > /etc/profile
systemctl start dracut-emergency.service
rm -f -- /etc/profile
/sbin/rdsosreport
echo 'You might want to save "/run/initramfs/rdsosreport.txt" to a USB stick or /boot'
echo 'after mounting them and attach it to a bug report.'
- if ! RD_DEBUG= getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then
+ if ! RD_DEBUG='' getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then
echo
echo 'To get more debug information in the report,'
echo 'reboot with "rd.debug" added to the kernel command line.'
echo 'Dropping to debug shell.'
echo
export PS1="$_name:\${PWD}# "
- [ -e /.profile ] || > /.profile
+ [ -e /.profile ] || : > /.profile
- _ctty="$(RD_DEBUG= getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
+ _ctty="$(RD_DEBUG='' getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
if [ -z "$_ctty" ]; then
_ctty=console
while [ -f /sys/class/tty/$_ctty/active ]; do
&& _emergency_action=halt
if getargbool 1 rd.shell -d -y rdshell || getarg rd.break -d rdbreak; then
- _emergency_shell $_rdshell_name
+ _emergency_shell "$_rdshell_name"
else
source_hook "$hook"
warn "$action has failed. To debug this issue add \"rd.shell rd.debug\" to the kernel command line."
for var in "$@"; do
eval val=\$$var
unset $var
- [ -n "$val" ] && eval $var=\"$val\"
+ [ -n "$val" ] && eval "$var=\"$val\""
done
}
setmemdebug() {
if [ -z "$DEBUG_MEM_LEVEL" ]; then
- export DEBUG_MEM_LEVEL=$(getargnum 0 0 5 rd.memdebug)
+ DEBUG_MEM_LEVEL=$(getargnum 0 0 5 rd.memdebug)
+ export DEBUG_MEM_LEVEL
fi
}
return
fi
- msg=$(echo $msg)
+ # FIXME? useless echo?
+ # shellcheck disable=SC2116
+ msg=$(echo "$msg")
msg_printed=0
while [ $# -gt 0 ]; do
echo "$prefix $msg"
msg_printed=1
fi
- show_memstats $trace
+ show_memstats "$trace"
fi
shift
done
show_memstats() {
case $1 in
shortmem)
- cat /proc/meminfo | grep -e "^MemFree" -e "^Cached" -e "^Slab"
+ grep -e "^MemFree" -e "^Cached" -e "^Slab" /proc/meminfo
;;
mem)
cat /proc/meminfo
export PATH
# mount some important things
-[ ! -d /proc/self ] \
- && mount -t proc -o nosuid,noexec,nodev proc /proc > /dev/null
-
-if [ "$?" != "0" ]; then
- echo "Cannot mount proc on /proc! Compile the kernel with CONFIG_PROC_FS!"
- exit 1
+if [ ! -d /proc/self ]; then
+ if ! mount -t proc -o nosuid,noexec,nodev proc /proc > /dev/null; then
+ echo "Cannot mount proc on /proc! Compile the kernel with CONFIG_PROC_FS!"
+ exit 1
+ fi
fi
-[ ! -d /sys/kernel ] \
- && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys > /dev/null
-
-if [ "$?" != "0" ]; then
- echo "Cannot mount sysfs on /sys! Compile the kernel with CONFIG_SYSFS!"
- exit 1
+if [ ! -d /sys/kernel ]; then
+ if ! mount -t sysfs -o nosuid,noexec,nodev sysfs /sys > /dev/null; then
+ echo "Cannot mount sysfs on /sys! Compile the kernel with CONFIG_SYSFS!"
+ exit 1
+ fi
fi
RD_DEBUG=""
if command -v kmod > /dev/null 2> /dev/null; then
kmod static-nodes --format=tmpfiles 2> /dev/null \
- | while read type file mode a a a majmin || [ -n "$type" ]; do
+ | while read -r type file mode _ _ _ majmin || [ -n "$type" ]; do
type=${type%\!}
case $type in
d)
- mkdir -m $mode -p $file
+ mkdir -m "$mode" -p "$file"
;;
c)
- mknod -m $mode $file $type ${majmin%:*} ${majmin#*:}
+ mknod -m "$mode" "$file" "$type" "${majmin%:*}" "${majmin#*:}"
;;
esac
done
trap "emergency_shell Signal caught!" 0
-export UDEVVERSION=$(udevadm --version)
-if [ $UDEVVERSION -gt 166 ]; then
- # newer versions of udev use /run/udev/rules.d
- export UDEVRULESD=/run/udev/rules.d
- [ -d /run/udev ] || mkdir -p -m 0755 /run/udev
- [ -d $UDEVRULESD ] || mkdir -p -m 0755 $UDEVRULESD
-else
- mkdir -m 0755 -p /dev/.udev /dev/.udev/rules.d
- export UDEVRULESD=/dev/.udev/rules.d
-fi
+export UDEVRULESD=/run/udev/rules.d
+[ -d /run/udev ] || mkdir -p -m 0755 /run/udev
+[ -d "$UDEVRULESD" ] || mkdir -p -m 0755 "$UDEVRULESD"
if [ "$RD_DEBUG" = "yes" ]; then
mkfifo /run/initramfs/loginit.pipe
- loginit $DRACUT_QUIET < /run/initramfs/loginit.pipe > /dev/console 2>&1 &
+ loginit "$DRACUT_QUIET" < /run/initramfs/loginit.pipe > /dev/console 2>&1 &
exec > /run/initramfs/loginit.pipe 2>&1
else
exec 0<> /dev/console 1<> /dev/console 2<> /dev/console
if getarg "rd.cmdline=ask"; then
echo "Enter additional kernel command line parameter (end with ctrl-d or .)"
- while read -p "> " line || [ -n "$line" ]; do
+ while read -r -p "> " line || [ -n "$line" ]; do
[ "$line" = "." ] && break
echo "$line" >> /etc/cmdline.d/99-cmdline-ask.conf
done
getargbool 0 rd.udev.debug -d -y rdudevdebug && UDEV_LOG=debug
# start up udev and trigger cold plugs
-UDEV_LOG=$UDEV_LOG $systemdutildir/systemd-udevd --daemon --resolve-names=never
+UDEV_LOG=$UDEV_LOG "$systemdutildir"/systemd-udevd --daemon --resolve-names=never
UDEV_QUEUE_EMPTY="udevadm settle --timeout=0"
-if [ $UDEVVERSION -lt 140 ]; then
- UDEV_QUEUE_EMPTY="udevadm settle --timeout=1"
-fi
-
udevproperty "hookdir=$hookdir"
make_trace_mem "hook pre-trigger" '1:shortmem' '2+:mem' '3+:slab'
check_finished && break
- if [ -f $hookdir/initqueue/work ]; then
- rm -f -- $hookdir/initqueue/work
+ if [ -f "$hookdir"/initqueue/work ]; then
+ rm -f -- "$hookdir"/initqueue/work
fi
- for job in $hookdir/initqueue/*.sh; do
+ for job in "$hookdir"/initqueue/*.sh; do
[ -e "$job" ] || break
- job=$job . $job
+ # shellcheck disable=SC2097 disable=SC1090 disable=SC2098
+ job=$job . "$job"
check_finished && break 2
done
$UDEV_QUEUE_EMPTY > /dev/null 2>&1 || continue
- for job in $hookdir/initqueue/settled/*.sh; do
+ for job in "$hookdir"/initqueue/settled/*.sh; do
[ -e "$job" ] || break
- job=$job . $job
+ # shellcheck disable=SC2097 disable=SC1090 disable=SC2098
+ job=$job . "$job"
check_finished && break 2
done
sleep 0.5
if [ $main_loop -gt $((2 * RDRETRY / 3)) ]; then
- for job in $hookdir/initqueue/timeout/*.sh; do
+ for job in "$hookdir"/initqueue/timeout/*.sh; do
[ -e "$job" ] || break
- job=$job . $job
+ # shellcheck disable=SC2097 disable=SC1090 disable=SC2098
+ job=$job . "$job"
udevadm settle --timeout=0 > /dev/null 2>&1 || main_loop=0
- [ -f $hookdir/initqueue/work ] && main_loop=0
+ [ -f "$hookdir"/initqueue/work ] && main_loop=0
done
fi
usable_root "$NEWROOT" && break
umount "$NEWROOT"
fi
- for f in $hookdir/mount/*.sh; do
+ for f in "$hookdir"/mount/*.sh; do
+ # shellcheck disable=SC1090
[ -f "$f" ] && . "$f"
if ismounted "$NEWROOT"; then
usable_root "$NEWROOT" && break
{
printf "Mounted root filesystem "
- while read dev mp rest || [ -n "$dev" ]; do [ "$mp" = "$NEWROOT" ] && echo $dev; done < /proc/mounts
+ while read -r dev mp _ || [ -n "$dev" ]; do [ "$mp" = "$NEWROOT" ] && echo "$dev"; done < /proc/mounts
} | vinfo
# pre pivot scripts are sourced just before we doing cleanup and switch over
emergency_shell
}
-if [ $UDEVVERSION -lt 168 ]; then
- # stop udev queue before killing it
- udevadm control --stop-exec-queue
-
- HARD=""
- while pidof udevd > /dev/null 2>&1; do
- for pid in $(pidof udevd); do
- kill $HARD $pid > /dev/null 2>&1
- done
- HARD="-9"
- done
-else
- udevadm control --exit
- udevadm info --cleanup-db
-fi
+udevadm control --exit
+udevadm info --cleanup-db
debug_off # Turn off debugging for this section
rm -f -- /tmp/export.orig
initargs=""
-read CLINE < /proc/cmdline
+read -r CLINE < /proc/cmdline
if getarg init= > /dev/null; then
ignoreargs="console BOOT_IMAGE"
# only pass arguments after init= to the init
CLINE=${CLINE#*init=}
- set -- $CLINE
+ set -- "$CLINE"
shift # clear out the rest of the "init=" arg
for x in "$@"; do
for s in $ignoreargs; do
- [ "${x%%=*}" = $s ] && continue 2
+ [ "${x%%=*}" = "$s" ] && continue 2
done
initargs="$initargs $x"
done
unset CLINE
else
debug_off # Turn off debugging for this section
- set -- $CLINE
+ set -- "$CLINE"
for x in "$@"; do
case "$x" in
[0-9] | s | S | single | emergency | auto)
. /etc/capsdrop
info "Calling $INIT with capabilities $CAPS_INIT_DROP dropped."
unset RD_DEBUG
- exec $CAPSH --drop="$CAPS_INIT_DROP" -- \
+ exec "$CAPSH" --drop="$CAPS_INIT_DROP" -- \
-c "exec switch_root \"$NEWROOT\" \"$INIT\" $initargs" \
|| {
warn "Command:"
- warn capsh --drop=$CAPS_INIT_DROP -- -c exec switch_root "$NEWROOT" "$INIT" $initargs
+ warn capsh --drop="$CAPS_INIT_DROP" -- -c exec switch_root "$NEWROOT" "$INIT" "$initargs"
warn "failed."
emergency_shell
}
else
unset RD_DEBUG
- exec $SWITCH_ROOT "$NEWROOT" "$INIT" $initargs || {
+ exec "$SWITCH_ROOT" "$NEWROOT" "$INIT" "$initargs" || {
warn "Something went very badly wrong in the initramfs. Please "
warn "file a bug against dracut."
emergency_shell
install() {
inst_multiple mount mknod mkdir sleep chroot chown \
sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid \
- modprobe
+ modprobe chmod
inst_multiple -o findmnt less kmod dracut-getargs
if ! dracut_module_included "systemd"; then
inst_multiple switch_root || dfatal "Failed to install switch_root"
inst_hook cmdline 10 "$moddir/parse-root-opts.sh"
- inst_multiple -o $systemdutildir/systemd-timestamp
+ inst_multiple -o "$systemdutildir"/systemd-timestamp
fi
if [[ $realinitpath ]]; then
echo ro >> "${initdir}/etc/cmdline.d/base.conf"
fi
- [ -e "${initdir}/usr/lib" ] || mkdir -m 0755 -p ${initdir}/usr/lib
+ [ -e "${initdir}/usr/lib" ] || mkdir -m 0755 -p "${initdir}"/usr/lib
local VERSION=""
local PRETTY_NAME=""
# Derive an os-release file from the host, if it exists
if [[ -e $dracutsysrootdir/etc/os-release ]]; then
+ # shellcheck disable=SC1090
. "$dracutsysrootdir"/etc/os-release
grep -hE -ve '^VERSION=' -ve '^PRETTY_NAME' "$dracutsysrootdir"/etc/os-release > "${initdir}"/usr/lib/initrd-release
[[ -n ${VERSION} ]] && VERSION+=" "
# Fall back to synthesizing one, since dracut is presently used
# on non-systemd systems as well.
{
- echo NAME=dracut
- echo ID=dracut
- echo VERSION_ID=\"$DRACUT_VERSION\"
- echo ANSI_COLOR='"0;34"'
- } > ${initdir}/usr/lib/initrd-release
+ echo "NAME=dracut"
+ echo "ID=dracut"
+ echo "VERSION_ID=\"$DRACUT_VERSION\""
+ echo 'ANSI_COLOR="0;34"'
+ } > "${initdir}"/usr/lib/initrd-release
fi
VERSION+="dracut-$DRACUT_VERSION"
PRETTY_NAME+="dracut-$DRACUT_VERSION (Initramfs)"
{
- echo VERSION=\"$VERSION\"
- echo PRETTY_NAME=\"$PRETTY_NAME\"
+ echo "VERSION=\"$VERSION\""
+ echo "PRETTY_NAME=\"$PRETTY_NAME\""
# This addition is relatively new, intended to allow software
# to easily detect the dracut version if need be without
# having it mixed in with the real underlying OS version.
- echo DRACUT_VERSION=\"${DRACUT_VERSION}\"
+ echo "DRACUT_VERSION=\"${DRACUT_VERSION}\""
} >> "$initdir"/usr/lib/initrd-release
echo "dracut-$DRACUT_VERSION" > "$initdir/lib/dracut/dracut-$DRACUT_VERSION"
- ln -sf ../usr/lib/initrd-release $initdir/etc/initrd-release
- ln -sf initrd-release $initdir/usr/lib/os-release
- ln -sf initrd-release $initdir/etc/os-release
+ ln -sf ../usr/lib/initrd-release "$initdir"/etc/initrd-release
+ ln -sf initrd-release "$initdir"/usr/lib/os-release
+ ln -sf initrd-release "$initdir"/etc/os-release
## save host_devs which we need bring up
if [[ $hostonly_cmdline == "yes" ]]; then
if [[ -f $initdir/lib/dracut/need-initqueue ]] || ! dracut_module_included "systemd"; then
(
if dracut_module_included "systemd"; then
- DRACUT_SYSTEMD=1
+ export DRACUT_SYSTEMD=1
fi
- PREFIX="$initdir"
+ export PREFIX="$initdir"
+ # shellcheck source=dracut-lib.sh
. "$moddir/dracut-lib.sh"
for _dev in "${host_devs[@]}"; do
[[ $_dev == "$_dev2" ]] && continue 2
done
- _pdev=$(get_persistent_dev $_dev)
+ _pdev=$(get_persistent_dev "$_dev")
case "$_pdev" in
- /dev/?*) wait_for_dev $_pdev ;;
+ /dev/?*) wait_for_dev "$_pdev" ;;
*) ;;
esac
done