Skip to content

Commit b4de9ee

Browse files
aafeijoo-susejohannbg
authored andcommitted
fix(zipl): remove trailing spaces from zipl boot device name
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.
1 parent e877be6 commit b4de9ee

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

dracut-functions.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ str_starts() { [ "${1#"$2"*}" != "$1" ]; }
3737
# returns OK if $1 contains literal string $2 at the end, and isn't empty
3838
str_ends() { [ "${1%*"$2"}" != "$1" ]; }
3939

40+
trim() {
41+
local var="$*"
42+
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
43+
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
44+
printf "%s" "$var"
45+
}
46+
4047
# find a binary. If we were not passed the full path directly,
4148
# search in the usual places to find the binary.
4249
find_binary() {

modules.d/91zipl/module-setup.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
33
# ex: ts=8 sw=4 sts=4 et filetype=sh
44

5+
get_boot_zipl_dev() {
6+
local _boot_zipl
7+
_boot_zipl=$(sed -n -e '/^[[:space:]]*#/d' -e 's/\(.*\)\w*\/boot\/zipl.*/\1/p' "$dracutsysrootdir"/etc/fstab)
8+
printf "%s" "$(trim "$_boot_zipl")"
9+
}
10+
511
# called by dracut
612
check() {
713
local _arch=${DRACUT_ARCH:-$(uname -m)}
@@ -21,7 +27,7 @@ depends() {
2127
installkernel() {
2228
local _boot_zipl
2329

24-
_boot_zipl=$(sed -n -e '/^[[:space:]]*#/d' -e 's/\(.*\)\w*\/boot\/zipl.*/\1/p' /etc/fstab)
30+
_boot_zipl=$(get_boot_zipl_dev)
2531
if [ -n "$_boot_zipl" ]; then
2632
eval "$(blkid -s TYPE -o udev "${_boot_zipl}")"
2733
if [ -n "$ID_FS_TYPE" ]; then
@@ -39,9 +45,9 @@ installkernel() {
3945
cmdline() {
4046
local _boot_zipl
4147

42-
_boot_zipl=$(sed -n -e '/^[[:space:]]*#/d' -e 's/\(.*\)\w*\/boot\/zipl.*/\1/p' /etc/fstab)
48+
_boot_zipl=$(get_boot_zipl_dev)
4349
if [ -n "$_boot_zipl" ]; then
44-
echo "rd.zipl=${_boot_zipl}"
50+
printf "%s" " rd.zipl=${_boot_zipl}"
4551
fi
4652
}
4753

0 commit comments

Comments
 (0)