2008-09-29 Felix Zielcke <fzielcke@z-51.de>
[grub2/phcoder/solaris.git] / util / grub-mkconfig.in
blobf7cf0d1f09cec2557722c6bea45403353a335c8d
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 case x${GRUB_TERMINAL} in
135 # If this platform supports gfxterm, try to use it.
136 if test -e ${grub_prefix}/gfxterm.mod ; then
137 GRUB_TERMINAL=gfxterm
140 xconsole | xserial | xofconsole | xgfxterm) ;;
141 *) echo "Invalid terminal \"${GRUB_TERMINAL}\"" >&2 ; exit 1 ;;
142 esac
144 # check for terminals that require fonts
145 case ${GRUB_TERMINAL} in
146 gfxterm)
147 if path=`font_path` ; then
148 GRUB_FONT_PATH="${path}"
149 else
150 # fallback to the native terminal for this platform
151 unset GRUB_TERMINAL
154 esac
156 # does our terminal support utf-8 ?
157 case ${GRUB_TERMINAL} in
158 gfxterm) ;;
160 # make sure all our children behave in conformance with ascii..
161 export LANG=C
163 esac
165 # These are defined in this script, export them here so that user can
166 # override them.
167 export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_FS GRUB_FONT_PATH GRUB_PRELOAD_MODULES
169 # These are optional, user-defined variables.
170 export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID GRUB_GFXMODE
172 if test "x${grub_cfg}" != "x"; then
173 rm -f ${grub_cfg}.new
174 exec > ${grub_cfg}.new
176 # Allow this to fail, since /boot/grub/ might need to be fatfs to support some
177 # firmware implementations (e.g. OFW or EFI).
178 chmod 444 ${grub_cfg}.new || true
180 echo "Generating grub.cfg ..." >&2
182 cat << EOF
184 # DO NOT EDIT THIS FILE
186 # It is automatically generated by $0 using templates
187 # from ${update_grub_dir} and settings from ${sysconfdir}/default/grub
191 for i in ${grub_mkconfig_dir}/* ; do
192 case "$i" in
193 # emacsen backup files. FIXME: support other editors
194 *~) ;;
196 if grub_file_is_not_garbage "$i" && test -x "$i" ; then
197 echo
198 echo "### BEGIN $i ###"
199 "$i"
200 echo "### END $i ###"
203 esac
204 done
206 if test "x${grub_cfg}" != "x" ; then
207 # none of the children aborted with error, install the new grub.cfg
208 mv -f ${grub_cfg}.new ${grub_cfg}
211 echo "done" >&2