Skip to content

Commit

Permalink
fix(zipl): remove trailing spaces from zipl boot device name
Browse files Browse the repository at this point in the history
Trailing spaces are misleading blkid input after fixes for shellcheck were
introduced in 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.
  • Loading branch information
aafeijoo-suse authored and johannbg committed Dec 21, 2022
1 parent e877be6 commit b4de9ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions dracut-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ str_starts() { [ "${1#"$2"*}" != "$1" ]; }
# 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() {
Expand Down
12 changes: 9 additions & 3 deletions modules.d/91zipl/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# -*- 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)}
Expand All @@ -21,7 +27,7 @@ depends() {
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
Expand All @@ -39,9 +45,9 @@ installkernel() {
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
}

Expand Down

0 comments on commit b4de9ee

Please sign in to comment.