winboot: check all grub conf files

This commit is contained in:
Jeremy Gardais 2019-03-13 20:39:14 +01:00
parent 9486c02189
commit 177a2a24b5
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 15 additions and 4 deletions

19
winboot
View File

@ -1,20 +1,31 @@
#!/bin/sh #!/bin/sh
GRUB_DEFAULT_PATH='/etc/default/grub' GRUB_DEFAULT_PATH='/etc/default/grub'
WIN_GRUB="3" GRUB_DEFAULT_DIR='/etc/default/grub.d'
WIN_GRUB="2"
# First check in Grub default dir if saved mode is set
if grep -q -E -R -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_DIR}"
then
printf '%b' "Reboot to windaube partition\\n"
sudo grub-reboot "${WIN_GRUB}"
sudo systemctl reboot
fi
# Otherwise check the default grub file
if grep -q -E -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_PATH}" if grep -q -E -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_PATH}"
then then
printf '%b' "Reboot to windaube partition\n" printf '%b' "Reboot to windaube partition\\n"
sudo grub-reboot "${WIN_GRUB}" sudo grub-reboot "${WIN_GRUB}"
sudo systemctl reboot sudo systemctl reboot
else else
printf '%b' "GRUB_DEFAULT is not set in 'saved' mode\n"
printf '%b' "GRUB_DEFAULT is not set in 'saved' mode\\n"
sudo sed -i 's/\(^GRUB_DEFAULT.*\)/#\1\nGRUB_DEFAULT=saved/' "${GRUB_DEFAULT_PATH}" sudo sed -i 's/\(^GRUB_DEFAULT.*\)/#\1\nGRUB_DEFAULT=saved/' "${GRUB_DEFAULT_PATH}"
GRUB_DEFAULT_ENTRY=$(grep -E -- "#GRUB_DEFAULT=" "${GRUB_DEFAULT_PATH}" | cut -d"=" -f2) GRUB_DEFAULT_ENTRY=$(grep -E -- "#GRUB_DEFAULT=" "${GRUB_DEFAULT_PATH}" | cut -d"=" -f2)
sudo grub-set-default "${GRUB_DEFAULT_ENTRY}" sudo grub-set-default "${GRUB_DEFAULT_ENTRY}"
sudo update-grub sudo update-grub
printf '%b' "Please launch this script once again.\n" printf '%b' "Please launch this script once again.\\n"
fi fi
exit 0 exit 0