]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(zipl): remove trailing spaces from zipl boot device name
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Mon, 14 Nov 2022 15:45:48 +0000 (16:45 +0100)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Wed, 21 Dec 2022 17:16:47 +0000 (17:16 +0000)
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.

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

index 6ab31aa87182c52a1c7f0216b7592b6131933e85..280e4e782373d94bf81d01b32ef20becbd2d9089 100755 (executable)
@@ -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() {
index 8b3c5d2d78542dade212faf999a2d509d145db94..cb21454f238bdbfcad0675ab83d22a2710f10ca1 100755 (executable)
@@ -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)}
@@ -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
@@ -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
 }