Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / util / grub-mkconfig.in
blobd1fae4937e9ccef58d282c1e043ee280bb741d27
1 #! /bin/sh
2 set -e
4 # Generate grub.cfg by inspecting /boot contents.
5 # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
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.
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.
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/>.
20 prefix="@prefix@"
21 exec_prefix="@exec_prefix@"
22 datarootdir="@datarootdir@"
24 prefix="@prefix@"
25 exec_prefix="@exec_prefix@"
26 sbindir="@sbindir@"
27 bindir="@bindir@"
28 sysconfdir="@sysconfdir@"
29 PACKAGE_NAME=@PACKAGE_NAME@
30 PACKAGE_VERSION=@PACKAGE_VERSION@
31 host_os=@host_os@
32 datadir="@datadir@"
33 if [ "x$pkgdatadir" = x ]; then
34 pkgdatadir="${datadir}/@PACKAGE@"
36 grub_cfg=""
37 grub_mkconfig_dir="${sysconfdir}"/grub.d
39 self=`basename $0`
41 grub_probe="${sbindir}/@grub_probe@"
42 grub_file="${bindir}/@grub_file@"
43 grub_editenv="${bindir}/@grub_editenv@"
44 grub_script_check="${bindir}/@grub_script_check@"
46 export TEXTDOMAIN=@PACKAGE@
47 export TEXTDOMAINDIR="@localedir@"
49 . "${pkgdatadir}/grub-mkconfig_lib"
51 # Usage: usage
52 # Print the usage.
53 usage () {
54 gettext_printf "Usage: %s [OPTION]\n" "$self"
55 gettext "Generate a grub config file"; echo
56 echo
57 print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")"
58 print_option_help "-h, --help" "$(gettext "print this message and exit")"
59 print_option_help "-v, --version" "$(gettext "print the version information and exit")"
60 echo
61 gettext "Report bugs to <bug-grub@gnu.org>."; echo
64 argument () {
65 opt=$1
66 shift
68 if test $# -eq 0; then
69 gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" "$opt" 1>&2
70 exit 1
72 echo $1
75 # Check the arguments.
76 while test $# -gt 0
78 option=$1
79 shift
81 case "$option" in
82 -h | --help)
83 usage
84 exit 0 ;;
85 -v | --version)
86 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
87 exit 0 ;;
88 -o | --output)
89 grub_cfg=`argument $option "$@"`; shift;;
90 --output=*)
91 grub_cfg=`echo "$option" | sed 's/--output=//'`
93 -*)
94 gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
95 usage
96 exit 1
98 # Explicitly ignore non-option arguments, for compatibility.
99 esac
100 done
102 if [ "x$EUID" = "x" ] ; then
103 EUID=`id -u`
106 if [ "$EUID" != 0 ] ; then
107 root=f
108 case "`uname 2>/dev/null`" in
109 CYGWIN*)
110 # Cygwin: Assume root if member of admin group
111 for g in `id -G 2>/dev/null` ; do
112 case $g in
113 0|544) root=t ;;
114 esac
115 done ;;
116 esac
117 if [ $root != t ] ; then
118 gettext_printf "%s: You must run this as root\n" "$self" >&2
119 exit 1
123 set $grub_probe dummy
124 if test -f "$1"; then
126 else
127 gettext_printf "%s: Not found.\n" "$1" 1>&2
128 exit 1
131 # Device containing our userland. Typically used for root= parameter.
132 GRUB_DEVICE="`${grub_probe} --target=device /`"
133 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
135 # Device containing our /boot partition. Usually the same as GRUB_DEVICE.
136 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
137 GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
139 # Filesystem for the device containing our userland. Used for stuff like
140 # choosing Hurd filesystem module.
141 GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"
143 if [ x"$GRUB_FS" = xunknown ]; then
144 GRUB_FS="$(stat -f --printf=%T / || echo unknown)"
147 if test -f ${sysconfdir}/default/grub ; then
148 . ${sysconfdir}/default/grub
151 # XXX: should this be deprecated at some point?
152 if [ "x${GRUB_TERMINAL}" != "x" ] ; then
153 GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}"
154 GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}"
157 termoutdefault=0
158 if [ "x${GRUB_TERMINAL_OUTPUT}" = "x" ]; then
159 GRUB_TERMINAL_OUTPUT=gfxterm;
160 termoutdefault=1;
163 for x in ${GRUB_TERMINAL_OUTPUT}; do
164 case "x${x}" in
165 xgfxterm) ;;
166 xconsole | xserial | xofconsole | xvga_text)
167 # make sure all our children behave in conformance with ascii..
168 export LANG=C;;
169 *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
170 esac
171 done
173 GRUB_ACTUAL_DEFAULT="$GRUB_DEFAULT"
175 if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
178 # These are defined in this script, export them here so that user can
179 # override them.
180 export GRUB_DEVICE \
181 GRUB_DEVICE_UUID \
182 GRUB_DEVICE_BOOT \
183 GRUB_DEVICE_BOOT_UUID \
184 GRUB_FS \
185 GRUB_FONT \
186 GRUB_PRELOAD_MODULES \
187 GRUB_ACTUAL_DEFAULT
189 # These are optional, user-defined variables.
190 export GRUB_DEFAULT \
191 GRUB_HIDDEN_TIMEOUT \
192 GRUB_HIDDEN_TIMEOUT_QUIET \
193 GRUB_TIMEOUT \
194 GRUB_TIMEOUT_STYLE \
195 GRUB_DEFAULT_BUTTON \
196 GRUB_HIDDEN_TIMEOUT_BUTTON \
197 GRUB_TIMEOUT_BUTTON \
198 GRUB_TIMEOUT_STYLE_BUTTON \
199 GRUB_BUTTON_CMOS_ADDRESS \
200 GRUB_BUTTON_CMOS_CLEAN \
201 GRUB_DISTRIBUTOR \
202 GRUB_CMDLINE_LINUX \
203 GRUB_CMDLINE_LINUX_DEFAULT \
204 GRUB_CMDLINE_XEN \
205 GRUB_CMDLINE_XEN_DEFAULT \
206 GRUB_CMDLINE_LINUX_XEN_REPLACE \
207 GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \
208 GRUB_CMDLINE_NETBSD \
209 GRUB_CMDLINE_NETBSD_DEFAULT \
210 GRUB_CMDLINE_GNUMACH \
211 GRUB_TERMINAL_INPUT \
212 GRUB_TERMINAL_OUTPUT \
213 GRUB_SERIAL_COMMAND \
214 GRUB_DISABLE_LINUX_UUID \
215 GRUB_DISABLE_RECOVERY \
216 GRUB_VIDEO_BACKEND \
217 GRUB_GFXMODE \
218 GRUB_BACKGROUND \
219 GRUB_THEME \
220 GRUB_GFXPAYLOAD_LINUX \
221 GRUB_DISABLE_OS_PROBER \
222 GRUB_INIT_TUNE \
223 GRUB_SAVEDEFAULT \
224 GRUB_ENABLE_CRYPTODISK \
225 GRUB_BADRAM \
226 GRUB_OS_PROBER_SKIP_LIST \
227 GRUB_DISABLE_SUBMENU
229 if test "x${grub_cfg}" != "x"; then
230 rm -f "${grub_cfg}.new"
231 oldumask=$(umask); umask 077
232 exec > "${grub_cfg}.new"
233 umask $oldumask
235 gettext "Generating grub configuration file ..." >&2
236 echo >&2
238 cat << EOF
240 # DO NOT EDIT THIS FILE
242 # It is automatically generated by $self using templates
243 # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
248 for i in "${grub_mkconfig_dir}"/* ; do
249 case "$i" in
250 # emacsen backup files. FIXME: support other editors
251 *~) ;;
252 # emacsen autosave files. FIXME: support other editors
253 */\#*\#) ;;
255 if grub_file_is_not_garbage "$i" && test -x "$i" ; then
256 echo
257 echo "### BEGIN $i ###"
258 "$i"
259 echo "### END $i ###"
262 esac
263 done
265 if test "x${grub_cfg}" != "x" ; then
266 if ! ${grub_script_check} ${grub_cfg}.new; then
267 # TRANSLATORS: %s is replaced by filename
268 gettext_printf "Syntax errors are detected in generated GRUB config file.
269 Ensure that there are no errors in /etc/default/grub
270 and /etc/grub.d/* files or please file a bug report with
271 %s file attached." "${grub_cfg}.new" >&2
272 echo >&2
273 else
274 # none of the children aborted with error, install the new grub.cfg
275 mv -f ${grub_cfg}.new ${grub_cfg}
279 gettext "done" >&2
280 echo >&2