fix(base): shellcheck for modules.d/99base

Also remove some functions, which are not used and broken anyway.
master
Harald Hoyer 2021-03-22 10:13:19 +01:00 committed by Harald Hoyer
parent cbef7cf3da
commit 2fabaaa62d
8 changed files with 206 additions and 219 deletions

View File

View File

@ -3,9 +3,10 @@
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
@ -71,8 +72,9 @@ if [ -z "$DRACUT_SYSTEMD" ]; then
info() {
check_quiet
echo "<30>dracut: $*" > /dev/kmsg
[ "$DRACUT_QUIET" != "yes" ] \
&& echo "dracut: $*" >&2 || :
if [ "$DRACUT_QUIET" != "yes" ]; then
echo "dracut: $*" >&2
fi
}

else
@ -88,14 +90,14 @@ 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
}

@ -121,7 +123,6 @@ str_replace() {

killall_proc_mountpoint() {
local _pid
local _t
local _killed=0
for _pid in /proc/*; do
_pid=${_pid##/proc/}
@ -180,7 +181,11 @@ getarg() {
-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
@ -193,7 +198,11 @@ getarg() {
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
@ -207,7 +216,11 @@ getarg() {
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
@ -234,12 +247,11 @@ getargbool() {
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
}
@ -267,44 +279,44 @@ getargnum() {
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
@ -394,7 +406,19 @@ source_all() {
_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
@ -409,8 +433,9 @@ source_hook() {

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
@ -419,6 +444,7 @@ check_finished() {
source_conf() {
local f
[ "$1" ] && [ -d "/$1" ] || return
# shellcheck disable=SC1090
for f in "/$1"/*.conf; do [ -e "$f" ] && . "$f"; done
}

@ -434,7 +460,7 @@ die() {
} >> $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
@ -456,7 +482,7 @@ check_quiet() {
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
}
@ -474,52 +500,43 @@ check_occurances() {
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
@ -538,7 +555,7 @@ else
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
@ -644,10 +661,11 @@ mkuniqdir() {
# 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"
)
}
@ -671,7 +689,7 @@ copytree() {
# 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"
@ -684,10 +702,11 @@ foreach_uuid_until() (
[ -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

@ -715,6 +734,7 @@ devnames() {

case "$dev" in
UUID=*)
# shellcheck disable=SC2016
dev="$(foreach_uuid_until '! blkid -U $___' "${dev#UUID=}")" \
&& return 255
[ -z "$dev" ] && return 255
@ -781,10 +801,11 @@ inst_hook() {
_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"
@ -801,41 +822,12 @@ inst_hook() {
# 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,
@ -844,11 +836,11 @@ add_mount_point() {
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"
}

@ -869,6 +861,7 @@ dev_unit_name() {

dev="${1%%/}"
dev="${dev##/}"
# shellcheck disable=SC1003
dev="$(str_replace "$dev" '\' '\x5c')"
dev="$(str_replace "$dev" '-' '\x2d')"
if [ "${dev##.}" != "$dev" ]; then
@ -898,21 +891,21 @@ set_systemd_timeout_for_dev() {

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

@ -948,7 +941,7 @@ wait_for_dev() {
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() {
@ -958,29 +951,30 @@ 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() {
@ -1003,7 +997,7 @@ 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
@ -1034,7 +1028,7 @@ if ! command -v pidof > /dev/null 2> /dev/null; then
[ "${_rl%/$_cmd}" != "$_rl" ] || continue
fi
i=${i%/exe}
echo ${i##/proc/}
echo "${i##/proc/}"
_ret=0
done
debug_on
@ -1045,7 +1039,7 @@ fi
_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
@ -1057,7 +1051,7 @@ _emergency_shell() {
/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.'
@ -1066,9 +1060,9 @@ _emergency_shell() {
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
@ -1115,7 +1109,7 @@ emergency_shell() {
&& _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."
@ -1143,7 +1137,7 @@ export_n() {
for var in "$@"; do
eval val=\$$var
unset $var
[ -n "$val" ] && eval $var=\"$val\"
[ -n "$val" ] && eval "$var=\"$val\""
done
}

@ -1186,7 +1180,8 @@ are_lists_eq() {

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
}

@ -1207,7 +1202,9 @@ make_trace_mem() {
return
fi

msg=$(echo $msg)
# FIXME? useless echo?
# shellcheck disable=SC2116
msg=$(echo "$msg")

msg_printed=0
while [ $# -gt 0 ]; do
@ -1236,7 +1233,7 @@ make_trace_mem() {
echo "$prefix $msg"
msg_printed=1
fi
show_memstats $trace
show_memstats "$trace"
fi
shift
done
@ -1246,7 +1243,7 @@ make_trace_mem() {
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

View File

@ -16,20 +16,18 @@ PATH=/usr/sbin:/usr/bin:/sbin:/bin
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=""
@ -77,14 +75,14 @@ fi

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
@ -92,20 +90,13 @@ fi

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
@ -118,7 +109,7 @@ source_conf /etc/conf.d

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
@ -150,14 +141,10 @@ getargbool 0 rd.udev.info -d -y rdudevinfo && UDEV_LOG=info
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'
@ -186,21 +173,23 @@ while :; do

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

@ -210,11 +199,12 @@ while :; do
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

@ -245,7 +235,8 @@ while :; do
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
@ -265,7 +256,7 @@ done

{
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
@ -303,21 +294,8 @@ done
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

@ -345,23 +323,23 @@ done
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)
@ -399,17 +377,17 @@ if [ -f /etc/capsdrop ]; then
. /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

View File

@ -54,18 +54,19 @@ fi
exe=$1
shift

[ -x "$exe" ] || exe=$(command -v $exe)
[ -x "$exe" ] || exe=$(command -v "$exe")
if [ -z "$exe" ]; then
echo "Invalid command"
exit 1
fi

{
# shellcheck disable=SC2016
[ -n "$onetime" ] && echo '[ -e "$job" ] && rm -f -- "$job"'
[ -n "$env" ] && echo "$env"
echo "$exe" "$@"
} > "/tmp/$$-${job}.sh"

mv -f "/tmp/$$-${job}.sh" "$hookdir/initqueue${qname}/${job}.sh"
[ -z "$qname" ] && >> $hookdir/initqueue/work
[ -z "$qname" ] && : >> "$hookdir"/initqueue/work
exit 0

View File

@ -5,12 +5,13 @@ set +x

QUIET=$1

printf -- "$$" > /run/initramfs/loginit.pid
printf "%s" "$$" > /run/initramfs/loginit.pid

# shellcheck disable=SC2015
[ -e /dev/kmsg ] && exec 5> /dev/kmsg || exec 5> /dev/null
exec 6> /run/initramfs/init.log

while read line || [ -n "$line" ]; do
while read -r line || [ -n "$line" ]; do
if [ "$line" = "DRACUT_LOG_END" ]; then
rm -f -- /run/initramfs/loginit.pipe
exit 0

View File

@ -15,7 +15,7 @@ depends() {
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

@ -55,7 +55,7 @@ install() {
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
@ -69,12 +69,13 @@ install() {
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+=" "
@ -83,26 +84,26 @@ install() {
# 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
@ -112,10 +113,11 @@ install() {
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
@ -130,10 +132,10 @@ install() {
[[ $_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

View File

@ -1,5 +1,6 @@
#!/bin/sh

# shellcheck disable=SC2034
root=$(getarg root=)

rflags="$(getarg rootflags=)"

View File

@ -10,14 +10,18 @@ PWFILTER='s/\(ftp:\/\/.*\):.*@/\1:*******@/g;s/\(cifs:\/\/.*\):.*@/\1:*******@/g
set -x
cat /lib/dracut/dracut-*

cat /proc/cmdline | sed -e "$PWFILTER"
echo "/proc/cmdline"
sed -e "$PWFILTER" /proc/cmdline

[ -f /etc/cmdline ] && cat /etc/cmdline | sed -e "$PWFILTER"
if [ -f /etc/cmdline ]; then
echo "/etc/cmdline"
sed -e "$PWFILTER" /etc/cmdline
fi

for _i in /etc/cmdline.d/*.conf; do
[ -f "$_i" ] || break
echo $_i
cat $_i | sed -e "$PWFILTER"
echo "$_i"
sed -e "$PWFILTER" "$_i"
done

cat /proc/self/mountinfo
@ -30,8 +34,8 @@ ls -l /dev/disk/by*

for _i in /etc/conf.d/*.conf; do
[ -f "$_i" ] || break
echo $_i
cat $_i | sed -e "$PWFILTER"
echo "$_i"
sed -e "$PWFILTER" "$_i"
done

if command -v lvm > /dev/null 2> /dev/null; then
@ -50,5 +54,8 @@ if command -v journalctl > /dev/null 2> /dev/null; then
journalctl -ab --no-pager -o short-monotonic | sed -e "$PWFILTER"
else
dmesg | sed -e "$PWFILTER"
[ -f /run/initramfs/init.log ] && cat /run/initramfs/init.log | sed -e "$PWFILTER"
if [ -f /run/initramfs/init.log ]; then
echo "/run/initramfs/init.log"
sed -e "$PWFILTER" /run/initramfs/init.log
fi
fi