Created
May 23, 2021 23:11
-
-
Save dbazile/16e4a72fc2d7abd566b032634ef080b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
NEW_CONFIG='/root/grub.cfg.new' | |
OLD_CONFIG='/boot/efi/EFI/fedora/grub.cfg' | |
checkpoint() { echo -e "\033[1m\n$*\033[0m"; } | |
checkpoint "edit grub defaults:" | |
sudo vim /etc/default/grub | |
checkpoint "generate config: $NEW_CONFIG" | |
sudo grub2-mkconfig 2>/dev/null | sudo tee "$NEW_CONFIG" > /dev/null | |
checkpoint "changes:" | |
if sudo diff -u --color "$OLD_CONFIG" "$NEW_CONFIG"; then | |
echo "none" | |
exit 1 | |
fi | |
checkpoint "backup and install new config?" | |
read -p '(y/N): ' | |
if [[ ! $REPLY =~ ^y|Y ]]; then | |
echo "exiting" | |
exit 1 | |
fi | |
checkpoint "making backup:" | |
timestamp=$(date +'%Y%m%d%H%M%S') | |
backup="/root/grub.cfg.${timestamp}~" | |
set -x | |
sudo cp "$OLD_CONFIG" "$backup" | |
sudo chmod -x "$backup" | |
sudo mv "$NEW_CONFIG" "$OLD_CONFIG" | |
sudo chmod +x "$OLD_CONFIG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment