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@"
23 exec_prefix
=@exec_prefix@
25 PACKAGE_NAME
=@PACKAGE_NAME@
26 PACKAGE_VERSION
=@PACKAGE_VERSION@
27 datarootdir
="@datarootdir@"
29 if [ "x$pkgdatadir" = x
]; then
30 pkgdatadir
="${datadir}/@PACKAGE_TARNAME@"
35 grub_editenv
=${bindir}/`echo grub-editenv | sed ${transform}`
38 grubdir
=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
40 .
"${pkgdatadir}/grub-mkconfig_lib"
45 gettext_printf
"Usage: %s [OPTION] MENU_ENTRY\n" "$self"
46 gettext "Set the default boot menu entry for GRUB, for the next boot only."; echo
48 printf " -h, --help %s\n" "$(gettext "print this message and
exit")"
49 printf " -v, --version %s\n" "$(gettext "print the version information and
exit")"
50 dirmsg
="$(gettext_printf "expect GRUB images under the directory DIR
/%s instead of the
%s directory
" "@grubdirname@
" "$grubdir")"
51 printf " --boot-directory=%-7s%s\n" "$(gettext "DIR
")" "$dirmsg"
53 gettext "MENU_ENTRY is a number or a menu item title."; echo
55 gettext "Report bugs to <bug-grub@gnu.org>."; echo
62 if test $# -eq 0; then
63 gettext_printf
"%s: option requires an argument -- '%s'\n" "$0" "$opt" 1>&2
69 # Check the arguments.
80 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
83 # Accept for compatibility
85 rootdir
=`argument $option "$@"`; shift ;;
87 rootdir
=`echo "$option" | sed 's/--root-directory=//'` ;;
90 bootdir
=`argument $option "$@"`; shift;;
92 bootdir
=`echo "$option" | sed 's/--boot-directory=//'` ;;
95 gettext_printf
"Unrecognized option \`%s'\n" "$option" 1>&2
100 if test "x$entry" != x
; then
101 gettext "More than one menu entry?" 1>&2
110 if test "x$entry" = x
; then
111 gettext "menu entry not specified." 1>&2
117 if [ -z "$bootdir" ]; then
118 # Default bootdir if bootdir not initialized.
119 bootdir
=/@bootdirname@
121 if [ -n "$rootdir" ] ; then
122 # Initialize bootdir if rootdir was initialized.
123 bootdir
=${rootdir}/@bootdirname@
127 grubdir
=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
129 prev_saved_entry
=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
130 if [ "$prev_saved_entry" ]; then
131 $grub_editenv ${grubdir}/grubenv
set prev_saved_entry
="$prev_saved_entry"
133 # We need some non-empty value for prev_saved_entry so that GRUB will
134 # recognise that grub-reboot has been used and restore the previous
135 # saved entry. "0" is the same as an empty value, i.e. the first menu
137 $grub_editenv ${grubdir}/grubenv
set prev_saved_entry
=0
139 $grub_editenv ${grubdir}/grubenv
set saved_entry
="$entry"