bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[grub-mkconfig] Problem with generation method in grub-mkconfig


From: Alban PONCHE
Subject: [grub-mkconfig] Problem with generation method in grub-mkconfig
Date: Tue, 2 Jan 2024 11:01:03 +0100 (CET)

Hello,

actually, with grub-mkconfig, you can't use "sed -i /boot/grub/grub.cfg.new" in
one of /etc/grub.d/* script, due to the use of "exec > /boot/grub/grub.cfg.new"
method.

I propose to rewrite the output redirection in more standard way, to permit
usage of sed -i in /etc/grub.d/* script, wich is usefull, when you dont want to
"override" a "standard" distro script (10_linux for example) but having fully
customized menuentry


<code>

diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 32c480dae..bdabb7a0d 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -257,23 +257,24 @@ export GRUB_DEFAULT \
GRUB_OS_PROBER_SKIP_LIST \
GRUB_DISABLE_SUBMENU

+NEW_GRUBCFG="${grub_cfg}.new"
if test "x${grub_cfg}" != “x”; then
- rm -f "${grub_cfg}.new"
+ rm -f "${NEW_GRUBCFG}"
oldumask=$(umask); umask 077
- exec > "${grub_cfg}.new"
+ printf "" > "${NEW_GRUBCFG}"
umask $oldumask
fi
gettext "Generating grub configuration file ..." >&2
echo >&2

-cat << EOF
-#
+DISCLAIMER="#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by $self using templates
# from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
#
-EOF
+"
+printf "%s\n“ ”${DISCLAIMER}" >> "${NEW_GRUBCFG}"


for i in "${grub_mkconfig_dir}"/* ; do
@@ -284,10 +285,13 @@ for i in "${grub_mkconfig_dir}"/* ; do
*/\#*\#) ;;
*)
if grub_file_is_not_garbage "$i" && test -x "$i" ; then
- echo
- echo "### BEGIN $i ###"
- "$i"
- echo "### END $i ###"
+ echo "" >> "${NEW_GRUBCFG}"
+ echo "### BEGIN $i ###" >> "${NEW_GRUBCFG}"
+ if ! "$i" >> "${NEW_GRUBCFG}";then
+ echo "[ERROR] '$i' failed !" >&2
+ exit 99
+ fi
+ echo "### END $i ###" >> "${NEW_GRUBCFG}"
fi
;;
esac
@@ -299,7 +303,7 @@ if test "x${grub_cfg}" != “x” ; then
gettext_printf "Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
-%s file attached.“ ”${grub_cfg}.new" >&2
+%s file attached.“ ”${NEW_GRUBCFG}" >&2
echo >&2
exit 1
else


</code>


Alban



reply via email to

[Prev in Thread] Current Thread [Next in Thread]