From 1567e3b5e6dbfe6219d2e04edaf5c51f0173cc0b Mon Sep 17 00:00:00 2001
From: Recolic Keghart <root@recolic.net>
Date: Tue, 12 Oct 2021 01:15:34 +0800
Subject: [PATCH] update

---
 aur/PKGBUILD                               |  2 +-
 src/shared-bootdir-helper-multi-kparam.cfg | 10 ++++------
 src/shared-bootdir-helper-multi-kparam.sh  | 11 +++++------
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/aur/PKGBUILD b/aur/PKGBUILD
index 33a185e..c3b1446 100644
--- a/aur/PKGBUILD
+++ b/aur/PKGBUILD
@@ -3,7 +3,7 @@
 # Mirror: https://github.com/recolic/shared-bootdir-helper
 
 pkgname=shared-bootdir-helper
-pkgver=1.0
+pkgver=1.1
 pkgrel=1
 pkgdesc="Allow multiple linux installations to share the same /boot directory, even with different kernel parameters. "
 url="https://git.recolic.net/root/$pkgname"
diff --git a/src/shared-bootdir-helper-multi-kparam.cfg b/src/shared-bootdir-helper-multi-kparam.cfg
index 569fc1d..3573e20 100644
--- a/src/shared-bootdir-helper-multi-kparam.cfg
+++ b/src/shared-bootdir-helper-multi-kparam.cfg
@@ -1,14 +1,12 @@
 
-# You use this placeholder in GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub
-placeholder="__KERNEL_PARAMETER_MANAGED_BY_HELPER"
-
 # mapping between hostname and kernel parameters. 
 declare -A map_hostname_to_kparam=(
     # Parameters can not contain `|` character, which will crash this naive script. 
     # hostname MUST be in lowercase, because `hook-kernel-rename.sh` converts hostname to lowercase. 
+    # kernel parameters MUST at least contain `root=xxx rw` to make kernel working. 
     # This is some examples: 
-    ["recolicpc"]="quiet amdgpu.ppfeaturemask=0xffffffff cryptdevice=/dev/disk/by-id/nvme-SAMSUNG_MZVLW256HEHP-xxxxxxxxxxxx:cryptlvm:allow-discards cryptkey=/dev/disk/by-partlabel/xxxxxxxx:0:64 crypto=:aes-xts-plain64:512:0:"
-    ["recolicmpc"]="quiet cryptdevice=/dev/disk/by-id/ata-SAMSUNG_MZNTY128HDHP-000xxxxxxxxxx:cryptlvm:allow-discards cryptkey=/dev/disk/by-partlabel/xxxxxxx:0:64 crypto=:aes-xts-plain64:512:0: resume=/dev/RecolicmpcVolGroup/swap"
-    ["recolicmsmpc"]="quiet cryptdevice=/dev/disk/by-id/xxxxxxxxxxxxxxxxxx:cryptlvm cryptkey=/dev/disk/by-partlabel/xxxxxxxx:0:64 crypto=xxxxxxxxxxxxxxxxxxxxxx"
+    ["recolicpc"]="root=/dev/mapper/RecolicpcVolGroup-root rw quiet amdgpu.ppfeaturemask=0xffffffff cryptdevice=/dev/disk/by-id/nvme-SAMSUNG_MZVLW256HEHP-xxxxxxxxxxxx:cryptlvm:allow-discards cryptkey=/dev/disk/by-partlabel/xxxxxxxx:0:64 crypto=:aes-xts-plain64:512:0:"
+    ["recolicmpc"]="root=/dev/mapper/RecolicmpcVolGroup-root rw quiet cryptdevice=/dev/disk/by-id/ata-SAMSUNG_MZNTY128HDHP-000xxxxxxxxxx:cryptlvm:allow-discards cryptkey=/dev/disk/by-partlabel/xxxxxxx:0:64 crypto=:aes-xts-plain64:512:0: resume=/dev/RecolicmpcVolGroup/swap"
+    ["recolicmsmpc"]="root=/dev/mapper/RecolicmsmpcVolGroup-root rw quiet cryptdevice=/dev/disk/by-id/xxxxxxxxxxxxxxxxxx:cryptlvm cryptkey=/dev/disk/by-partlabel/xxxxxxxx:0:64 crypto=xxxxxxxxxxxxxxxxxxxxxx"
 )
 
diff --git a/src/shared-bootdir-helper-multi-kparam.sh b/src/shared-bootdir-helper-multi-kparam.sh
index 1f3f8f6..dc69ac7 100755
--- a/src/shared-bootdir-helper-multi-kparam.sh
+++ b/src/shared-bootdir-helper-multi-kparam.sh
@@ -10,6 +10,8 @@
 #   to correct kernel parameters. 
 #
 # Usage: ./this.sh /boot/grub/grub.cfg
+#
+# Note that grub.cfg must be auto-generated, to make its format correct. 
 
 source "/etc/shared-bootdir-helper-multi-kparam.cfg" || exit 1
 
@@ -20,23 +22,20 @@ inputfile="$1"
 
 while IFS= read -r line; do
     matched=0
-    if [[ "$line" == *"$placeholder"* ]]; then
+    if [[ "$line" == *"\tlinux\t/"* ]]; then
         for hostname in "${!map_hostname_to_kparam[@]}"; do
             # Assuming that, the kimg filename contains "vmlinuz-xxx-$hostname ", in lowercase. That's important! 
             [[ "$line" == *"-$hostname "* ]] &&
-                echo "$line" | sed "s|$placeholder|${map_kimage_to_kparam[$hostname]}|g" >> "$tmpfile" &&
+                echo "$line" | sed "s|-$hostname .*$|-$hostname ${map_kimage_to_kparam[$hostname]}|g" >> "$tmpfile" &&
                 matched=1 && 
                 break
         done
+        [[ $matched == 0 ]] && echo "Warning: kernel line '$line' doesnt match ANY entry in /etc/shared-bootdir-helper-multi-kparam.cfg" && exit 2
     fi
     [[ $matched == 0 ]] && echo "$line" >> "$tmpfile"
 done < "$inputfile" || exit $?
 
 mv "$tmpfile" "$inputfile" || exit $?
 
-grep "$placeholder" "$inputfile" &&
-    echo "Warning: placeholder '$placeholder' still exists in processed grub.cfg. Have you correctly set the 'map_kimage_to_kparam' of $0? Please double-check! " &&
-    exit 2
-
 exit 0
 
-- 
GitLab