]> git.proxmox.com Git - grub2.git/blob - util/grub-reboot.in
Another round of string clarification and adding TRANSLATORS comments.
[grub2.git] / util / grub-reboot.in
1 #! /bin/sh
2 #
3 # Set a default boot entry for GRUB, for the next boot only.
4 # Copyright (C) 2004,2009 Free Software Foundation, Inc.
5 #
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.
10 #
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.
15 #
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/>.
18
19 # Initialize some variables.
20 transform="@program_transform_name@"
21
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}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`"
31 fi
32
33 self=`basename $0`
34
35 grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
36 rootdir=
37 bootdir=
38 grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
39
40 . "${pkgdatadir}/grub-mkconfig_lib"
41
42 # Usage: usage
43 # Print the usage.
44 usage () {
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
47 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"
52 echo
53 gettext "MENU_ENTRY is a number or a menu item title."; echo
54 echo
55 gettext "Report bugs to <bug-grub@gnu.org>."; echo
56 }
57
58 argument () {
59 opt=$1
60 shift
61
62 if test $# -eq 0; then
63 gettext_printf "%s: option requires an argument -- '%s'\n" "$0" "$opt" 1>&2
64 exit 1
65 fi
66 echo $1
67 }
68
69 # Check the arguments.
70 while test $# -gt 0
71 do
72 option=$1
73 shift
74
75 case "$option" in
76 -h | --help)
77 usage
78 exit 0 ;;
79 -v | --version)
80 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
81 exit 0 ;;
82
83 # Accept for compatibility
84 --root-directory)
85 rootdir=`argument $option "$@"`; shift ;;
86 --root-directory=*)
87 rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
88
89 --boot-directory)
90 bootdir=`argument $option "$@"`; shift;;
91 --boot-directory=*)
92 bootdir=`echo "$option" | sed 's/--boot-directory=//'` ;;
93
94 -*)
95 gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
96 usage
97 exit 1
98 ;;
99 *)
100 if test "x$entry" != x; then
101 gettext "More than one menu entry?" 1>&2
102 echo >&2
103 usage
104 exit 1
105 fi
106 entry="${option}" ;;
107 esac
108 done
109
110 if test "x$entry" = x; then
111 gettext "menu entry not specified." 1>&2
112 echo >&2
113 usage
114 exit 1
115 fi
116
117 if [ -z "$bootdir" ]; then
118 # Default bootdir if bootdir not initialized.
119 bootdir=/@bootdirname@
120
121 if [ -n "$rootdir" ] ; then
122 # Initialize bootdir if rootdir was initialized.
123 bootdir=${rootdir}/@bootdirname@
124 fi
125 fi
126
127 grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
128
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"
132 else
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
136 # entry.
137 $grub_editenv ${grubdir}/grubenv set prev_saved_entry=0
138 fi
139 $grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
140
141 # Bye.
142 exit 0