diff options
author | Egor Tensin <egor@tensin.name> | 2025-09-08 11:45:26 +0200 |
---|---|---|
committer | Egor Tensin <egor@tensin.name> | 2025-09-08 11:46:18 +0200 |
commit | 2b2d6a152de2ba6dd90fe0687d136e2eb6ccd989 (patch) | |
tree | 452dd1728bea59b2abe1102c109e02666a2d719c /bin/reboot-into-windows | |
parent | aur: 0.2-1 (diff) | |
download | grub-reboot-into-windows-2b2d6a152de2ba6dd90fe0687d136e2eb6ccd989.tar.gz grub-reboot-into-windows-2b2d6a152de2ba6dd90fe0687d136e2eb6ccd989.zip |
split AUR-related stuff to the aur branch
Diffstat (limited to 'bin/reboot-into-windows')
-rwxr-xr-x | bin/reboot-into-windows | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/bin/reboot-into-windows b/bin/reboot-into-windows new file mode 100755 index 0000000..a6584b9 --- /dev/null +++ b/bin/reboot-into-windows @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit lastpipe + +readonly cfg_path=/boot/grub/grub.cfg + +get_windows_menu_entry() { + local windows_entries + windows_entries="$( awk -F\' '/menuentry / {print $2}' "$cfg_path" | grep -Fi Windows )" + + local numof_entries + numof_entries="$( echo "$windows_entries" | wc -l )" + + if [ "$numof_entries" -ne 1 ]; then + echo "Don't know which one of the following entries to select:" >&2 + echo "$windows_entries" >&2 + return 1 + fi + + echo "$windows_entries" +} + +main() { + local entry + entry="$( get_windows_menu_entry )" + + # grub-reboot returns 0 even if something like a permission error happens. + # It does print something in that case though, and nothing after a + # successful termination. + local output + output="$( grub-reboot "$entry" )" + + if [ -n "$output" ]; then + echo "grub-reboot probably exited with an error:" >&2 + echo "$output" >&2 + return 1 + fi + + reboot +} + +main |