-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Grub theme configuration #149
Comments
Solution for Configuring a GRUB Theme by taking inspiration from ChrisTitusTech's GRUB projectDescription of the Solution You Might be Interested IntoTo provide a solution for configuring a GRUB theme, a script can be created that allows users to select a theme from the themes available in the Script OverviewThe following script dynamically lists the available themes in the specified directory and allows the user to select one. Once a theme is selected, it configures GRUB to use the chosen theme, enabling the GRUB menu with a 60-second timeout and setting the graphics mode to auto. The script also backs up the existing GRUB configuration before making any changes, ensuring that the original settings can be restored if needed. Implementation#!/bin/bash
# GRUB Theme Installer Script (Distro-Agnostic)
# Theme directory
THEME_DIR='/boot/grub/themes'
THEME_NAME=''
DISTRO=''
# Function to detect the Linux distribution
function detect_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
else
echo "Unknown distribution. Exiting..."
exit 1
fi
}
# Function to display menu and install selected theme
function select_theme() {
# Get the list of theme directories in THEME_DIR
themes=($(ls -d "${THEME_DIR}"/*/ | xargs -n 1 basename))
themes+=("Quit") # Add a Quit option at the end
if [ ${#themes[@]} -eq 1 ]; then
echo "No themes found in ${THEME_DIR}. Please add themes before running the script."
exit 1
fi
PS3='Choose The Theme You Want: '
select THEME_NAME in "${themes[@]}"; do
if [ "${THEME_NAME}" == "Quit" ]; then
echo 'Exiting...'
exit 0
elif [[ " ${themes[@]} " =~ " ${THEME_NAME} " ]]; then
echo "Installing ${THEME_NAME} Theme..."
break
else
echo "Invalid option"
fi
done
}
# Function to check for root access
function check_root() {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please use sudo."
exit 1
fi
}
# Function to backup the current GRUB config
function backup_grub() {
cp -an /etc/default/grub /etc/default/grub.bak
echo "Backup of GRUB config created at /etc/default/grub.bak"
}
# Function to install the selected theme
function install_theme() {
# Create the theme directory if it doesn't exist
if [[ ! -d "${THEME_DIR}/${THEME_NAME}" ]]; then
echo "Error: Theme ${THEME_NAME} does not exist."
exit 1
fi
# Set the theme in the GRUB config
sed -i '/GRUB_THEME=/d' /etc/default/grub
echo "GRUB_THEME=\"${THEME_DIR}/${THEME_NAME}/theme.txt\"" >> /etc/default/grub
echo "Theme ${THEME_NAME} installed."
}
# Function to configure GRUB
function config_grub() {
# Enable GRUB menu
sed -i '/GRUB_TIMEOUT_STYLE=/d' /etc/default/grub
echo 'GRUB_TIMEOUT_STYLE="menu"' >> /etc/default/grub
# Set GRUB timeout to 60 seconds
sed -i '/GRUB_TIMEOUT=/d' /etc/default/grub
echo 'GRUB_TIMEOUT=60' >> /etc/default/grub
# Set GRUB graphics mode to auto
sed -i '/GRUB_GFXMODE=/d' /etc/default/grub
echo 'GRUB_GFXMODE="auto"' >> /etc/default/grub
}
# Function to update GRUB based on distro
function update_grub() {
case "$DISTRO" in
ubuntu|debian)
update-grub
;;
arch|manjaro)
grub-mkconfig -o /boot/grub/grub.cfg
;;
fedora|centos)
grub2-mkconfig -o /boot/grub2/grub.cfg
;;
*)
echo "Unsupported distribution: $DISTRO"
exit 1
;;
esac
echo "GRUB configuration updated."
}
# Main function to run the theme installation process
function main() {
detect_distro
check_root
select_theme
backup_grub
install_theme
config_grub
update_grub
echo "GRUB Theme Update Successful!"
}
main
Explanation
Describe Alternatives You've Considered
Additional ContextThis script is designed to make it easy for users to apply a GRUB theme by selecting one from the available directories. The focus is on simplicity and reliability, ensuring that users can update their GRUB theme with minimal effort. Future versions of the script could incorporate additional features like theme downloads or a library of standard themes to further enhance the user experience. |
Added in #493 /close |
Describe the solution you'd like
Add an option to configure a grub theme
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
The text was updated successfully, but these errors were encountered: