0108858483
- /home/.chezmoiscripts/universal/run_onchange_after_60-grub-settings.tmpl - /home/.chezmoiscripts/universal/run_onchange_after_61-plymouth-settings.tmpl - /home/.chezmoiscripts/universal/run_onchange_after_64-grub-settings.tmpl - /software.yml
141 lines
6 KiB
Cheetah
141 lines
6 KiB
Cheetah
{{- if (eq .host.distro.family "linux") -}}
|
|
#!/usr/bin/env bash
|
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
{{ includeTemplate "universal/logg" }}
|
|
|
|
### Fix Qubes issue
|
|
if command -v qubesctl > /dev/null && [ -f /boot/grub2/grubenv ] && [ -d /boot/efi/EFI/qubes ]; then
|
|
sudo cp -f /boot/grub2/grubenv /boot/efi/EFI/qubes/grubenv
|
|
logg success 'Copied /boot/grub2/grubenv to /boot/efi/EFI/qubes/grubenv'
|
|
fi
|
|
|
|
### Ensure /boot/grub2/themes is directory
|
|
if [ ! -d /boot/grub2/themes ]; then
|
|
sudo mkdir -p /boot/grub2/themes
|
|
logg success 'Created /boot/grub2/themes'
|
|
fi
|
|
|
|
### Copy GRUB theme to /boot/grub2/themes
|
|
if [ -d /usr/local/share/grub/themes ]; then
|
|
sudo cp -rf /usr/local/share/grub/themes/ /boot/grub2/themes
|
|
logg success 'Copied GRUB themes in /usr/local/share/grub/themes to /boot/grub2/themes'
|
|
else
|
|
logg warn '`/usr/local/share/grub/themes` is missing'
|
|
fi
|
|
|
|
### Set default GRUB screen resolution variables
|
|
SCREEN_RATIO_ULTRAWIDE="2100"
|
|
GRUB_RESOLUTION_TYPE="1080p"
|
|
|
|
### Determine screen size ratio (used for picking GRUB2 theme resolution)
|
|
if command -v xrandr && command -v uniq; then
|
|
SCREEN_WIDTH="$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)"
|
|
SCREEN_HEIGHT="$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)"
|
|
SCREEN_RATIO="$(awk -v height="$SCREEN_HEIGHT" -v width="$SCREEN_WIDTH" 'BEGIN { print ((height / width) * 1000) }')"
|
|
SCREEN_RATIO="${SCREEN_RATIO%.*}"
|
|
logg success "Screen detected as $SCREEN_WIDTH x $SCREEN_HEIGHT (ratio of $SCREEN_RATIO)"
|
|
if (( $(echo "$SCREEN_RATIO $SCREEN_RATIO_ULTRAWIDE" | awk '{print ($1 > $2)}') )); then
|
|
GRUB_RESOLUTION_TYPE="ultrawide"
|
|
logg info 'GRUB resolution registered as `ultrawide`'
|
|
fi
|
|
else
|
|
logg warn 'Missing either `xrandr` or `uniq` (required for calculating screen size ratio)'
|
|
fi
|
|
|
|
### Optimize the GRUB resolution
|
|
if [ -f /etc/default/grub ]; then
|
|
### GRUB_GFXMODE
|
|
logg info 'Setting GRUB_GFXMODE=auto in /etc/default/grub'
|
|
if cat /etc/default/grub | grep GRUB_GFX_MODE; then
|
|
sudo sed -i '/.*GRUB_GFXMODE.*/GRUB_GFXMODE=auto/' /etc/default/grub
|
|
else
|
|
echo "GRUB_GFXMODE=auto" | sudo tee -a /etc/default/grub
|
|
fi
|
|
|
|
### GRUB_GFXPAYLOAD_LINUX
|
|
logg info 'Setting GRUB_GFXPAYLOAD_LINUX=keep in /etc/default/grub'
|
|
if cat /etc/default/grub | grep GRUB_GFXPAYLOAD_LINUX; then
|
|
sudo sed -i '/.*GRUB_GFXPAYLOAD_LINUX.*/GRUB_GFXPAYLOAD_LINUX="keep"/' /etc/default/grub
|
|
else
|
|
echo 'GRUB_GFXPAYLOAD_LINUX="keep"' | sudo tee -a /etc/default/grub
|
|
fi
|
|
|
|
### GRUB_THEME
|
|
logg info 'Setting GRUB_THEME={{ .theme }} in /etc/default/grub'
|
|
if cat /etc/default/grub | grep GRUB_THEME; then
|
|
sudo sed -i '/.*GRUB_THEME.*/GRUB_THEME="{{ .theme }}-'"$GRUB_RESOLUTION_TYPE"'"/' /etc/default/grub
|
|
else
|
|
echo 'GRUB_THEME="{{ .theme }}-'"$GRUB_RESOLUTION_TYPE"'"' | sudo tee -a /etc/default/grub
|
|
fi
|
|
|
|
### GRUB_BACKGROUND
|
|
logg info 'Setting GRUB_BACKGROUND=/usr/local/share/grub/{{ .theme }}-blue.png in /etc/default/grub'
|
|
if cat /etc/default/grub | grep GRUB_BACKGROUND; then
|
|
sudo sed -i '/.*GRUB_BACKGROUND.*/GRUB_BACKGROUND="/usr/local/share/grub/{{ .theme }}-blue.png"/' /etc/default/grub
|
|
else
|
|
echo 'GRUB_BACKGROUND="/usr/local/share/grub/{{ .theme }}-blue.png"' | sudo tee -a /etc/default/grub
|
|
fi
|
|
|
|
### GRUB_TIMEOUT
|
|
logg info 'Setting GRUB_TIMEOUT={{ .grub.timeout }} in /etc/default/grub'
|
|
if cat /etc/default/grub | grep GRUB_TIMEOUT; then
|
|
sudo sed -i '/.*GRUB_TIMEOUT.*/GRUB_TIMEOUT="{{ .grub.timeout }}"/' /etc/default/grub
|
|
else
|
|
echo 'GRUB_TIMEOUT="{{ .grub.timeout }}"' | sudo tee -a /etc/default/grub
|
|
fi
|
|
|
|
### GRUB_FORCE_HIDDEN_MENU
|
|
logg info 'Setting GRUB_FORCE_HIDDEN_MENU={{ .grub.shiftToSee }} in /etc/default/grub'
|
|
sed -i '/GRUB_FORCE_HIDDEN_MENU/d' /etc/default/grub
|
|
echo "GRUB_FORCE_HIDDEN_MENU={{ .grub.shiftToSee }}" > /etc/default/grub
|
|
|
|
### Remove duplicate lines in /etc/default/grub
|
|
logg info 'Ensuring there are no duplicate entries in /etc/default/grub'
|
|
cat /etc/default/grub | uniq -u | sudo tee /etc/default/grub
|
|
else
|
|
logg warn '/etc/default/grub is missing'
|
|
fi
|
|
|
|
### Determine platform-specific icon to use
|
|
if command -v qubesctl > /dev/null; then
|
|
GRUB_ICON='qubes'
|
|
elif [ -f "/boot/grub2/themes/{{ .theme }}-$GRUB_RESOLUTION_TYPE/icons/{{ .host.distro.id }}.png" ]; then
|
|
GRUB_ICON='{{ .host.distro.id }}'
|
|
elif [ -f "/boot/grub2/themes/{{ .theme }}-$GRUB_RESOLUTION_TYPE/icons/{{ .host.distro.family }}.png" ]; then
|
|
GRUB_ICON='{{ .host.distro.family }}'
|
|
else
|
|
GRUB_ICON='linux'
|
|
fi
|
|
|
|
### Copy icon to GRUB2 theme folder
|
|
if [ -f "/boot/grub2/themes/{{ .theme }}-$GRUB_RESOLUTION_TYPE/icons/$GRUB_ICON.png" ]; then
|
|
cp -f /boot/grub2/themes/{{ .theme }}-$GRUB_RESOLUTION_TYPE/icons/$GRUB_ICON.png /boot/grub2/themes/{{ .theme }}-$GRUB_RESOLUTION_TYPE/icon.png
|
|
logg success 'Copied platform-specific icon to GRUB2 theme folder'
|
|
else
|
|
logg warn "/boot/grub2/themes/{{ .theme }}-$GRUB_RESOLUTION_TYPE/icons/$GRUB_ICON.png is missing"
|
|
fi
|
|
|
|
### Apply GRUB2 theme
|
|
# Set `export DEBUG_MODE=true` to bypass GRUB2 / Plymouth application
|
|
if [ -d /sys/firmware/efi ] && [ "$DEBUG_MODE" != 'true' ]; then
|
|
logg info 'Assuming system is UEFI-enabled since /sys/firmware/efi is present'
|
|
if [ -f /boot/efi/EFI/qubes/grub.cfg ]; then
|
|
logg info 'Running `sudo grub2-mkconfig -o /boot/efi/EFI/qubes/grub.cfg`'
|
|
sudo grub2-mkconfig -o /boot/efi/EFI/qubes/grub.cfg
|
|
logg success 'Applied GRUB2 theme'
|
|
elif [ -f /boot/efi/EFI/grub.cfg ]
|
|
logg info 'Running `sudo grub2-mkconfig -o /boot/efi/EFI/grub.cfg`'
|
|
sudo grub2-mkconfig -o /boot/efi/EFI/grub.cfg
|
|
logg success 'Applied GRUB2 theme'
|
|
else
|
|
logg warn 'Unknown GRUB2 configuration - not applying GRUB2 theme'
|
|
fi
|
|
else
|
|
logg info 'Assuming system is non-UEFI since /sys/firmware/efi is not present'
|
|
logg info 'Running `sudo grub2-mkconfig -o /boot/grub2/grub.cfg`'
|
|
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
|
|
logg success 'Applied GRUB2 theme'
|
|
fi
|
|
|
|
{{ end -}}
|