I'm having trouble updating GRUB, and it seems to have something to do with scripts being generated by grub-customizer with incorrect syntax. I'm not very experienced with shell scripting, so I need some help with figuring out what's causing the following error messages.
This is the output I get from sudo update-grub:
Generating grub configuration file ...
Found theme: /boot/grub/themes/artix_modified_16:9/theme.txt
Found linux image: /boot/vmlinuz-linux-lts
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-linux-lts.img
Found fallback initrd image(s) in /boot: intel-ucode.img amd-ucode.img initramfs-linux-lts-fallback.img
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: intel-ucode.img amd-ucode.img initramfs-linux-fallback.img
Found memtest86+ image: /boot/memtest86+/memtest.bin
Adding boot menu entry for UEFI Firmware Settings ...
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Adding boot menu entry for UEFI Firmware Settings ...
Found memtest86+ image: /boot/memtest86+/memtest.bin
error: syntax error.
error: Incorrect command.
error: syntax error.
Syntax error at line 241
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
/boot/grub/grub.cfg.new file attached.
This is what the end of my /boot/grub/grub.cfg.new looks like (except there are ^Ms on the end of some lines):
### BEGIN /etc/grub.d/61_linux_xen ###
### END /etc/grub.d/61_linux_xen ###
### BEGIN /etc/grub.d/62_os-prober ###
### END /etc/grub.d/62_os-prober ###
### BEGIN /etc/grub.d/63_uefi-firmware_proxy ###
fwsetup --is-supported
if [ "$grub_platform" = "efi" -a "$?" = 0 ]; then
fi
### END /etc/grub.d/63_uefi-firmware_proxy ###
### BEGIN /etc/grub.d/64_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/64_custom ###
### BEGIN /etc/grub.d/65_custom ###
if [ -f ${config_directory}/custom.cfg ]; then
source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg
fi
### END /etc/grub.d/65_custom ###
### BEGIN /etc/grub.d/66_memtest86+_proxy ###
if [ "${grub_platform}" == "pc" ]; then
fi
### END /etc/grub.d/66_memtest86+_proxy ###
And I found code that matches those blank if statements, except there's stuff inside them. The first bit is in /etc/grub.d/proxifiedScripts/uefi-firmware:
#! /bin/sh
set -e
# grub-mkconfig helper script.
# Copyright (C) 2020 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
prefix="/usr"
exec_prefix="/usr"
datarootdir="/usr/share"
export TEXTDOMAIN=grub
export TEXTDOMAINDIR="${datarootdir}/locale"
. "$pkgdatadir/grub-mkconfig_lib"
LABEL="UEFI Firmware Settings"
gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2
cat << EOF
fwsetup --is-supported
if [ "\$grub_platform" = "efi" -a "\$?" = 0 ]; then
menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
fwsetup
}
fi
EOF
The other bit is in /etc/grub.d/proxifiedScripts/memtest86+:
#!/usr/bin/env bash
########################################################
# This script generates a memtest86+ entry on grub.cfg #
# if memtest is installed on the system. #
########################################################
prefix="/usr"
exec_prefix="${prefix}"
datarootdir="/usr/share"
datadir="${datarootdir}"
. "${datadir}/grub/grub-mkconfig_lib"
MEMTEST86_IMAGE="/boot/memtest86+/memtest.bin"
CLASS="--class memtest86 --class gnu --class tool"
if [ -e "${MEMTEST86_IMAGE}" ] && is_path_readable_by_grub "${MEMTEST86_IMAGE}" ; then
## image exists, create menu entry
echo "Found memtest86+ image: ${MEMTEST86_IMAGE}" >&2
_GRUB_MEMTEST_HINTS_STRING="$(${grub_probe} --target=hints_string ${MEMTEST86_IMAGE})"
_GRUB_MEMTEST_FS_UUID="$(${grub_probe} --target=fs_uuid ${MEMTEST86_IMAGE})"
_GRUB_MEMTEST_REL_PATH="$(make_system_path_relative_to_its_root ${MEMTEST86_IMAGE})"
cat << EOF
if [ "\${grub_platform}" == "pc" ]; then
menuentry "Memory Tester (memtest86+)" ${CLASS} {
search --fs-uuid --no-floppy --set=root ${_GRUB_MEMTEST_HINTS_STRING} ${_GRUB_MEMTEST_FS_UUID}
linux16 ${_GRUB_MEMTEST_REL_PATH} ${GRUB_CMDLINE_MEMTEST86}
}
fi
EOF
fi
How do I fix this issue and what's causing it?