From 4d4e7cc5e92529482c33ed91bb074a2222cad458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 3 Jun 2016 20:51:18 +0200 Subject: [PATCH] kernel-install: do not add kernel entry if already present The entry may be already present for example when reinstalling package, or calling the script multiple times (which apparently is the case during system installation). --- system-config/kernel-xen-efi.install | 76 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/system-config/kernel-xen-efi.install b/system-config/kernel-xen-efi.install index da2afd9..02773ac 100755 --- a/system-config/kernel-xen-efi.install +++ b/system-config/kernel-xen-efi.install @@ -15,48 +15,50 @@ fi case "$COMMAND" in add) - # take the default section and use it as a template for the new entry - awk -F = --assign "kver=${KVER}" ' - /^\[/ { - # section header - previous section (if any) ended + if ! fgrep -q "[${KVER}]" $EFI_DIR/xen.cfg; then + # take the default section and use it as a template for the new entry + awk -F = --assign "kver=${KVER}" ' + /^\[/ { + # section header - previous section (if any) ended - # if default section already processed, that is all - if (in_default) exit; - in_global=0; - in_default=0; - } - /\[global\]/ { - in_global=1; - } - /^\[/ { - if ("[" default_name "]" == $0) { - in_default=1; - print "[" kver "]"; - next; + # if default section already processed, that is all + if (in_default) exit; + in_global=0; + in_default=0; + } + /\[global\]/ { + in_global=1; } - } - /^default=/ { - if (in_global) - default_name=$2; - } - /^kernel=/ { - if (in_default) { - sub("=[^ ]*", "=vmlinuz-" kver); + /^\[/ { + if ("[" default_name "]" == $0) { + in_default=1; + print "[" kver "]"; + next; + } } - } - /^ramdisk=/ { - if (in_default) { - sub("=[^ ]*", "=initramfs-" kver ".img"); + /^default=/ { + if (in_global) + default_name=$2; } - } - { - if (in_default) { - print; + /^kernel=/ { + if (in_default) { + sub("=[^ ]*", "=vmlinuz-" kver); + } } - }' $EFI_DIR/xen.cfg >> $EFI_DIR/xen.cfg - - # then change the default - sed -e "s/default=.*/default=$KVER/" -i $EFI_DIR/xen.cfg + /^ramdisk=/ { + if (in_default) { + sub("=[^ ]*", "=initramfs-" kver ".img"); + } + } + { + if (in_default) { + print; + } + }' $EFI_DIR/xen.cfg >> $EFI_DIR/xen.cfg + + # then change the default + sed -e "s/default=.*/default=$KVER/" -i $EFI_DIR/xen.cfg + fi cp "/boot/vmlinuz-$KVER" "$EFI_DIR/" dracut -f "$EFI_DIR/initramfs-${KVER}.img" "$KVER"