]>
Commit | Line | Data |
---|---|---|
1246efeb CW |
1 | #! /bin/sh |
2 | set -e | |
ebd97f6e | 3 | |
4 | # Generate grub.cfg by inspecting /boot contents. | |
d500ed12 | 5 | # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. |
ebd97f6e | 6 | # |
5a79f472 | 7 | # GRUB is free software: you can redistribute it and/or modify |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation, either version 3 of the License, or | |
ebd97f6e | 10 | # (at your option) any later version. |
11 | # | |
5a79f472 | 12 | # GRUB is distributed in the hope that it will be useful, |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
ebd97f6e | 16 | # |
17 | # You should have received a copy of the GNU General Public License | |
5a79f472 | 18 | # along with GRUB. If not, see <http://www.gnu.org/licenses/>. |
ebd97f6e | 19 | |
20 | transform="@program_transform_name@" | |
48b391e9 VS |
21 | prefix="@prefix@" |
22 | exec_prefix="@exec_prefix@" | |
23 | datarootdir="@datarootdir@" | |
24 | ||
25 | prefix="@prefix@" | |
26 | exec_prefix="@exec_prefix@" | |
27 | sbindir="@sbindir@" | |
28 | bindir="@bindir@" | |
29 | sysconfdir="@sysconfdir@" | |
0ea7c4f9 GS |
30 | PACKAGE_NAME=@PACKAGE_NAME@ |
31 | PACKAGE_VERSION=@PACKAGE_VERSION@ | |
38e55e90 | 32 | host_os=@host_os@ |
48b391e9 | 33 | datadir="@datadir@" |
c8d9ead6 | 34 | if [ "x$pkgdatadir" = x ]; then |
2311c5ca | 35 | pkgdatadir="${datadir}/@PACKAGE@" |
c8d9ead6 | 36 | fi |
18ade780 | 37 | grub_cfg="" |
48b391e9 | 38 | grub_mkconfig_dir="${sysconfdir}"/grub.d |
2e610d62 | 39 | |
0ea7c4f9 GS |
40 | self=`basename $0` |
41 | ||
48b391e9 | 42 | grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`" |
4417aae6 | 43 | grub_script_check="${bindir}/`echo grub-script-check | sed "${transform}"`" |
ebd97f6e | 44 | |
9cc3ee5c VS |
45 | export TEXTDOMAIN=@PACKAGE@ |
46 | export TEXTDOMAINDIR="@localedir@" | |
47 | ||
c8d9ead6 | 48 | . "${pkgdatadir}/grub-mkconfig_lib" |
a32d5c71 | 49 | |
68807e5f | 50 | # Usage: usage |
51 | # Print the usage. | |
52 | usage () { | |
a32d5c71 VS |
53 | gettext_printf "Usage: %s [OPTION]\n" "$self" |
54 | gettext "Generate a grub config file"; echo | |
55 | echo | |
56 | printf " -o, --output=%-11s%s\n" "$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")" | |
57 | printf " -h, --help %s\n" "$(gettext "print this message and exit")" | |
58 | printf " -v, --version %s\n" "$(gettext "print the version information and exit")" | |
59 | echo | |
60 | gettext "Report bugs to <bug-grub@gnu.org>."; echo | |
68807e5f | 61 | } |
62 | ||
b02c7c8f BC |
63 | argument () { |
64 | opt=$1 | |
65 | shift | |
66 | ||
67 | if test $# -eq 0; then | |
a32d5c71 | 68 | gettext_printf "%s: option requires an argument -- '%s'" "$0" "$opt" 1>&2 |
b02c7c8f BC |
69 | exit 1 |
70 | fi | |
71 | echo $1 | |
72 | } | |
73 | ||
68807e5f | 74 | # Check the arguments. |
7a64e28d BC |
75 | while test $# -gt 0 |
76 | do | |
77 | option=$1 | |
78 | shift | |
79 | ||
68807e5f | 80 | case "$option" in |
81 | -h | --help) | |
82 | usage | |
83 | exit 0 ;; | |
84 | -v | --version) | |
0ea7c4f9 | 85 | echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" |
68807e5f | 86 | exit 0 ;; |
7a64e28d | 87 | -o | --output) |
b02c7c8f | 88 | grub_cfg=`argument $option "$@"`; shift;; |
880fc3c4 | 89 | --output=*) |
18ade780 | 90 | grub_cfg=`echo "$option" | sed 's/--output=//'` |
b39f9d20 | 91 | ;; |
68807e5f | 92 | -*) |
a32d5c71 | 93 | gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2 |
68807e5f | 94 | usage |
95 | exit 1 | |
96 | ;; | |
044e2e60 | 97 | # Explicitly ignore non-option arguments, for compatibility. |
68807e5f | 98 | esac |
99 | done | |
100 | ||
991477f8 | 101 | if [ "x$EUID" = "x" ] ; then |
102 | EUID=`id -u` | |
ebd97f6e | 103 | fi |
104 | ||
991477f8 | 105 | if [ "$EUID" != 0 ] ; then |
b609876d | 106 | root=f |
107 | case "`uname 2>/dev/null`" in | |
108 | CYGWIN*) | |
109 | # Cygwin: Assume root if member of admin group | |
110 | for g in `id -G 2>/dev/null` ; do | |
111 | case $g in | |
112 | 0|544) root=t ;; | |
113 | esac | |
114 | done ;; | |
115 | esac | |
116 | if [ $root != t ] ; then | |
a32d5c71 | 117 | gettext_printf "%s: You must run this as root\n" "$self" >&2 |
b609876d | 118 | exit 1 |
119 | fi | |
ebd97f6e | 120 | fi |
121 | ||
2e610d62 | 122 | set $grub_probe dummy |
123 | if test -f "$1"; then | |
124 | : | |
125 | else | |
a32d5c71 | 126 | gettext_print "%s: Not found.\n" "$1" 1>&2 |
2e610d62 | 127 | exit 1 |
ebd97f6e | 128 | fi |
129 | ||
cc85c3c3 | 130 | # Device containing our userland. Typically used for root= parameter. |
69ba137e | 131 | GRUB_DEVICE="`${grub_probe} --target=device /`" |
132 | GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true | |
62191274 | 133 | |
134 | # Device containing our /boot partition. Usually the same as GRUB_DEVICE. | |
69ba137e | 135 | GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`" |
136 | GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true | |
57f96397 | 137 | |
138 | # Filesystem for the device containing our userland. Used for stuff like | |
139 | # choosing Hurd filesystem module. | |
99fd620d | 140 | GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`" |
57f96397 | 141 | |
ebd97f6e | 142 | if test -f ${sysconfdir}/default/grub ; then |
143 | . ${sysconfdir}/default/grub | |
144 | fi | |
145 | ||
651c29b7 | 146 | # XXX: should this be deprecated at some point? |
147 | if [ "x${GRUB_TERMINAL}" != "x" ] ; then | |
148 | GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}" | |
149 | GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}" | |
150 | fi | |
151 | ||
d5631db0 | 152 | termoutdefault=0 |
38e55e90 | 153 | if [ "x${GRUB_TERMINAL_OUTPUT}" = "x" ]; then |
d5631db0 VS |
154 | GRUB_TERMINAL_OUTPUT=gfxterm; |
155 | termoutdefault=1; | |
156 | fi | |
157 | ||
d5631db0 VS |
158 | for x in ${GRUB_TERMINAL_OUTPUT}; do |
159 | case "x${x}" in | |
160 | xgfxterm) ;; | |
161 | xconsole | xserial | xofconsole) | |
162 | # make sure all our children behave in conformance with ascii.. | |
163 | export LANG=C;; | |
164 | *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;; | |
165 | esac | |
166 | done | |
6193defe | 167 | |
57f96397 | 168 | # These are defined in this script, export them here so that user can |
169 | # override them. | |
9a10df16 | 170 | export GRUB_DEVICE \ |
171 | GRUB_DEVICE_UUID \ | |
172 | GRUB_DEVICE_BOOT \ | |
173 | GRUB_DEVICE_BOOT_UUID \ | |
174 | GRUB_FS \ | |
274416e8 | 175 | GRUB_FONT \ |
47454da5 | 176 | GRUB_PRELOAD_MODULES |
57f96397 | 177 | |
178 | # These are optional, user-defined variables. | |
9a10df16 | 179 | export GRUB_DEFAULT \ |
180 | GRUB_HIDDEN_TIMEOUT \ | |
181 | GRUB_HIDDEN_TIMEOUT_QUIET \ | |
182 | GRUB_TIMEOUT \ | |
76e6d0d7 VS |
183 | GRUB_DEFAULT_BUTTON \ |
184 | GRUB_HIDDEN_TIMEOUT_BUTTON \ | |
185 | GRUB_TIMEOUT_BUTTON \ | |
186 | GRUB_BUTTON_CMOS_ADDRESS \ | |
eaf41b25 | 187 | GRUB_BUTTON_CMOS_CLEAN \ |
9a10df16 | 188 | GRUB_DISTRIBUTOR \ |
189 | GRUB_CMDLINE_LINUX \ | |
190 | GRUB_CMDLINE_LINUX_DEFAULT \ | |
19dcc490 VS |
191 | GRUB_CMDLINE_XEN \ |
192 | GRUB_CMDLINE_XEN_DEFAULT \ | |
f35fa3a6 CW |
193 | GRUB_CMDLINE_LINUX_XEN_REPLACE \ |
194 | GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \ | |
0d2c20c6 GS |
195 | GRUB_CMDLINE_NETBSD \ |
196 | GRUB_CMDLINE_NETBSD_DEFAULT \ | |
ac96441c | 197 | GRUB_CMDLINE_GNUMACH \ |
9a10df16 | 198 | GRUB_TERMINAL_INPUT \ |
199 | GRUB_TERMINAL_OUTPUT \ | |
200 | GRUB_SERIAL_COMMAND \ | |
201 | GRUB_DISABLE_LINUX_UUID \ | |
219b3564 | 202 | GRUB_DISABLE_RECOVERY \ |
e4311a9f | 203 | GRUB_VIDEO_BACKEND \ |
5174302b | 204 | GRUB_GFXMODE \ |
d7c43ba1 | 205 | GRUB_BACKGROUND \ |
eb1c9594 | 206 | GRUB_THEME \ |
65a533e7 | 207 | GRUB_GFXPAYLOAD_LINUX \ |
0a39de87 | 208 | GRUB_DISABLE_OS_PROBER \ |
a0ca21c2 | 209 | GRUB_INIT_TUNE \ |
d500ed12 | 210 | GRUB_SAVEDEFAULT \ |
20a40940 | 211 | GRUB_ENABLE_CRYPTODISK \ |
d500ed12 | 212 | GRUB_BADRAM |
57f96397 | 213 | |
18ade780 | 214 | if test "x${grub_cfg}" != "x"; then |
055f856f MW |
215 | rm -f "${grub_cfg}.new" |
216 | oldumask=$(umask); umask 077 | |
217 | exec > "${grub_cfg}.new" | |
218 | umask $oldumask | |
18ade780 | 219 | fi |
a32d5c71 VS |
220 | gettext "Generating grub.cfg ..." >&2 |
221 | echo >&2 | |
ebd97f6e | 222 | |
223 | cat << EOF | |
224 | # | |
225 | # DO NOT EDIT THIS FILE | |
226 | # | |
0ea7c4f9 | 227 | # It is automatically generated by $self using templates |
f6fd460a | 228 | # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub |
ebd97f6e | 229 | # |
230 | EOF | |
231 | ||
18ade780 | 232 | for i in ${grub_mkconfig_dir}/* ; do |
53b052de | 233 | case "$i" in |
ebd97f6e | 234 | # emacsen backup files. FIXME: support other editors |
235 | *~) ;; | |
6d1fa41f MZ |
236 | # emacsen autosave files. FIXME: support other editors |
237 | \#*\#) ;; | |
ebd97f6e | 238 | *) |
2f80039d | 239 | if grub_file_is_not_garbage "$i" && test -x "$i" ; then |
ebd97f6e | 240 | echo |
241 | echo "### BEGIN $i ###" | |
53b052de | 242 | "$i" |
ebd97f6e | 243 | echo "### END $i ###" |
244 | fi | |
245 | ;; | |
246 | esac | |
247 | done | |
248 | ||
18ade780 | 249 | if test "x${grub_cfg}" != "x" ; then |
4417aae6 | 250 | if ! ${grub_script_check} ${grub_cfg}.new; then |
a32d5c71 VS |
251 | gettext_printf "Syntax errors are detected in generated GRUB config file. |
252 | Ensure that there are no errors in /etc/default/grub | |
253 | and /etc/grub.d/* files or please file a bug report with | |
254 | %s file attached." "${grub_cfg}.new" >&2 | |
75d8c629 | 255 | else |
256 | # none of the children aborted with error, install the new grub.cfg | |
257 | mv -f ${grub_cfg}.new ${grub_cfg} | |
258 | fi | |
18ade780 | 259 | fi |
ebd97f6e | 260 | |
a32d5c71 VS |
261 | gettext "done" >&2 |
262 | echo >&2 |