1
# Helper library for grub-mkconfig
2
# Copyright (C) 2007,2008,2009,2010 Free Software Foundation, Inc.
4
# GRUB is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
9
# GRUB is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17
transform="@program_transform_name@"
20
exec_prefix="@exec_prefix@"
21
datarootdir="@datarootdir@"
25
pkgdatadir="${datadir}/@PACKAGE@"
27
if test "x$grub_probe" = x; then
28
grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`"
30
if test "x$grub_mkrelpath" = x; then
31
grub_mkrelpath="${bindir}/`echo grub-mkrelpath | sed "${transform}"`"
34
if which gettext >/dev/null 2>/dev/null; then
44
echo "$(gettext "Warning:")" "$@" >&2
47
make_system_path_relative_to_its_root ()
49
"${grub_mkrelpath}" "$1"
52
is_path_readable_by_grub ()
56
# abort if path doesn't exist
57
if test -e "$path" ; then : ;else
61
# abort if file is in a filesystem we can't read
62
if "${grub_probe}" -t fs "$path" > /dev/null 2>&1 ; then : ; else
66
# ... or if we can't figure out the abstraction module, for example if
67
# memberlist fails on an LVM volume group.
68
if abstractions="`"${grub_probe}" -t abstraction "$path"`" 2>&1 ; then
74
if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
78
for abstraction in $abstractions; do
79
if [ "x$abstraction" = xcryptodisk ]; then
87
convert_system_path_to_grub_path ()
91
grub_warn "convert_system_path_to_grub_path() is deprecated. Use prepare_grub_to_access_device() instead."
93
# abort if GRUB can't access the path
94
if is_path_readable_by_grub "${path}" ; then : ; else
98
if drive="`"${grub_probe}" -t drive "$path"`" ; then : ; else
102
if relative_path="`make_system_path_relative_to_its_root "$path"`" ; then : ; else
106
echo "${drive}${relative_path}"
109
save_default_entry ()
111
if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
118
prepare_grub_to_access_device ()
122
partmap="`"${grub_probe}" --device "${device}" --target=partmap`"
123
for module in ${partmap} ; do
126
echo "insmod part_bsd";;
128
echo "insmod part_${module}";;
134
/dev/loop/*|/dev/loop[0-9])
135
grub_loop_device="${device#/dev/}"
136
loop_file=`losetup "${device}" | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
140
loop_device="${device}"
141
device=`"${grub_probe}" --target=device "${loop_file}"`
147
if dmsetup status $device 2>/dev/null | grep -q 'crypt[[:space:]]$'; then
149
"$device is a crypto device, which GRUB cannot read directly. Some" \
150
"necessary modules may be missing from /boot/grub/grub.cfg. You may" \
151
"need to list them in GRUB_PRELOAD_MODULES in /etc/default/grub. See" \
152
"http://bugs.debian.org/542165 for details."
156
# Abstraction modules aren't auto-loaded.
157
abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
158
for module in ${abstraction} ; do
159
echo "insmod ${module}"
162
fs="`"${grub_probe}" --device "${device}" --target=fs`"
163
for module in ${fs} ; do
164
echo "insmod ${module}"
167
if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
168
for uuid in "`"${grub_probe}" --device "${device}" --target=cryptodisk_uuid`"; do
169
echo "cryptomount -u $uuid"
173
# If there's a filesystem UUID that GRUB is capable of identifying, use it;
174
# otherwise set root as per value in device.map.
175
fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
176
if [ "x$fs_hint" != x ]; then
177
echo "set root='$fs_hint'"
179
if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
180
hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
181
echo "if [ x\$feature_platform_search_hint = xy ]; then"
182
echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
184
echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
188
if [ "x${loop_file}" != x ]; then
189
loop_mountpoint="$(awk '"'${loop_file}'" ~ "^"$2 && $2 != "/" { print $2 }' /proc/mounts | tail -n1)"
190
if [ "x${loop_mountpoint}" != x ]; then
191
echo "loopback ${grub_loop_device} ${loop_file#$loop_mountpoint}"
192
echo "set root=(${grub_loop_device})"
197
grub_get_device_id ()
200
if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
207
grub_file_is_not_garbage ()
209
if test -f "$1" ; then
211
*.dpkg-*) return 1 ;; # debian dpkg
212
*.rpmsave|*.rpmnew) return 1 ;;
213
README*|*/README*) return 1 ;; # documentation
223
case $version_sort_sort_has_v in
229
if sort -V </dev/null > /dev/null 2>&1; then
230
version_sort_sort_has_v=yes
233
version_sort_sort_has_v=no
239
version_test_numeric ()
241
version_test_numeric_a="$1"
242
version_test_numeric_cmp="$2"
243
version_test_numeric_b="$3"
244
if [ "$version_test_numeric_a" = "$version_test_numeric_b" ] ; then
245
case "$version_test_numeric_cmp" in
246
ge|eq|le) return 0 ;;
250
if [ "$version_test_numeric_cmp" = "lt" ] ; then
251
version_test_numeric_c="$version_test_numeric_a"
252
version_test_numeric_a="$version_test_numeric_b"
253
version_test_numeric_b="$version_test_numeric_c"
255
if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then
264
version_test_gt_sedexp="s/[^-]*-//;s/[._-]\(pre\|rc\|test\|git\|old\|trunk\)/~\1/g"
265
version_test_gt_a="`echo "$1" | sed -e "$version_test_gt_sedexp"`"
266
version_test_gt_b="`echo "$2" | sed -e "$version_test_gt_sedexp"`"
267
version_test_gt_cmp=gt
268
if [ "x$version_test_gt_b" = "x" ] ; then
271
case "$version_test_gt_a:$version_test_gt_b" in
273
*.old:*) version_test_gt_a="`echo -n "$version_test_gt_a" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=gt ;;
274
*:*.old) version_test_gt_b="`echo -n "$version_test_gt_b" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=ge ;;
276
dpkg --compare-versions "$version_test_gt_a" "$version_test_gt_cmp" "$version_test_gt_b"
280
version_find_latest ()
282
version_find_latest_a=""
284
if version_test_gt "$i" "$version_find_latest_a" ; then
285
version_find_latest_a="$i"
288
echo "$version_find_latest_a"
291
# One layer of quotation is eaten by "" and the second by
292
# sed; so this turns ' into \'. Note that you must use the output of
293
# this function in a printf format string.
300
gettext "$@" | grub_quote
303
# Run the first argument through gettext, and then pass that and all
304
# remaining arguments to printf. This is a useful abbreviation and tends to
307
gettext_printf_format="$1"
309
printf "$(gettext "$gettext_printf_format")" "$@"
312
uses_abstraction () {
315
abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
316
for module in ${abstraction}; do
317
if test "x${module}" = "x$2"; then
324
print_option_help () {
325
if test x$print_option_help_wc = x; then
326
if wc -L </dev/null > /dev/null 2>&1; then
327
print_option_help_wc=-L
328
elif wc -m </dev/null > /dev/null 2>&1; then
329
print_option_help_wc=-m
331
print_option_help_wc=-b
334
if test x$grub_have_fmt = x; then
335
if fmt -w 40 </dev/null > /dev/null 2>&1; then
341
print_option_help_lead=" $1"
342
print_option_help_lspace="$(echo "$print_option_help_lead" | wc $print_option_help_wc)"
343
print_option_help_fill="$((26 - print_option_help_lspace))"
344
printf "%s" "$print_option_help_lead"
345
if test $print_option_help_fill -le 0; then
346
print_option_help_nl=y
349
print_option_help_i=0;
350
while test $print_option_help_i -lt $print_option_help_fill; do
352
print_option_help_i=$((print_option_help_i+1))
354
print_option_help_nl=n
356
if test x$grub_have_fmt = xy; then
357
print_option_help_split="$(echo "$2" | fmt -w 50)"
359
print_option_help_split="$2"
361
if test x$print_option_help_nl = xy; then
362
echo "$print_option_help_split" | awk \
365
echo "$print_option_help_split" | awk 'BEGIN { n = 0 }
366
{ if (n == 1) print " " $0; else print $0; n = 1 ; }'
371
if test x$grub_have_fmt = x; then
372
if fmt -w 40 < /dev/null > /dev/null; then
379
if test x$grub_have_fmt = xy; then