~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

Viewing changes to .pc/mkconfig_stderr_handling.patch/util/grub-mkconfig_lib.in

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Helper library for grub-mkconfig
2
 
# Copyright (C) 2007,2008,2009,2010  Free Software Foundation, Inc.
3
 
#
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.
8
 
#
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.
13
 
#
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/>.
16
 
 
17
 
transform="@program_transform_name@"
18
 
 
19
 
prefix="@prefix@"
20
 
exec_prefix="@exec_prefix@"
21
 
datarootdir="@datarootdir@"
22
 
datadir="@datadir@"
23
 
bindir="@bindir@"
24
 
sbindir="@sbindir@"
25
 
pkgdatadir="${datadir}/@PACKAGE@"
26
 
 
27
 
if test "x$grub_probe" = x; then
28
 
  grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`"
29
 
fi
30
 
if test "x$grub_mkrelpath" = x; then
31
 
  grub_mkrelpath="${bindir}/`echo grub-mkrelpath | sed "${transform}"`"
32
 
fi
33
 
 
34
 
if which gettext >/dev/null 2>/dev/null; then
35
 
  :
36
 
else
37
 
  gettext () {
38
 
     printf "%s" "$@"
39
 
  }
40
 
fi
41
 
 
42
 
grub_warn ()
43
 
{
44
 
  echo "$(gettext "Warning:")" "$@" >&2
45
 
}
46
 
 
47
 
make_system_path_relative_to_its_root ()
48
 
{
49
 
  "${grub_mkrelpath}" "$1"
50
 
}
51
 
 
52
 
is_path_readable_by_grub ()
53
 
{
54
 
  path="$1"
55
 
 
56
 
  # abort if path doesn't exist
57
 
  if test -e "$path" ; then : ;else
58
 
    return 1
59
 
  fi
60
 
 
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
63
 
    return 1
64
 
  fi
65
 
 
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 
69
 
      :
70
 
  else
71
 
    return 1
72
 
  fi
73
 
 
74
 
  if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
75
 
      return 0
76
 
  fi
77
 
  
78
 
  for abstraction in $abstractions; do
79
 
      if [ "x$abstraction" = xcryptodisk ]; then
80
 
          return 1
81
 
      fi
82
 
  done
83
 
 
84
 
  return 0
85
 
}
86
 
 
87
 
convert_system_path_to_grub_path ()
88
 
{
89
 
  path="$1"
90
 
 
91
 
  grub_warn "convert_system_path_to_grub_path() is deprecated.  Use prepare_grub_to_access_device() instead."
92
 
 
93
 
  # abort if GRUB can't access the path
94
 
  if is_path_readable_by_grub "${path}" ; then : ; else
95
 
    return 1
96
 
  fi
97
 
 
98
 
  if drive="`"${grub_probe}" -t drive "$path"`" ; then : ; else
99
 
    return 1
100
 
  fi
101
 
 
102
 
  if relative_path="`make_system_path_relative_to_its_root "$path"`" ; then : ; else
103
 
    return 1
104
 
  fi
105
 
 
106
 
  echo "${drive}${relative_path}"
107
 
}
108
 
 
109
 
save_default_entry ()
110
 
{
111
 
  if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
112
 
    cat << EOF
113
 
savedefault
114
 
EOF
115
 
  fi
116
 
}
117
 
 
118
 
prepare_grub_to_access_device ()
119
 
{
120
 
  device="$1"
121
 
 
122
 
  partmap="`"${grub_probe}" --device "${device}" --target=partmap`"
123
 
  for module in ${partmap} ; do
124
 
    case "${module}" in
125
 
      netbsd | openbsd)
126
 
        echo "insmod part_bsd";;
127
 
      *)
128
 
        echo "insmod part_${module}";;
129
 
    esac
130
 
  done
131
 
 
132
 
  loop_file=
133
 
  case ${device} in
134
 
    /dev/loop/*|/dev/loop[0-9])
135
 
      grub_loop_device="${device#/dev/}"
136
 
      loop_file=`losetup "${device}" | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
137
 
      case $loop_file in
138
 
        /dev/*) ;;
139
 
        *)
140
 
          loop_device="${device}"
141
 
          device=`"${grub_probe}" --target=device "${loop_file}"`
142
 
        ;;
143
 
      esac
144
 
    ;;
145
 
  esac
146
 
 
147
 
  if dmsetup status $device 2>/dev/null | grep -q 'crypt[[:space:]]$'; then
148
 
    grub_warn \
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."
153
 
    return 0
154
 
  fi
155
 
 
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}"
160
 
  done
161
 
 
162
 
  fs="`"${grub_probe}" --device "${device}" --target=fs`"
163
 
  for module in ${fs} ; do
164
 
    echo "insmod ${module}"
165
 
  done
166
 
 
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"
170
 
      done
171
 
  fi
172
 
 
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'"
178
 
  fi
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}"
183
 
    echo "else"
184
 
    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
185
 
    echo "fi"
186
 
  fi
187
 
 
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})"
193
 
    fi
194
 
  fi
195
 
}
196
 
 
197
 
grub_get_device_id ()
198
 
{
199
 
  device="$1"
200
 
  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
201
 
    echo "$fs_uuid";
202
 
  else
203
 
    echo "$device"
204
 
  fi
205
 
}
206
 
 
207
 
grub_file_is_not_garbage ()
208
 
{
209
 
  if test -f "$1" ; then
210
 
    case "$1" in
211
 
      *.dpkg-*) return 1 ;; # debian dpkg
212
 
      *.rpmsave|*.rpmnew) return 1 ;;
213
 
      README*|*/README*)  return 1 ;; # documentation
214
 
    esac
215
 
  else
216
 
    return 1
217
 
  fi
218
 
  return 0
219
 
}
220
 
 
221
 
version_sort ()
222
 
{
223
 
  case $version_sort_sort_has_v in
224
 
    yes)
225
 
      LC_ALL=C sort -V;;
226
 
    no)
227
 
      LC_ALL=C sort -n;;
228
 
    *)
229
 
      if sort -V </dev/null > /dev/null 2>&1; then
230
 
        version_sort_sort_has_v=yes
231
 
        LC_ALL=C sort -V
232
 
      else
233
 
        version_sort_sort_has_v=no
234
 
        LC_ALL=C sort -n
235
 
      fi;;
236
 
   esac
237
 
}
238
 
 
239
 
version_test_numeric ()
240
 
{
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 ;;
247
 
      gt|lt) return 1 ;;
248
 
    esac
249
 
  fi
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"
254
 
  fi
255
 
  if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then
256
 
    return 0
257
 
  else
258
 
    return 1
259
 
  fi
260
 
}
261
 
 
262
 
version_test_gt ()
263
 
{
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
269
 
    return 0
270
 
  fi
271
 
  case "$version_test_gt_a:$version_test_gt_b" in
272
 
    *.old:*.old) ;;
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 ;;
275
 
  esac
276
 
  dpkg --compare-versions "$version_test_gt_a" "$version_test_gt_cmp" "$version_test_gt_b"
277
 
  return "$?"
278
 
}
279
 
 
280
 
version_find_latest ()
281
 
{
282
 
  version_find_latest_a=""
283
 
  for i in "$@" ; do
284
 
    if version_test_gt "$i" "$version_find_latest_a" ; then
285
 
      version_find_latest_a="$i"
286
 
    fi
287
 
  done
288
 
  echo "$version_find_latest_a"
289
 
}
290
 
 
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.
294
 
 
295
 
grub_quote () {
296
 
  sed "s/'/'\\\\''/g"
297
 
}
298
 
 
299
 
gettext_quoted () {
300
 
  gettext "$@" | grub_quote
301
 
}
302
 
 
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
305
 
# be easier to type.
306
 
gettext_printf () {
307
 
  gettext_printf_format="$1"
308
 
  shift
309
 
  printf "$(gettext "$gettext_printf_format")" "$@"
310
 
}
311
 
 
312
 
uses_abstraction () {
313
 
  device="$1"
314
 
 
315
 
  abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
316
 
  for module in ${abstraction}; do
317
 
    if test "x${module}" = "x$2"; then
318
 
      return 0
319
 
    fi
320
 
  done
321
 
  return 1
322
 
}
323
 
 
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
330
 
      else
331
 
          print_option_help_wc=-b
332
 
      fi
333
 
  fi
334
 
  if test x$grub_have_fmt = x; then
335
 
      if fmt -w 40  </dev/null > /dev/null 2>&1; then
336
 
          grub_have_fmt=y;
337
 
      else
338
 
          grub_have_fmt=n;
339
 
      fi
340
 
  fi
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
347
 
      echo
348
 
  else
349
 
      print_option_help_i=0;
350
 
      while test $print_option_help_i -lt $print_option_help_fill; do
351
 
      printf " "
352
 
          print_option_help_i=$((print_option_help_i+1))
353
 
      done
354
 
      print_option_help_nl=n
355
 
  fi
356
 
  if test x$grub_have_fmt = xy; then
357
 
      print_option_help_split="$(echo "$2" | fmt -w 50)"
358
 
  else
359
 
      print_option_help_split="$2"
360
 
  fi
361
 
  if test x$print_option_help_nl = xy; then
362
 
      echo "$print_option_help_split" | awk \
363
 
          '{ print "                          " $0; }'
364
 
  else
365
 
      echo "$print_option_help_split" | awk 'BEGIN   { n = 0 }
366
 
  { if (n == 1) print "                          " $0; else print $0; n = 1 ; }'
367
 
  fi
368
 
}
369
 
 
370
 
grub_fmt () {
371
 
  if test x$grub_have_fmt = x; then
372
 
      if fmt -w 40 < /dev/null > /dev/null; then
373
 
          grub_have_fmt=y;
374
 
      else
375
 
          grub_have_fmt=n;
376
 
      fi
377
 
  fi
378
 
 
379
 
  if test x$grub_have_fmt = xy; then
380
 
      fmt
381
 
  else
382
 
      cat
383
 
  fi
384
 
}