]> git.proxmox.com Git - grub2.git/blob - util/grub-mkconfig.in
Replace PACKAGE_TARNAME with PACKAGE in pkglibdir and pkgdatadir.
[grub2.git] / util / grub-mkconfig.in
1 #! /bin/sh
2 set -e
3
4 # Generate grub.cfg by inspecting /boot contents.
5 # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
6 #
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
10 # (at your option) any later version.
11 #
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.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19
20 transform="@program_transform_name@"
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@"
30 PACKAGE_NAME=@PACKAGE_NAME@
31 PACKAGE_VERSION=@PACKAGE_VERSION@
32 host_os=@host_os@
33 datadir="@datadir@"
34 if [ "x$pkgdatadir" = x ]; then
35 pkgdatadir="${datadir}/@PACKAGE@"
36 fi
37 grub_cfg=""
38 grub_mkconfig_dir="${sysconfdir}"/grub.d
39
40 self=`basename $0`
41
42 grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`"
43 grub_script_check="${bindir}/`echo grub-script-check | sed "${transform}"`"
44
45 . "${pkgdatadir}/grub-mkconfig_lib"
46
47 # Usage: usage
48 # Print the usage.
49 usage () {
50 gettext_printf "Usage: %s [OPTION]\n" "$self"
51 gettext "Generate a grub config file"; echo
52 echo
53 printf " -o, --output=%-11s%s\n" "$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")"
54 printf " -h, --help %s\n" "$(gettext "print this message and exit")"
55 printf " -v, --version %s\n" "$(gettext "print the version information and exit")"
56 echo
57 gettext "Report bugs to <bug-grub@gnu.org>."; echo
58 }
59
60 argument () {
61 opt=$1
62 shift
63
64 if test $# -eq 0; then
65 gettext_printf "%s: option requires an argument -- '%s'" "$0" "$opt" 1>&2
66 exit 1
67 fi
68 echo $1
69 }
70
71 # Check the arguments.
72 while test $# -gt 0
73 do
74 option=$1
75 shift
76
77 case "$option" in
78 -h | --help)
79 usage
80 exit 0 ;;
81 -v | --version)
82 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
83 exit 0 ;;
84 -o | --output)
85 grub_cfg=`argument $option "$@"`; shift;;
86 --output=*)
87 grub_cfg=`echo "$option" | sed 's/--output=//'`
88 ;;
89 -*)
90 gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
91 usage
92 exit 1
93 ;;
94 # Explicitly ignore non-option arguments, for compatibility.
95 esac
96 done
97
98 if [ "x$EUID" = "x" ] ; then
99 EUID=`id -u`
100 fi
101
102 if [ "$EUID" != 0 ] ; then
103 root=f
104 case "`uname 2>/dev/null`" in
105 CYGWIN*)
106 # Cygwin: Assume root if member of admin group
107 for g in `id -G 2>/dev/null` ; do
108 case $g in
109 0|544) root=t ;;
110 esac
111 done ;;
112 esac
113 if [ $root != t ] ; then
114 gettext_printf "%s: You must run this as root\n" "$self" >&2
115 exit 1
116 fi
117 fi
118
119 set $grub_probe dummy
120 if test -f "$1"; then
121 :
122 else
123 gettext_print "%s: Not found.\n" "$1" 1>&2
124 exit 1
125 fi
126
127 # Device containing our userland. Typically used for root= parameter.
128 GRUB_DEVICE="`${grub_probe} --target=device /`"
129 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
130
131 # Device containing our /boot partition. Usually the same as GRUB_DEVICE.
132 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
133 GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
134
135 # Filesystem for the device containing our userland. Used for stuff like
136 # choosing Hurd filesystem module.
137 GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"
138
139 if test -f ${sysconfdir}/default/grub ; then
140 . ${sysconfdir}/default/grub
141 fi
142
143 # XXX: should this be deprecated at some point?
144 if [ "x${GRUB_TERMINAL}" != "x" ] ; then
145 GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}"
146 GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}"
147 fi
148
149 termoutdefault=0
150 if [ "x${GRUB_TERMINAL_OUTPUT}" = "x" ]; then
151 GRUB_TERMINAL_OUTPUT=gfxterm;
152 termoutdefault=1;
153 fi
154
155 for x in ${GRUB_TERMINAL_OUTPUT}; do
156 case "x${x}" in
157 xgfxterm) ;;
158 xconsole | xserial | xofconsole)
159 # make sure all our children behave in conformance with ascii..
160 export LANG=C;;
161 *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
162 esac
163 done
164
165 # These are defined in this script, export them here so that user can
166 # override them.
167 export GRUB_DEVICE \
168 GRUB_DEVICE_UUID \
169 GRUB_DEVICE_BOOT \
170 GRUB_DEVICE_BOOT_UUID \
171 GRUB_FS \
172 GRUB_FONT \
173 GRUB_PRELOAD_MODULES
174
175 # These are optional, user-defined variables.
176 export GRUB_DEFAULT \
177 GRUB_HIDDEN_TIMEOUT \
178 GRUB_HIDDEN_TIMEOUT_QUIET \
179 GRUB_TIMEOUT \
180 GRUB_DEFAULT_BUTTON \
181 GRUB_HIDDEN_TIMEOUT_BUTTON \
182 GRUB_TIMEOUT_BUTTON \
183 GRUB_BUTTON_CMOS_ADDRESS \
184 GRUB_BUTTON_CMOS_CLEAN \
185 GRUB_DISTRIBUTOR \
186 GRUB_CMDLINE_LINUX \
187 GRUB_CMDLINE_LINUX_DEFAULT \
188 GRUB_CMDLINE_XEN \
189 GRUB_CMDLINE_XEN_DEFAULT \
190 GRUB_CMDLINE_LINUX_XEN_REPLACE \
191 GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \
192 GRUB_CMDLINE_NETBSD \
193 GRUB_CMDLINE_NETBSD_DEFAULT \
194 GRUB_CMDLINE_GNUMACH \
195 GRUB_TERMINAL_INPUT \
196 GRUB_TERMINAL_OUTPUT \
197 GRUB_SERIAL_COMMAND \
198 GRUB_DISABLE_LINUX_UUID \
199 GRUB_DISABLE_RECOVERY \
200 GRUB_VIDEO_BACKEND \
201 GRUB_GFXMODE \
202 GRUB_BACKGROUND \
203 GRUB_THEME \
204 GRUB_GFXPAYLOAD_LINUX \
205 GRUB_DISABLE_OS_PROBER \
206 GRUB_INIT_TUNE \
207 GRUB_SAVEDEFAULT \
208 GRUB_ENABLE_CRYPTODISK \
209 GRUB_BADRAM
210
211 if test "x${grub_cfg}" != "x"; then
212 rm -f "${grub_cfg}.new"
213 oldumask=$(umask); umask 077
214 exec > "${grub_cfg}.new"
215 umask $oldumask
216 fi
217 gettext "Generating grub.cfg ..." >&2
218 echo >&2
219
220 cat << EOF
221 #
222 # DO NOT EDIT THIS FILE
223 #
224 # It is automatically generated by $self using templates
225 # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
226 #
227 EOF
228
229 for i in ${grub_mkconfig_dir}/* ; do
230 case "$i" in
231 # emacsen backup files. FIXME: support other editors
232 *~) ;;
233 # emacsen autosave files. FIXME: support other editors
234 \#*\#) ;;
235 *)
236 if grub_file_is_not_garbage "$i" && test -x "$i" ; then
237 echo
238 echo "### BEGIN $i ###"
239 "$i"
240 echo "### END $i ###"
241 fi
242 ;;
243 esac
244 done
245
246 if test "x${grub_cfg}" != "x" ; then
247 if ! ${grub_script_check} ${grub_cfg}.new; then
248 gettext_printf "Syntax errors are detected in generated GRUB config file.
249 Ensure that there are no errors in /etc/default/grub
250 and /etc/grub.d/* files or please file a bug report with
251 %s file attached." "${grub_cfg}.new" >&2
252 else
253 # none of the children aborted with error, install the new grub.cfg
254 mv -f ${grub_cfg}.new ${grub_cfg}
255 fi
256 fi
257
258 gettext "done" >&2
259 echo >&2