From 32e5fdbde5ff902b7a5ff42b5008c73c3aa5df75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= Date: Thu, 12 Dec 2024 11:09:28 +0100 Subject: [PATCH] Improve regular expressions This change will ensure that the first `sed` command that removes the `kargs` key completely will also remove the following `match-architectures` key if the key exists. Also, the second `sed` command that just removes an item from the list if the list contains multiple items has been adjusted to correctly remove commans between the items. Credit to Matus Marhefka :+1: --- .../templates/grub2_bootloader_argument_absent/bash.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/templates/grub2_bootloader_argument_absent/bash.template b/shared/templates/grub2_bootloader_argument_absent/bash.template index ca95bdea81b..bf3a443bf48 100644 --- a/shared/templates/grub2_bootloader_argument_absent/bash.template +++ b/shared/templates/grub2_bootloader_argument_absent/bash.template @@ -4,8 +4,8 @@ Product-specific categorization should be synced across all template content types -#}} if {{{ bash_bootc_build() }}} ; then - sed -i -E "/kargs\s*=\s*\[\s*\"{{{ ARG_NAME }}}=[^\"]*\"\s*]/d" "$KARGS_DIR/*.toml" - sed -i -E "s/^(\s*kargs\s*=\s*\[.*)\"{{{ ARG_NAME }}}=[^\"]*\"(.*]\s*)/\1\2/" "$KARGS_DIR/*.toml" + sed -i -E "/kargs\s*=\s*\[\s*\"{{{ ARG_NAME }}}=[^\"]*\"\s*]/{:a;N;/^\n$/ba;N;/match-architectures.*/d;}" "$KARGS_DIR/*.toml" + sed -i -E -e "s/^(\s*kargs\s*=\s*\[.*)\"{{{ ARG_NAME }}}=[^\"]*\"[,[:space:]]*(.*]\s*)/\1\2/" -e "s/^(\s*kargs.*),\s*\]$/\1\]/" "$KARGS_DIR/*.toml" else {{{ grub2_bootloader_argument_absent_remediation(ARG_NAME) }}} fi