My-distro-configs/calamares/scripts/grub-defaults

54 lines
1.8 KiB
Plaintext
Raw Normal View History

2024-09-08 16:09:09 +00:00
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2023 PeppermintOS Team (peppermintosteam@proton.me)
# This script configures grub defaults after Debian installation.
# Define CHROOT
CHROOT=$(mount | grep proc | grep calamares | awk '{print $3}' | sed -e "s#/proc##g")
# Sets GRUB configuration.
# Writes the configuration to the /etc/default/grub file.
# Updates the bootloader.
# Check if CHROOT is set
if [ -z "$CHROOT" ]; then
echo "CHROOT not set. Exiting."
exit 1
fi
# Defines the variables
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="My-distro"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
GRUB_GFXMODE=1440x900
GRUB_THEME="/boot/grub/themes/my-distro/theme.txt"
GRUB_DISABLE_OS_PROBER=false
# GRUB configuration file path
GRUB_CONFIG_FILE="$CHROOT/etc/default/grub"
# Modify the GRUB file
sed -i "s/^GRUB_DEFAULT=.*/GRUB_DEFAULT=$GRUB_DEFAULT/" $GRUB_CONFIG_FILE
sed -i "s/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=$GRUB_TIMEOUT/" $GRUB_CONFIG_FILE
sed -i "s/^GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"$GRUB_DISTRIBUTOR\"/" $GRUB_CONFIG_FILE
sed -i "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"$GRUB_CMDLINE_LINUX_DEFAULT\"/" $GRUB_CONFIG_FILE
sed -i "s/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"$GRUB_CMDLINE_LINUX\"/" $GRUB_CONFIG_FILE
sed -i "s/^#GRUB_GFXMODE=.*/GRUB_GFXMODE=$GRUB_GFXMODE/" $GRUB_CONFIG_FILE
# Add GRUB_THEME if it doesn't exist
if ! grep -q "^GRUB_THEME=" $GRUB_CONFIG_FILE; then
echo "GRUB_THEME=\"$GRUB_THEME\"" >> $GRUB_CONFIG_FILE
else
sed -i "s#^GRUB_THEME=.*#GRUB_THEME=\"$GRUB_THEME\"#" $GRUB_CONFIG_FILE
fi
sed -i "s/^#GRUB_DISABLE_OS_PROBER=.*/GRUB_DISABLE_OS_PROBER=$GRUB_DISABLE_OS_PROBER/" $GRUB_CONFIG_FILE
# Run update-grub after modifying the file
chroot $CHROOT update-grub