From 6ebedc72e1e0d6d1c824915a73d51e1f8925af77 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 10 Sep 2025 11:35:49 +0200 Subject: de-hardcode names --- bin/.gitattributes | 2 +- bin/grub-reboot-into-windows | 43 ------------------------------------------- bin/script | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 44 deletions(-) delete mode 100755 bin/grub-reboot-into-windows create mode 100755 bin/script (limited to 'bin') diff --git a/bin/.gitattributes b/bin/.gitattributes index 713687e..4ace0b5 100644 --- a/bin/.gitattributes +++ b/bin/.gitattributes @@ -1 +1 @@ -grub-reboot-into-windows text eol=lf +script text eol=lf diff --git a/bin/grub-reboot-into-windows b/bin/grub-reboot-into-windows deleted file mode 100755 index a6584b9..0000000 --- a/bin/grub-reboot-into-windows +++ /dev/null @@ -1,43 +0,0 @@ -#!/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 diff --git a/bin/script b/bin/script new file mode 100755 index 0000000..a6584b9 --- /dev/null +++ b/bin/script @@ -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 -- cgit v1.2.3