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