Trailing spaces are misleading blkid input after fixes for shellcheck were
introduced in https://github.com/dracutdevs/dracut/commit/
d75b029a
Test showing the wrong output:
```
localhost:~ # _boot_zipl=$(sed -n -e '/^[[:space:]]*#/d' -e 's/\(.*\)\w*\/boot\/zipl.*/\1/p' /etc/fstab)
localhost:~ # echo "[${_boot_zipl}]"
[/dev/disk/by-path/ccw-0.0.0000-part1 ]
localhost:~ # blkid -s TYPE -o udev "${_boot_zipl}"
localhost:~ # blkid -s TYPE -o udev ${_boot_zipl}
ID_FS_TYPE=ext2
```
Also, remove duplicate code by creating a function to get the zipl boot device,
prepend $dracutsysrootdir to /etc/fstab and print cmdline properly: start
with a space and do not print a newline.
# returns OK if $1 contains literal string $2 at the end, and isn't empty
str_ends() { [ "${1%*"$2"}" != "$1" ]; }
+trim() {
+ local var="$*"
+ var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
+ var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
+ printf "%s" "$var"
+}
+
# find a binary. If we were not passed the full path directly,
# search in the usual places to find the binary.
find_binary() {
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+get_boot_zipl_dev() {
+ local _boot_zipl
+ _boot_zipl=$(sed -n -e '/^[[:space:]]*#/d' -e 's/\(.*\)\w*\/boot\/zipl.*/\1/p' "$dracutsysrootdir"/etc/fstab)
+ printf "%s" "$(trim "$_boot_zipl")"
+}
+
# called by dracut
check() {
local _arch=${DRACUT_ARCH:-$(uname -m)}
installkernel() {
local _boot_zipl
- _boot_zipl=$(sed -n -e '/^[[:space:]]*#/d' -e 's/\(.*\)\w*\/boot\/zipl.*/\1/p' /etc/fstab)
+ _boot_zipl=$(get_boot_zipl_dev)
if [ -n "$_boot_zipl" ]; then
eval "$(blkid -s TYPE -o udev "${_boot_zipl}")"
if [ -n "$ID_FS_TYPE" ]; then
cmdline() {
local _boot_zipl
- _boot_zipl=$(sed -n -e '/^[[:space:]]*#/d' -e 's/\(.*\)\w*\/boot\/zipl.*/\1/p' /etc/fstab)
+ _boot_zipl=$(get_boot_zipl_dev)
if [ -n "$_boot_zipl" ]; then
- echo "rd.zipl=${_boot_zipl}"
+ printf "%s" " rd.zipl=${_boot_zipl}"
fi
}