install.fairie/home/dot_local/bin/post-installx/executable_post-plymouth.sh

98 lines
4.3 KiB
Bash
Raw Normal View History

2024-05-03 19:40:44 -07:00
#!/usr/bin/env bash
# @file Plymouth Theme / Configuration
# @brief Configures Plymouth to use a custom theme
# @description
# This script installs Plymouth and then configures it to use our custom Betelgeuse theme.
2024-05-27 20:45:14 -07:00
set -Eeuo pipefail
2024-05-27 20:50:11 -07:00
trap "gum log -sl error 'Script encountered an error!'" ERR
2024-05-27 04:15:03 -07:00
2024-05-03 19:40:44 -07:00
### Create /etc/plymouth/plymouthd.conf
if [ -f /etc/plymouth/plymouthd.conf ]; then
### Back up original plymouthd.conf
if [ ! -f /etc/plymouth/plymouthd.conf.bak ]; then
2024-05-27 20:50:11 -07:00
gum log -sl info 'Backing up /etc/plymouth/plymouthd.conf to /etc/plymouth/plymouthd.conf.bak'
2024-05-03 19:40:44 -07:00
sudo cp -f /etc/plymouth/plymouthd.conf /etc/plymouth/plymouthd.conf.bak
fi
### Create new plymouthd.conf
2024-05-27 20:50:11 -07:00
gum log -sl info 'Populating the /etc/plymouth/plymouthd.conf file'
2024-05-03 19:40:44 -07:00
echo "[Daemon]" | sudo tee /etc/plymouth/plymouthd.conf > /dev/null
2024-05-27 04:15:03 -07:00
echo "Theme=Betelgeuse" | sudo tee -a /etc/plymouth/plymouthd.conf > /dev/null
2024-05-03 19:40:44 -07:00
echo "ShowDelay=1" | sudo tee -a /etc/plymouth/plymouthd.conf > /dev/null
fi
### Apply update-alternatives
if command -v update-alternatives > /dev/null; then
2024-05-27 04:15:03 -07:00
if [ -f "/usr/local/share/plymouth/themes/Betelgeuse/Betelgeuse.plymouth" ]; then
sudo update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth "/usr/local/share/plymouth/themes/Betelgeuse/Betelgeuse.plymouth" 100
2024-05-27 23:55:42 -07:00
gum log -sl info 'Installed default.plymouth'
2024-05-03 19:40:44 -07:00
# Required sometimes
2024-05-27 04:15:03 -07:00
sudo update-alternatives --set default.plymouth "/usr/local/share/plymouth/themes/Betelgeuse/Betelgeuse.plymouth"
2024-05-27 23:55:42 -07:00
gum log -sl info 'Set default.plymouth'
2024-05-03 19:40:44 -07:00
else
2024-05-27 20:50:11 -07:00
gum log -sl warn "/usr/local/share/plymouth/themes/Betelgeuse/Betelgeuse.plymouth does not exist!"
2024-05-03 19:40:44 -07:00
fi
else
2024-05-27 20:50:11 -07:00
gum log -sl warn 'update-alternatives is not available'
2024-05-03 19:40:44 -07:00
fi
### Update /etc/plymouth/plymouthd.conf
# Replaced by code above
# if [ -f /etc/plymouth/plymouthd.conf ]; then
2024-05-27 20:50:11 -07:00
# gum log -sl info 'Setting ShowDelay=1 in /etc/plymouth/plymouthd.conf'
2024-05-03 19:40:44 -07:00
# if cat /etc/plymouth/plymouthd.conf | grep ShowDelay; then
# sudo sed -i 's/^ShowDelay=.*/ShowDelay=1/' /etc/plymouth/plymouthd.conf
# else
# echo 'ShowDelay=1' | sudo tee -a /etc/plymouth/plymouthd.conf > /dev/null
# fi
# else
2024-05-27 20:50:11 -07:00
# gum log -sl warn '/etc/plymouth/plymouthd.conf does not exist!'
2024-05-03 19:40:44 -07:00
# fi
### Symlink /usr/local/share/plymouth/themes to /usr/share/plymouth/themes
2024-05-27 04:15:03 -07:00
if [ ! -d '/usr/share/plymouth/themes/Betelgeuse' ]; then
2024-05-27 20:50:11 -07:00
gum log -sl info 'Symlinking /usr/local/share/plymouth/themes/Betelgeuse to /usr/share/plymouth/themes/Betelgeuse'
2024-05-27 04:15:03 -07:00
sudo ln -s '/usr/local/share/plymouth/themes/Betelgeuse' '/usr/share/plymouth/themes/Betelgeuse'
2024-05-03 19:40:44 -07:00
fi
### Set default Plymouth theme
if command -v plymouth-set-default-theme > /dev/null; then
2024-05-27 04:15:03 -07:00
sudo plymouth-set-default-theme -R 'Betelgeuse' || EXIT_CODE=$?
2024-05-27 20:45:14 -07:00
if [ -n "${EXIT_CODE:-}" ]; then
2024-05-27 20:50:11 -07:00
gum log -sl warn 'There may have been an issue while setting the Plymouth default theme with plymouth-set-default-theme'
2024-05-03 19:40:44 -07:00
else
2024-05-27 23:55:42 -07:00
gum log -sl info 'Set Plymouth default theme with plymouth-set-default-theme'
2024-05-03 19:40:44 -07:00
fi
else
2024-05-27 20:50:11 -07:00
gum log -sl warn 'Could not apply default Plymouth theme because plymouth-set-default-theme is missing'
2024-05-03 19:40:44 -07:00
fi
### Apply update-alternatives (again - required sometimes)
if command -v update-alternatives > /dev/null; then
2024-05-27 04:15:03 -07:00
if [ -f "/usr/local/share/plymouth/themes/Betelgeuse/Betelgeuse.plymouth" ]; then
2024-05-03 19:40:44 -07:00
# Required sometimes
2024-05-27 04:15:03 -07:00
sudo update-alternatives --set default.plymouth "/usr/local/share/plymouth/themes/Betelgeuse/Betelgeuse.plymouth"
2024-05-27 23:55:42 -07:00
gum log -sl info 'Set default.plymouth (second time is required sometimes)'
2024-05-03 19:40:44 -07:00
else
2024-05-27 20:50:11 -07:00
gum log -sl warn "/usr/local/share/plymouth/themes/Betelgeuse/Betelgeuse.plymouth does not exist!"
2024-05-03 19:40:44 -07:00
fi
else
2024-05-27 20:50:11 -07:00
gum log -sl warn 'update-alternatives is not available'
2024-05-03 19:40:44 -07:00
fi
### Update kernel / initrd images
# Set `export DEBUG_MODE=true` to bypass GRUB2 / Plymouth application
if [ "$DEBUG_MODE" != 'true' ]; then
if command -v update-initramfs > /dev/null; then
2024-05-27 20:50:11 -07:00
gum log -sl info 'Running sudo update-initramfs -u'
2024-05-03 19:40:44 -07:00
sudo update-initramfs -u
2024-05-27 23:55:42 -07:00
gum log -sl info 'Updated kernel / initrd images for Plymouth'
2024-05-03 19:40:44 -07:00
elif command -v dracut > /dev/null; then
2024-05-27 20:50:11 -07:00
gum log -sl info 'Running sudo dracut --regenerate-all -f'
2024-05-03 19:40:44 -07:00
sudo dracut --regenerate-all -f
2024-05-27 23:55:42 -07:00
gum log -sl info 'Updated kernel / initrd images for Plymouth'
2024-05-03 19:40:44 -07:00
else
2024-05-27 20:50:11 -07:00
gum log -sl warn 'Unable to update kernel / initrd images because neither update-initramfs or dracut are available'
2024-05-03 19:40:44 -07:00
fi
fi