]> git.proxmox.com Git - grub2.git/blame - util/update-grub.in
2008-07-29 Christian Franke <franke@computer.org>
[grub2.git] / util / update-grub.in
CommitLineData
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
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}`
27grub_cfg=${grub_prefix}/grub.cfg
28update_grub_dir=${sysconfdir}/grub.d
6193defe 29platform=@platform@
2e610d62 30
31grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
32grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
ebd97f6e 33
68807e5f 34# Usage: usage
35# Print the usage.
36usage () {
37 cat <<EOF
38Usage: $0 [OPTION]
39Generate /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
45Report bugs to <bug-grub@gnu.org>.
46EOF
47}
48
49# Check the arguments.
50for 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
67done
68
42c71976 69. ${libdir}/grub/update-grub_lib
70
991477f8 71if [ "x$EUID" = "x" ] ; then
72 EUID=`id -u`
ebd97f6e 73fi
74
991477f8 75if [ "$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 90fi
91
2e610d62 92set $grub_mkdevicemap dummy
93if test -f "$1"; then
94 :
95else
96 echo "$1: Not found." 1>&2
97 exit 1
ebd97f6e 98fi
99
2e610d62 100set $grub_probe dummy
101if test -f "$1"; then
102 :
103else
104 echo "$1: Not found." 1>&2
105 exit 1
ebd97f6e 106fi
107
2e610d62 108mkdir -p ${grub_prefix}
109
110if test -e ${grub_prefix}/device.map ; then : ; else
111 grub-mkdevicemap
ebd97f6e 112fi
113
cc85c3c3 114# Device containing our userland. Typically used for root= parameter.
69ba137e 115GRUB_DEVICE="`${grub_probe} --target=device /`"
116GRUB_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 119GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
120GRUB_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 124GRUB_FS="`${grub_probe} --target=fs / 2> /dev/null || echo unknown`"
57f96397 125
ebd97f6e 126if test -f ${sysconfdir}/default/grub ; then
127 . ${sysconfdir}/default/grub
128fi
129
6193defe 130# if ${GRUB_TERMINAL} is set, check it has a sane value. if undefined,
131# fallback to our default
132case ${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 ;;
139esac
140
141# check for terminals that require fonts
142case ${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 ;;
151esac
152
153# does our terminal support utf-8 ?
154case ${platform}:${GRUB_TERMINAL} in
155 *:gfxterm) ;;
156 *:*)
157 # make sure all our children behave in conformance with ascii..
158 export LANG=C
159 ;;
160esac
161
57f96397 162# These are defined in this script, export them here so that user can
163# override them.
62191274 164export 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 167export 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 169rm -f ${grub_cfg}.new
57f96397 170exec > ${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).
174chmod 444 ${grub_cfg}.new || true
57f96397 175
ebd97f6e 176echo "Updating ${grub_cfg} ..." >&2
177
178cat << 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#
185EOF
186
ebd97f6e 187for 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
200done
201
202# none of the children aborted with error, install the new grub.cfg
b609876d 203mv -f ${grub_cfg}.new ${grub_cfg}
ebd97f6e 204
205echo "done" >&2