Update svn:ignore property
[grub2/jjazz.git] / util / grub-mkconfig.in
blob2d7510f83f50d7d33ddc6c7ad239faa76a341116
1 #! /bin/sh -e
3 # Generate grub.cfg by inspecting /boot contents.
4 # Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
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.
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.
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/>.
19 transform="@program_transform_name@"
21 prefix=@prefix@
22 exec_prefix=@exec_prefix@
23 sbindir=@sbindir@
24 libdir=@libdir@
25 sysconfdir=@sysconfdir@
26 grub_prefix=`echo /boot/grub | sed ${transform}`
27 grub_cfg=""
28 grub_mkconfig_dir=${sysconfdir}/grub.d
30 grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
31 grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
33 # Usage: usage
34 # Print the usage.
35 usage () {
36 cat <<EOF
37 Usage: $0 [OPTION]
38 Generate a grub config file
40 -o, --output=FILE output generated config to FILE [default=stdout]
41 -h, --help print this message and exit
42 -v, --version print the version information and exit
44 Report bugs to <bug-grub@gnu.org>.
45 EOF
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 ;;
57 -o)
58 shift
59 grub_cfg=$1
61 --output=)
62 grub_cfg=`echo "$option" | sed 's/--output=//'`
63 ;;
64 -*)
65 echo "Unrecognized option \`$option'" 1>&2
66 usage
67 exit 1
69 esac
70 done
72 . ${libdir}/grub/grub-mkconfig_lib
74 if [ "x$EUID" = "x" ] ; then
75 EUID=`id -u`
78 if [ "$EUID" != 0 ] ; then
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
95 set $grub_mkdevicemap dummy
96 if test -f "$1"; then
98 else
99 echo "$1: Not found." 1>&2
100 exit 1
103 set $grub_probe dummy
104 if test -f "$1"; then
106 else
107 echo "$1: Not found." 1>&2
108 exit 1
111 mkdir -p ${grub_prefix}
113 if test -e ${grub_prefix}/device.map ; then : ; else
114 grub-mkdevicemap
117 # Device containing our userland. Typically used for root= parameter.
118 GRUB_DEVICE="`${grub_probe} --target=device /`"
119 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
121 # Device containing our /boot partition. Usually the same as GRUB_DEVICE.
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
125 # Filesystem for the device containing our userland. Used for stuff like
126 # choosing Hurd filesystem module.
127 GRUB_FS="`${grub_probe} --target=fs / 2> /dev/null || echo unknown`"
129 if test -f ${sysconfdir}/default/grub ; then
130 . ${sysconfdir}/default/grub
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}"
139 case x${GRUB_TERMINAL_OUTPUT} in
141 # If this platform supports gfxterm, try to use it.
142 if test -e ${grub_prefix}/gfxterm.mod ; then
143 GRUB_TERMINAL_OUTPUT=gfxterm
146 xconsole | xserial | xofconsole | xgfxterm) ;;
147 *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
148 esac
150 # check for terminals that require fonts
151 case ${GRUB_TERMINAL_OUTPUT} in
152 gfxterm)
153 if path=`font_path` ; then
154 GRUB_FONT_PATH="${path}"
155 else
156 # fallback to the native terminal for this platform
157 unset GRUB_TERMINAL_OUTPUT
160 esac
162 # does our terminal support utf-8 ?
163 case ${GRUB_TERMINAL_OUTPUT} in
164 gfxterm) ;;
166 # make sure all our children behave in conformance with ascii..
167 export LANG=C
169 esac
171 # These are defined in this script, export them here so that user can
172 # override them.
173 export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_FS GRUB_FONT_PATH GRUB_PRELOAD_MODULES
175 # These are optional, user-defined variables.
176 export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL_OUTPUT GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID GRUB_GFXMODE
178 if test "x${grub_cfg}" != "x"; then
179 rm -f ${grub_cfg}.new
180 exec > ${grub_cfg}.new
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
186 echo "Generating grub.cfg ..." >&2
188 cat << EOF
190 # DO NOT EDIT THIS FILE
192 # It is automatically generated by $0 using templates
193 # from ${update_grub_dir} and settings from ${sysconfdir}/default/grub
197 for i in ${grub_mkconfig_dir}/* ; do
198 case "$i" in
199 # emacsen backup files. FIXME: support other editors
200 *~) ;;
202 if grub_file_is_not_garbage "$i" && test -x "$i" ; then
203 echo
204 echo "### BEGIN $i ###"
205 "$i"
206 echo "### END $i ###"
209 esac
210 done
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}
217 echo "done" >&2