Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / util / grub-reboot.in
blob93dbe6cdcb0435350331b8eadbe4cb7831277511
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 transform="@program_transform_name@"
22 prefix=@prefix@
23 exec_prefix=@exec_prefix@
24 bindir=@bindir@
25 PACKAGE_NAME=@PACKAGE_NAME@
26 PACKAGE_VERSION=@PACKAGE_VERSION@
27 datarootdir="@datarootdir@"
28 datadir="@datadir@"
29 if [ "x$pkgdatadir" = x ]; then
30 pkgdatadir="${datadir}/@PACKAGE@"
33 self=`basename $0`
35 grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
36 rootdir=
37 bootdir=
38 grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
40 export TEXTDOMAIN=@PACKAGE@
41 export TEXTDOMAINDIR="@localedir@"
43 . "${pkgdatadir}/grub-mkconfig_lib"
45 # Usage: usage
46 # Print the usage.
47 usage () {
48 gettext_printf "Usage: %s [OPTION] MENU_ENTRY\n" "$self"
49 gettext "Set the default boot menu entry for GRUB, for the next boot only."; echo
50 echo
51 print_option_help "-h, --help" "$(gettext "print this message and exit")"
52 print_option_help "-v, --version" "$(gettext "print the version information and exit")"
53 dirmsg="$(gettext_printf "expect GRUB images under the directory DIR/%s instead of the %s directory" "@grubdirname@" "$grubdir")"
54 print_option_help "--boot-directory=$(gettext "DIR")" "$dirmsg"
55 echo
56 gettext "MENU_ENTRY is a number, a menu item title or a menu item identifier."; echo
57 echo
58 gettext "Report bugs to <bug-grub@gnu.org>."; echo
61 argument () {
62 opt=$1
63 shift
65 if test $# -eq 0; then
66 gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
67 exit 1
69 echo $1
72 # Check the arguments.
73 while test $# -gt 0
75 option=$1
76 shift
78 case "$option" in
79 -h | --help)
80 usage
81 exit 0 ;;
82 -v | --version)
83 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
84 exit 0 ;;
86 # Accept for compatibility
87 --root-directory)
88 rootdir=`argument $option "$@"`; shift ;;
89 --root-directory=*)
90 rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
92 --boot-directory)
93 bootdir=`argument $option "$@"`; shift;;
94 --boot-directory=*)
95 bootdir=`echo "$option" | sed 's/--boot-directory=//'` ;;
97 -*)
98 gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
99 usage
100 exit 1
103 if test "x$entry" != x; then
104 gettext "More than one menu entry?" 1>&2
105 echo >&2
106 usage
107 exit 1
109 entry="${option}" ;;
110 esac
111 done
113 if test "x$entry" = x; then
114 gettext "Menu entry not specified." 1>&2
115 echo >&2
116 usage
117 exit 1
120 if [ -z "$bootdir" ]; then
121 # Default bootdir if bootdir not initialized.
122 bootdir=/@bootdirname@
124 if [ -n "$rootdir" ] ; then
125 # Initialize bootdir if rootdir was initialized.
126 bootdir=${rootdir}/@bootdirname@
130 grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
132 prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
133 if [ "$prev_saved_entry" ]; then
134 $grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry"
135 else
136 # We need some non-empty value for prev_saved_entry so that GRUB will
137 # recognise that grub-reboot has been used and restore the previous
138 # saved entry. "0" is the same as an empty value, i.e. the first menu
139 # entry.
140 $grub_editenv ${grubdir}/grubenv set prev_saved_entry=0
142 $grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
144 # Bye.
145 exit 0