00_header.in 8.51 KB
Newer Older
1 2
#! /bin/sh
set -e
3

4
# grub-mkconfig helper script.
5
# Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
6
#
7 8 9
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
10 11
# (at your option) any later version.
#
12 13 14 15
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
16 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/>.
19

20 21 22
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
23
grub_lang=`echo $LANG | cut -d . -f 1`
24

25 26 27
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR="@localedir@"

28
. "$pkgdatadir/grub-mkconfig_lib"
29

30
# Do this as early as possible, since other commands might depend on it.
31
# (e.g. the `loadfont' command might need lvm or raid modules)
32 33 34 35
for i in ${GRUB_PRELOAD_MODULES} ; do
  echo "insmod $i"
done

36
if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
37
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
38
if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
39
if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi
40

41 42 43 44
if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi
if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi
if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi

45
cat << EOF
46 47 48
if [ -s \$prefix/grubenv ]; then
  load_env
fi
49 50 51 52 53
EOF
if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
    cat <<EOF
if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
   set default="${GRUB_DEFAULT_BUTTON}"
54 55 56 57 58
elif [ "\${next_entry}" ] ; then
   set default="\${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
59 60 61 62 63 64
else
   set default="${GRUB_DEFAULT}"
fi
EOF
else
    cat <<EOF
65 66 67 68 69 70 71 72
if [ "\${next_entry}" ] ; then
   set default="\${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="${GRUB_DEFAULT}"
fi
73 74 75
EOF
fi
cat <<EOF
76 77 78 79 80 81 82 83 84

if [ x"\${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

85
if [ "\${prev_saved_entry}" ]; then
86
  set saved_entry="\${prev_saved_entry}"
87
  save_env saved_entry
88
  set prev_saved_entry=
89
  save_env prev_saved_entry
90
  set boot_once=true
91
fi
92 93

function savedefault {
94
  if [ -z "\${boot_once}" ]; then
95
    saved_entry="\${chosen}"
96 97 98
    save_env saved_entry
  fi
}
99 100 101 102 103 104 105 106

function load_video {
EOF
if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
    cat <<EOF
  insmod ${GRUB_VIDEO_BACKEND}
EOF
else
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
# If all_video.mod isn't available load all modules available
# with versions prior to introduction of all_video.mod
cat <<EOF
  if [ x\$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
EOF
122 123 124 125
fi
cat <<EOF
}

126 127
EOF

128 129 130 131 132 133 134 135 136 137 138 139
serial=0;
gfxterm=0;
for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
    if [ xserial = "x$x" ]; then
	serial=1;
    fi
    if [ xgfxterm = "x$x" ]; then
	gfxterm=1;
    fi
done

if [ "x$serial" = x1 ]; then
140
    if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
141
	grub_warn "$(gettext "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used.")"
142
	GRUB_SERIAL_COMMAND=serial
143 144
    fi
    echo "${GRUB_SERIAL_COMMAND}"
145
fi
146

147
if [ "x$gfxterm" = x1 ]; then
148 149 150 151 152 153
    if [ -n "$GRUB_FONT" ] ; then
       # Make the font accessible
       prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT}"`
    cat << EOF
if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
EOF
154
    else
155
	for dir in "${pkgdatadir}" "`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`" /usr/share/grub ; do
156 157 158 159 160 161 162 163
	    for basename in unicode unifont ascii; do
		path="${dir}/${basename}.pf2"
		if is_path_readable_by_grub "${path}" > /dev/null ; then
		    font_path="${path}"
		else
		    continue
		fi
		break 2
164
	    done
165 166
	done
	if [ -n "${font_path}" ] ; then
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    cat << EOF
if [ x\$feature_default_font_path = xy ] ; then
   font=unicode
else
EOF
                # Make the font accessible
		prepare_grub_to_access_device `${grub_probe} --target=device "${font_path}"`
    cat << EOF
    font="`make_system_path_relative_to_its_root "${font_path}"`"
fi

if loadfont \$font ; then
EOF
	    else
    cat << EOF
if loadfont unicode ; then
EOF
	    fi
	fi
186

187
    cat << EOF
188
  set gfxmode=${GRUB_GFXMODE}
189
  load_video
190
  insmod gfxterm
191 192 193
EOF

# Gettext variables and module
194
if [ "x${LANG}" != "xC" ] &&  [ "x${LANG}" != "x" ]; then
195
  cat << EOF
196
  set locale_dir=\$prefix/locale
197 198 199 200 201 202
  set lang=${grub_lang}
  insmod gettext
EOF
fi

cat <<EOF
203 204 205 206 207 208 209 210 211 212
fi
EOF
fi

case x${GRUB_TERMINAL_INPUT} in
  x)
    # Just use the native terminal
  ;;
  x*)
    cat << EOF
213
terminal_input ${GRUB_TERMINAL_INPUT}
214 215 216 217 218 219 220 221 222 223
EOF
  ;;
esac

case x${GRUB_TERMINAL_OUTPUT} in
  x)
    # Just use the native terminal
  ;;
  x*)
    cat << EOF
224
terminal_output ${GRUB_TERMINAL_OUTPUT}
225
EOF
226 227 228 229
  ;;
esac

if [ "x$gfxterm" = x1 ]; then
230 231
    if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
	&& is_path_readable_by_grub "$GRUB_THEME"; then
232 233
	gettext_printf "Found theme: %s\n" "$GRUB_THEME" >&2

234
	prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"`
235
	cat << EOF
236
insmod gfxmenu
237
EOF
238
	themedir="`dirname "$GRUB_THEME"`"
239 240 241
	for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
	    if [ -f "$x" ]; then
		cat << EOF
242
loadfont (\$root)`make_system_path_relative_to_its_root $x`
243 244 245
EOF
	    fi
	done
246
	if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
247
	    cat << EOF
248
insmod jpeg
249 250 251 252
EOF
	fi
	if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
	    cat << EOF
253
insmod png
254 255 256 257
EOF
	fi
	if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
	    cat << EOF
258
insmod tga
259 260 261 262
EOF
	fi
	    
	cat << EOF
263
set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
264
export theme
265 266 267
EOF
    elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
	    && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
268
	gettext_printf "Found background: %s\n" "$GRUB_BACKGROUND" >&2
269 270 271 272
	case "$GRUB_BACKGROUND" in 
	    *.png)         reader=png ;;
	    *.tga)         reader=tga ;;
	    *.jpg|*.jpeg)  reader=jpeg ;;
273
	    *)             gettext "Unsupported image format" >&2; echo >&2; exit 1 ;;
274
	esac
275
	prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"`
276
	cat << EOF
277 278
insmod $reader
background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
279 280
EOF
    fi
281
fi
282

283 284
make_timeout ()
{
285 286 287
    if [ "x${3}" != "x" ] ; then
	timeout="${2}"
	style="${3}"
288
    elif [ "x${1}" != "x" ] && [ "x${1}" != "x0" ] ; then
289 290 291 292
	# Handle the deprecated GRUB_HIDDEN_TIMEOUT scheme.
	timeout="${1}"
	if [ "x${2}" != "x0" ] ; then
	    grub_warn "$(gettext "Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.")"
293
	fi
294 295
	if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
	    style="hidden"
296
	    verbose=
297 298 299
	else
	    style="countdown"
	    verbose=" --verbose"
300
	fi
301 302 303 304 305 306
    else
	# No hidden timeout, so treat as GRUB_TIMEOUT_STYLE=menu
	timeout="${2}"
	style="menu"
    fi
    cat << EOF
307
if [ x\$feature_timeout_style = xy ] ; then
308 309 310
  set timeout_style=${style}
  set timeout=${timeout}
EOF
311 312 313 314 315 316 317 318 319
    if [ "x${style}" = "xmenu" ] ; then
	cat << EOF
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=${timeout}
EOF
    else
	cat << EOF
320 321 322
# Fallback hidden-timeout code in case the timeout_style feature is
# unavailable.
elif sleep${verbose} --interruptible ${timeout} ; then
323
  set timeout=0
324
EOF
325 326
    fi
    cat << EOF
327 328
fi
EOF
329 330 331 332 333 334
}

if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
    cat <<EOF
if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
EOF
335
make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_STYLE_BUTTON}"
336
echo else
337
make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
338 339
echo fi
else
340
make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
341
fi
342

343 344 345 346 347 348
if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then
    cat <<EOF
cmosclean $GRUB_BUTTON_CMOS_ADDRESS
EOF
fi

349 350
# Play an initial tune
if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
351 352 353 354 355
  echo "play ${GRUB_INIT_TUNE}"
fi

if [ "x${GRUB_BADRAM}" != "x" ] ; then
  echo "badram ${GRUB_BADRAM}"
356
fi