2016-12-19 17:45:17 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
GRUB_DEFAULT_PATH='/etc/default/grub'
|
2019-03-13 20:39:14 +01:00
|
|
|
GRUB_DEFAULT_DIR='/etc/default/grub.d'
|
|
|
|
WIN_GRUB="2"
|
2016-12-19 17:45:17 +01:00
|
|
|
|
2019-03-13 20:39:14 +01:00
|
|
|
# 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
|
2016-12-19 17:45:17 +01:00
|
|
|
if grep -q -E -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_PATH}"
|
|
|
|
then
|
2019-03-13 20:39:14 +01:00
|
|
|
printf '%b' "Reboot to windaube partition\\n"
|
2016-12-19 17:45:17 +01:00
|
|
|
sudo grub-reboot "${WIN_GRUB}"
|
|
|
|
sudo systemctl reboot
|
|
|
|
else
|
2019-03-13 20:39:14 +01:00
|
|
|
|
|
|
|
printf '%b' "GRUB_DEFAULT is not set in 'saved' mode\\n"
|
2016-12-19 17:45:17 +01:00
|
|
|
sudo sed -i 's/\(^GRUB_DEFAULT.*\)/#\1\nGRUB_DEFAULT=saved/' "${GRUB_DEFAULT_PATH}"
|
2016-12-20 18:52:25 +01:00
|
|
|
GRUB_DEFAULT_ENTRY=$(grep -E -- "#GRUB_DEFAULT=" "${GRUB_DEFAULT_PATH}" | cut -d"=" -f2)
|
|
|
|
sudo grub-set-default "${GRUB_DEFAULT_ENTRY}"
|
2016-12-19 17:45:17 +01:00
|
|
|
sudo update-grub
|
2019-03-13 20:39:14 +01:00
|
|
|
printf '%b' "Please launch this script once again.\\n"
|
2016-12-19 17:45:17 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|