add support for grub configs that do not use GRUB_CMDLINE_LINUX_DEFAULT variable

This commit is contained in:
HikariKnight 2022-03-11 08:14:27 +01:00
parent 4abea3d6d5
commit 34dd4212d2
No known key found for this signature in database
GPG key ID: E8B239063B022F5A

View file

@ -36,11 +36,23 @@ function set_GRUB () {
CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
# HIGHLY EXPERIMENTAL!
GRUB_CMDLINE=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX_DEFAULT" | perl -pe "s/GRUB_CMDLINE_LINUX_DEFAULT=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g")
GRUB_CMDLINE_LINUX_DEFAULT=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX_DEFAULT")
local GRUB_CMDLINE
local GRUB_CMDLINE_LINUX
# Check if there is a GRUB_CMDLINE_LINUX_DEFAULT line in grub config
if grep -q "GRUB_CMDLINE_LINUX_DEFAULT=" ;
then
# Update the GRUB_CMDLINE_LINUX_DEFAULT line
perl -pi -e "s/${GRUB_CMDLINE_LINUX_DEFAULT}/GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/config/etc/default/grub"
GRUB_CMDLINE=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX_DEFAULT" | perl -pe "s/GRUB_CMDLINE_LINUX_DEFAULT=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g")
GRUB_CMDLINE_LINUX=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX_DEFAULT")
perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/config/etc/default/grub"
else
# Update the GRUB_CMDLINE_LINUX line
GRUB_CMDLINE=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX" | perl -pe "s/GRUB_CMDLINE_LINUX=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g")
GRUB_CMDLINE_LINUX=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX")
perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/config/etc/default/grub"
fi
echo "The script will now replace your default grub file with a new one.
Then attempt to update grub and generate a new grub.cfg.