]>
Commit | Line | Data |
---|---|---|
ebd97f6e | 1 | #! /bin/sh -e |
2 | ||
3 | # Generate grub.cfg by inspecting /boot contents. | |
f6fd460a | 4 | # Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. |
ebd97f6e | 5 | # |
5a79f472 | 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 | |
ebd97f6e | 9 | # (at your option) any later version. |
10 | # | |
5a79f472 | 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. | |
ebd97f6e | 15 | # |
16 | # You should have received a copy of the GNU General Public License | |
5a79f472 | 17 | # along with GRUB. If not, see <http://www.gnu.org/licenses/>. |
ebd97f6e | 18 | |
19 | transform="@program_transform_name@" | |
20 | ||
2e610d62 | 21 | prefix=@prefix@ |
22 | exec_prefix=@exec_prefix@ | |
23 | sbindir=@sbindir@ | |
42c71976 | 24 | libdir=@libdir@ |
ebd97f6e | 25 | sysconfdir=@sysconfdir@ |
26 | grub_prefix=`echo /boot/grub | sed ${transform}` | |
18ade780 | 27 | grub_cfg="" |
28 | grub_mkconfig_dir=${sysconfdir}/grub.d | |
2e610d62 | 29 | |
30 | grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` | |
31 | grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` | |
ebd97f6e | 32 | |
68807e5f | 33 | # Usage: usage |
34 | # Print the usage. | |
35 | usage () { | |
36 | cat <<EOF | |
37 | Usage: $0 [OPTION] | |
18ade780 | 38 | Generate a grub config file |
68807e5f | 39 | |
18ade780 | 40 | -o, --output=FILE output generated config to FILE [default=stdout] |
68807e5f | 41 | -h, --help print this message and exit |
42 | -v, --version print the version information and exit | |
68807e5f | 43 | |
44 | Report bugs to <bug-grub@gnu.org>. | |
45 | EOF | |
46 | } | |
47 | ||
48 | # Check the arguments. | |
49 | for option in "$@"; do | |
50 | case "$option" in | |
51 | -h | --help) | |
52 | usage | |
53 | exit 0 ;; | |
54 | -v | --version) | |
55 | echo "$0 (GNU GRUB ${PACKAGE_VERSION})" | |
56 | exit 0 ;; | |
18ade780 | 57 | -o) |
58 | shift | |
59 | grub_cfg=$1 | |
60 | ;; | |
61 | --output=) | |
62 | grub_cfg=`echo "$option" | sed 's/--output=//'` | |
b39f9d20 | 63 | ;; |
68807e5f | 64 | -*) |
65 | echo "Unrecognized option \`$option'" 1>&2 | |
66 | usage | |
67 | exit 1 | |
68 | ;; | |
69 | esac | |
70 | done | |
71 | ||
18ade780 | 72 | . ${libdir}/grub/grub-mkconfig_lib |
42c71976 | 73 | |
991477f8 | 74 | if [ "x$EUID" = "x" ] ; then |
75 | EUID=`id -u` | |
ebd97f6e | 76 | fi |
77 | ||
991477f8 | 78 | if [ "$EUID" != 0 ] ; then |
b609876d | 79 | root=f |
80 | case "`uname 2>/dev/null`" in | |
81 | CYGWIN*) | |
82 | # Cygwin: Assume root if member of admin group | |
83 | for g in `id -G 2>/dev/null` ; do | |
84 | case $g in | |
85 | 0|544) root=t ;; | |
86 | esac | |
87 | done ;; | |
88 | esac | |
89 | if [ $root != t ] ; then | |
90 | echo "$0: You must run this as root" >&2 | |
91 | exit 1 | |
92 | fi | |
ebd97f6e | 93 | fi |
94 | ||
2e610d62 | 95 | set $grub_mkdevicemap dummy |
96 | if test -f "$1"; then | |
97 | : | |
98 | else | |
99 | echo "$1: Not found." 1>&2 | |
100 | exit 1 | |
ebd97f6e | 101 | fi |
102 | ||
2e610d62 | 103 | set $grub_probe dummy |
104 | if test -f "$1"; then | |
105 | : | |
106 | else | |
107 | echo "$1: Not found." 1>&2 | |
108 | exit 1 | |
ebd97f6e | 109 | fi |
110 | ||
2e610d62 | 111 | mkdir -p ${grub_prefix} |
112 | ||
113 | if test -e ${grub_prefix}/device.map ; then : ; else | |
74b21bee | 114 | ${grub_mkdevicemap} |
ebd97f6e | 115 | fi |
116 | ||
cc85c3c3 | 117 | # Device containing our userland. Typically used for root= parameter. |
69ba137e | 118 | GRUB_DEVICE="`${grub_probe} --target=device /`" |
119 | GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true | |
62191274 | 120 | |
121 | # Device containing our /boot partition. Usually the same as GRUB_DEVICE. | |
69ba137e | 122 | GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`" |
123 | GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true | |
57f96397 | 124 | |
125 | # Filesystem for the device containing our userland. Used for stuff like | |
126 | # choosing Hurd filesystem module. | |
69ba137e | 127 | GRUB_FS="`${grub_probe} --target=fs / 2> /dev/null || echo unknown`" |
57f96397 | 128 | |
ebd97f6e | 129 | if test -f ${sysconfdir}/default/grub ; then |
130 | . ${sysconfdir}/default/grub | |
131 | fi | |
132 | ||
651c29b7 | 133 | # XXX: should this be deprecated at some point? |
134 | if [ "x${GRUB_TERMINAL}" != "x" ] ; then | |
135 | GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}" | |
136 | GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}" | |
137 | fi | |
138 | ||
139 | case x${GRUB_TERMINAL_OUTPUT} in | |
52768e37 | 140 | x) |
141 | # If this platform supports gfxterm, try to use it. | |
142 | if test -e ${grub_prefix}/gfxterm.mod ; then | |
651c29b7 | 143 | GRUB_TERMINAL_OUTPUT=gfxterm |
52768e37 | 144 | fi |
145 | ;; | |
146 | xconsole | xserial | xofconsole | xgfxterm) ;; | |
651c29b7 | 147 | *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;; |
6193defe | 148 | esac |
149 | ||
150 | # check for terminals that require fonts | |
651c29b7 | 151 | case ${GRUB_TERMINAL_OUTPUT} in |
6193defe | 152 | gfxterm) |
1eb8c802 | 153 | if path=`font_path` ; then |
972e2f7a | 154 | GRUB_FONT_PATH="${path}" |
1eb8c802 | 155 | else |
52768e37 | 156 | # fallback to the native terminal for this platform |
651c29b7 | 157 | unset GRUB_TERMINAL_OUTPUT |
6193defe | 158 | fi |
159 | ;; | |
160 | esac | |
161 | ||
162 | # does our terminal support utf-8 ? | |
651c29b7 | 163 | case ${GRUB_TERMINAL_OUTPUT} in |
52768e37 | 164 | gfxterm) ;; |
165 | *) | |
6193defe | 166 | # make sure all our children behave in conformance with ascii.. |
167 | export LANG=C | |
168 | ;; | |
169 | esac | |
170 | ||
57f96397 | 171 | # These are defined in this script, export them here so that user can |
172 | # override them. | |
62191274 | 173 | export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_FS GRUB_FONT_PATH GRUB_PRELOAD_MODULES |
57f96397 | 174 | |
175 | # These are optional, user-defined variables. | |
59e5d3ec | 176 | export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL_INPUT GRUB_TERMINAL_OUTPUT GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID GRUB_GFXMODE |
57f96397 | 177 | |
18ade780 | 178 | if test "x${grub_cfg}" != "x"; then |
179 | rm -f ${grub_cfg}.new | |
180 | exec > ${grub_cfg}.new | |
57f96397 | 181 | |
18ade780 | 182 | # Allow this to fail, since /boot/grub/ might need to be fatfs to support some |
183 | # firmware implementations (e.g. OFW or EFI). | |
184 | chmod 444 ${grub_cfg}.new || true | |
185 | fi | |
186 | echo "Generating grub.cfg ..." >&2 | |
ebd97f6e | 187 | |
188 | cat << EOF | |
189 | # | |
190 | # DO NOT EDIT THIS FILE | |
191 | # | |
cc85c3c3 | 192 | # It is automatically generated by $0 using templates |
f6fd460a | 193 | # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub |
ebd97f6e | 194 | # |
195 | EOF | |
196 | ||
18ade780 | 197 | for i in ${grub_mkconfig_dir}/* ; do |
53b052de | 198 | case "$i" in |
ebd97f6e | 199 | # emacsen backup files. FIXME: support other editors |
200 | *~) ;; | |
201 | *) | |
2f80039d | 202 | if grub_file_is_not_garbage "$i" && test -x "$i" ; then |
ebd97f6e | 203 | echo |
204 | echo "### BEGIN $i ###" | |
53b052de | 205 | "$i" |
ebd97f6e | 206 | echo "### END $i ###" |
207 | fi | |
208 | ;; | |
209 | esac | |
210 | done | |
211 | ||
18ade780 | 212 | if test "x${grub_cfg}" != "x" ; then |
213 | # none of the children aborted with error, install the new grub.cfg | |
214 | mv -f ${grub_cfg}.new ${grub_cfg} | |
215 | fi | |
ebd97f6e | 216 | |
217 | echo "done" >&2 |