Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / util / grub-reboot.in
blob225fe5f218813befa313dffaf9732d779017a112
1 #! /bin/sh
3 # Set a default boot entry for GRUB, for the next boot only.
4 # Copyright (C) 2004,2009 Free Software Foundation, Inc.
6 # GRUB is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # GRUB is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 # Initialize some variables.
20 prefix=@prefix@
21 exec_prefix=@exec_prefix@
22 bindir=@bindir@
23 sysconfdir="@sysconfdir@"
24 PACKAGE_NAME=@PACKAGE_NAME@
25 PACKAGE_VERSION=@PACKAGE_VERSION@
26 datarootdir="@datarootdir@"
27 datadir="@datadir@"
28 if [ "x$pkgdatadir" = x ]; then
29 pkgdatadir="${datadir}/@PACKAGE@"
32 self=`basename $0`
34 grub_editenv=${bindir}/@grub_editenv@
35 rootdir=
36 bootdir=
37 grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
39 export TEXTDOMAIN=@PACKAGE@
40 export TEXTDOMAINDIR="@localedir@"
42 . "${pkgdatadir}/grub-mkconfig_lib"
44 # Usage: usage
45 # Print the usage.
46 usage () {
47 gettext_printf "Usage: %s [OPTION] MENU_ENTRY\n" "$self"
48 gettext "Set the default boot menu entry for GRUB, for the next boot only."; echo
49 print_option_help "-h, --help" "$(gettext "print this message and exit")"
50 print_option_help "-v, --version" "$(gettext "print the version information and exit")"
51 dirmsg="$(gettext_printf "expect GRUB images under the directory DIR/%s instead of the %s directory" "@grubdirname@" "$grubdir")"
52 print_option_help "--boot-directory=$(gettext "DIR")" "$dirmsg"
53 echo
54 gettext "MENU_ENTRY is a number, a menu item title or a menu item identifier. Please note that menu items in
55 submenus or sub-submenus require specifying the submenu components and then the
56 menu item component. The titles should be separated using the greater-than
57 character (>) with no extra spaces. Depending on your shell some characters including > may need escaping. More information about this is available
58 in the GRUB Manual in the section about the 'default' command. "; echo
59 echo
60 gettext "Report bugs to <bug-grub@gnu.org>."; echo
63 argument () {
64 opt=$1
65 shift
67 if test $# -eq 0; then
68 gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" "$opt" 1>&2
69 exit 1
71 echo $1
74 # Check the arguments.
75 while test $# -gt 0
77 option=$1
78 shift
80 case "$option" in
81 -h | --help)
82 usage
83 exit 0 ;;
84 -v | --version)
85 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
86 exit 0 ;;
88 # Accept for compatibility
89 --root-directory)
90 rootdir=`argument $option "$@"`; shift ;;
91 --root-directory=*)
92 rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
94 --boot-directory)
95 bootdir=`argument $option "$@"`; shift;;
96 --boot-directory=*)
97 bootdir=`echo "$option" | sed 's/--boot-directory=//'` ;;
99 -*)
100 gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
101 usage
102 exit 1
105 if test "x$entry" != x; then
106 gettext "More than one menu entry?" 1>&2
107 echo >&2
108 usage
109 exit 1
111 entry="${option}" ;;
112 esac
113 done
115 if test "x$entry" = x; then
116 gettext "Menu entry not specified." 1>&2
117 echo >&2
118 usage
119 exit 1
122 if [ -z "$bootdir" ]; then
123 # Default bootdir if bootdir not initialized.
124 bootdir=/@bootdirname@
126 if [ -n "$rootdir" ] ; then
127 # Initialize bootdir if rootdir was initialized.
128 bootdir=${rootdir}/@bootdirname@
132 grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
134 # Restore saved_entry if it was set by previous version
135 prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^prev_saved_entry=//p'`
136 if [ "$prev_saved_entry" ]; then
137 $grub_editenv ${grubdir}/grubenv set saved_entry="$prev_saved_entry"
138 $grub_editenv ${grubdir}/grubenv unset prev_saved_entry
141 $grub_editenv ${grubdir}/grubenv set next_entry="$entry"
143 # Bye.
144 exit 0