]> git.proxmox.com Git - grub2.git/blame - util/grub-mkconfig.in
2009-06-12 Pavel Roskin <proski@gnu.org>
[grub2.git] / util / grub-mkconfig.in
CommitLineData
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
19transform="@program_transform_name@"
20
2e610d62 21prefix=@prefix@
22exec_prefix=@exec_prefix@
23sbindir=@sbindir@
42c71976 24libdir=@libdir@
ebd97f6e 25sysconfdir=@sysconfdir@
26grub_prefix=`echo /boot/grub | sed ${transform}`
18ade780 27grub_cfg=""
28grub_mkconfig_dir=${sysconfdir}/grub.d
2e610d62 29
30grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
31grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
ebd97f6e 32
68807e5f 33# Usage: usage
34# Print the usage.
35usage () {
36 cat <<EOF
37Usage: $0 [OPTION]
18ade780 38Generate 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
44Report bugs to <bug-grub@gnu.org>.
45EOF
46}
47
48# Check the arguments.
49for 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
70done
71
18ade780 72. ${libdir}/grub/grub-mkconfig_lib
42c71976 73
991477f8 74if [ "x$EUID" = "x" ] ; then
75 EUID=`id -u`
ebd97f6e 76fi
77
991477f8 78if [ "$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 93fi
94
2e610d62 95set $grub_mkdevicemap dummy
96if test -f "$1"; then
97 :
98else
99 echo "$1: Not found." 1>&2
100 exit 1
ebd97f6e 101fi
102
2e610d62 103set $grub_probe dummy
104if test -f "$1"; then
105 :
106else
107 echo "$1: Not found." 1>&2
108 exit 1
ebd97f6e 109fi
110
2e610d62 111mkdir -p ${grub_prefix}
112
113if test -e ${grub_prefix}/device.map ; then : ; else
74b21bee 114 ${grub_mkdevicemap}
ebd97f6e 115fi
116
cc85c3c3 117# Device containing our userland. Typically used for root= parameter.
69ba137e 118GRUB_DEVICE="`${grub_probe} --target=device /`"
119GRUB_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 122GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
123GRUB_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 127GRUB_FS="`${grub_probe} --target=fs / 2> /dev/null || echo unknown`"
57f96397 128
ebd97f6e 129if test -f ${sysconfdir}/default/grub ; then
130 . ${sysconfdir}/default/grub
131fi
132
651c29b7 133# XXX: should this be deprecated at some point?
134if [ "x${GRUB_TERMINAL}" != "x" ] ; then
135 GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}"
136 GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}"
137fi
138
139case 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 148esac
149
150# check for terminals that require fonts
651c29b7 151case ${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 ;;
160esac
161
162# does our terminal support utf-8 ?
651c29b7 163case ${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 ;;
169esac
170
57f96397 171# These are defined in this script, export them here so that user can
172# override them.
62191274 173export 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 176export 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 178if 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
185fi
186echo "Generating grub.cfg ..." >&2
ebd97f6e 187
188cat << 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#
195EOF
196
18ade780 197for 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
210done
211
18ade780 212if 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}
215fi
ebd97f6e 216
217echo "done" >&2