From 177a2a24b575e8ddf83ba220c3b0c92082c300b0 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Wed, 13 Mar 2019 20:39:14 +0100 Subject: [PATCH] winboot: check all grub conf files --- winboot | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/winboot b/winboot index a02dc83..7944e29 100755 --- a/winboot +++ b/winboot @@ -1,20 +1,31 @@ #!/bin/sh 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}" then - printf '%b' "Reboot to windaube partition\n" + printf '%b' "Reboot to windaube partition\\n" sudo grub-reboot "${WIN_GRUB}" sudo systemctl reboot 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}" GRUB_DEFAULT_ENTRY=$(grep -E -- "#GRUB_DEFAULT=" "${GRUB_DEFAULT_PATH}" | cut -d"=" -f2) sudo grub-set-default "${GRUB_DEFAULT_ENTRY}" sudo update-grub - printf '%b' "Please launch this script once again.\n" + printf '%b' "Please launch this script once again.\\n" fi exit 0