source: src-sh/pc-extractoverlay/ports-overlay/usr/local/share/grub/grub-mkconfig_lib @ 0fbe5d0

releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 0fbe5d0 was 0fbe5d0, checked in by Kris Moore <kris@…>, 8 months ago

Update grub overlay data to match current 2.02 pre-release version we just pushed to
ports tree

  • Property mode set to 100644
File size: 9.1 KB
Line 
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
17prefix="/usr/local"
18exec_prefix="/usr/local"
19datarootdir="/usr/local/share"
20datadir="${datarootdir}"
21bindir="${exec_prefix}/bin"
22sbindir="${exec_prefix}/sbin"
23if [ "x$pkgdatadir" = x ]; then
24    pkgdatadir="${datadir}/grub"
25fi
26
27if test "x$grub_probe" = x; then
28  grub_probe="${sbindir}/grub-probe"
29fi
30if test "x$grub_file" = x; then
31  grub_file="${bindir}/grub-file"
32fi
33if test "x$grub_mkrelpath" = x; then
34  grub_mkrelpath="${bindir}/grub-mkrelpath"
35fi
36
37if which gettext >/dev/null 2>/dev/null; then
38  :
39else
40  gettext () {
41     printf "%s" "$@"
42  }
43fi
44
45grub_warn ()
46{
47  echo "$(gettext "Warning:")" "$@" >&2
48}
49
50make_system_path_relative_to_its_root ()
51{
52  "${grub_mkrelpath}" "$1"
53}
54
55is_path_readable_by_grub ()
56{
57  path="$1"
58
59  # abort if path doesn't exist
60  if test -e "$path" ; then : ;else
61    return 1
62  fi
63
64  # abort if file is in a filesystem we can't read
65  if "${grub_probe}" -t fs "$path" > /dev/null 2>&1 ; then : ; else
66    return 1
67  fi
68
69  # ... or if we can't figure out the abstraction module, for example if
70  # memberlist fails on an LVM volume group.
71  if abstractions="`"${grub_probe}" -t abstraction "$path"`" 2> /dev/null ; then
72      :
73  else
74    return 1
75  fi
76
77  if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then
78      return 0
79  fi
80 
81  for abstraction in $abstractions; do
82      if [ "x$abstraction" = xcryptodisk ]; then
83          return 1
84      fi
85  done
86
87  return 0
88}
89
90convert_system_path_to_grub_path ()
91{
92  path="$1"
93
94  grub_warn "convert_system_path_to_grub_path() is deprecated.  Use prepare_grub_to_access_device() instead."
95
96  # abort if GRUB can't access the path
97  if is_path_readable_by_grub "${path}" ; then : ; else
98    return 1
99  fi
100
101  if drive="`"${grub_probe}" -t drive "$path"`" ; then : ; else
102    return 1
103  fi
104
105  if relative_path="`make_system_path_relative_to_its_root "$path"`" ; then : ; else
106    return 1
107  fi
108
109  echo "${drive}${relative_path}"
110}
111
112save_default_entry ()
113{
114  if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
115    cat << EOF
116savedefault
117EOF
118  fi
119}
120
121prepare_grub_to_access_device ()
122{
123  old_ifs="$IFS"
124  IFS='
125'
126  partmap="`"${grub_probe}" --device $@ --target=partmap`"
127  for module in ${partmap} ; do
128    case "${module}" in
129      netbsd | openbsd)
130        echo "insmod part_bsd";;
131      *)
132        echo "insmod part_${module}";;
133    esac
134  done
135
136  # Abstraction modules aren't auto-loaded.
137  abstraction="`"${grub_probe}" --device $@ --target=abstraction`"
138  for module in ${abstraction} ; do
139    echo "insmod ${module}"
140  done
141
142  # KPM - 6-24-2013
143  # Add this work-around since GRUB doesn't like to identify ZFS
144  # partitions which are in a raidz configuration, gives Unknown FS error
145  # We can instead look at zpool to see if this device is used though
146  zpool status 2>/dev/null | grep -q "`echo ${device} | sed 's|/dev/||g'`"
147  if [ $? -eq 0 ] ; then
148     fs="zfs"
149  else
150     fs="`"${grub_probe}" --device $@ --target=fs`"
151  fi
152
153  for module in ${fs} ; do
154    echo "insmod ${module}"
155  done
156
157  if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then
158      for uuid in "`"${grub_probe}" --device $@ --target=cryptodisk_uuid`"; do
159          echo "cryptomount -u $uuid"
160      done
161  fi
162
163  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
164  # otherwise set root as per value in device.map.
165  fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`"
166  if [ "x$fs_hint" != x ]; then
167    echo "set root='$fs_hint'"
168  fi
169  if fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then
170    hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints=
171    echo "if [ x\$feature_platform_search_hint = xy ]; then"
172    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
173    echo "else"
174    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
175    echo "fi"
176  fi
177  IFS="$old_ifs"
178}
179
180grub_get_device_id ()
181{
182  old_ifs="$IFS"
183  IFS='
184'
185  device="$1"
186  if fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then
187    echo "$fs_uuid";
188  else
189    echo $device |sed 's, ,_,g'
190  fi
191  IFS="$old_ifs"
192}
193
194grub_file_is_not_garbage ()
195{
196  if test -f "$1" ; then
197    case "$1" in
198      *.dpkg-*) return 1 ;; # debian dpkg
199      *.rpmsave|*.rpmnew) return 1 ;;
200      README*|*/README*)  return 1 ;; # documentation
201    esac
202  else
203    return 1
204  fi
205  return 0
206}
207
208version_sort ()
209{
210  case $version_sort_sort_has_v in
211    yes)
212      LC_ALL=C sort -V;;
213    no)
214      LC_ALL=C sort -n;;
215    *)
216      if sort -V </dev/null > /dev/null 2>&1; then
217        version_sort_sort_has_v=yes
218        LC_ALL=C sort -V
219      else
220        version_sort_sort_has_v=no
221        LC_ALL=C sort -n
222      fi;;
223   esac
224}
225
226version_test_numeric ()
227{
228  version_test_numeric_a="$1"
229  version_test_numeric_cmp="$2"
230  version_test_numeric_b="$3"
231  if [ "$version_test_numeric_a" = "$version_test_numeric_b" ] ; then
232    case "$version_test_numeric_cmp" in
233      ge|eq|le) return 0 ;;
234      gt|lt) return 1 ;;
235    esac
236  fi
237  if [ "$version_test_numeric_cmp" = "lt" ] ; then
238    version_test_numeric_c="$version_test_numeric_a"
239    version_test_numeric_a="$version_test_numeric_b"
240    version_test_numeric_b="$version_test_numeric_c"
241  fi
242  if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then
243    return 0
244  else
245    return 1
246  fi
247}
248
249version_test_gt ()
250{
251  version_test_gt_a="`echo "$1" | sed -e "s/[^-]*-//"`"
252  version_test_gt_b="`echo "$2" | sed -e "s/[^-]*-//"`"
253  version_test_gt_cmp=gt
254  if [ "x$version_test_gt_b" = "x" ] ; then
255    return 0
256  fi
257  case "$version_test_gt_a:$version_test_gt_b" in
258    *.old:*.old) ;;
259    *.old:*) version_test_gt_a="`echo -n "$version_test_gt_a" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=gt ;;
260    *:*.old) version_test_gt_b="`echo -n "$version_test_gt_b" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=ge ;;
261  esac
262  version_test_numeric "$version_test_gt_a" "$version_test_gt_cmp" "$version_test_gt_b"
263  return "$?"
264}
265
266version_find_latest ()
267{
268  version_find_latest_a=""
269  for i in "$@" ; do
270    if version_test_gt "$i" "$version_find_latest_a" ; then
271      version_find_latest_a="$i"
272    fi
273  done
274  echo "$version_find_latest_a"
275}
276
277# One layer of quotation is eaten by "" and the second by sed; so this turns
278# ' into \'.
279grub_quote () {
280  sed "s/'/'\\\\''/g"
281}
282
283gettext_quoted () {
284  gettext "$@" | grub_quote
285}
286
287# Run the first argument through gettext, and then pass that and all
288# remaining arguments to printf.  This is a useful abbreviation and tends to
289# be easier to type.
290gettext_printf () {
291  gettext_printf_format="$1"
292  shift
293  printf "$(gettext "$gettext_printf_format")" "$@"
294}
295
296uses_abstraction () {
297  device="$1"
298  old_ifs="$IFS"
299  IFS='
300'
301
302  abstraction="`"${grub_probe}" --device ${device} --target=abstraction`"
303  for module in ${abstraction}; do
304    if test "x${module}" = "x$2"; then
305      IFS="$old_ifs"
306      return 0
307    fi
308  done
309  IFS="$old_ifs"
310  return 1
311}
312
313print_option_help () {
314  if test x$print_option_help_wc = x; then
315      if wc -L  </dev/null > /dev/null 2>&1; then
316          print_option_help_wc=-L
317      elif wc -m  </dev/null > /dev/null 2>&1; then
318          print_option_help_wc=-m
319      else
320          print_option_help_wc=-b
321      fi
322  fi
323  if test x$grub_have_fmt = x; then
324      if fmt -w 40  </dev/null > /dev/null 2>&1; then
325          grub_have_fmt=y;
326      else
327          grub_have_fmt=n;
328      fi
329  fi
330  print_option_help_lead="  $1"
331  print_option_help_lspace="$(echo "$print_option_help_lead" | wc $print_option_help_wc)"
332  print_option_help_fill="$((26 - print_option_help_lspace))"
333  printf "%s" "$print_option_help_lead"
334  if test $print_option_help_fill -le 0; then
335      print_option_help_nl=y
336      echo
337  else
338      print_option_help_i=0;
339      while test $print_option_help_i -lt $print_option_help_fill; do
340      printf " "
341          print_option_help_i=$((print_option_help_i+1))
342      done
343      print_option_help_nl=n
344  fi
345  if test x$grub_have_fmt = xy; then
346      print_option_help_split="$(echo "$2" | fmt -w 50)"
347  else
348      print_option_help_split="$2"
349  fi
350  if test x$print_option_help_nl = xy; then
351      echo "$print_option_help_split" | awk \
352          '{ print "                          " $0; }'
353  else
354      echo "$print_option_help_split" | awk 'BEGIN   { n = 0 }
355  { if (n == 1) print "                          " $0; else print $0; n = 1 ; }'
356  fi
357}
358
359grub_fmt () {
360  if test x$grub_have_fmt = x; then
361      if fmt -w 40 < /dev/null > /dev/null; then
362          grub_have_fmt=y;
363      else
364          grub_have_fmt=n;
365      fi
366  fi
367
368  if test x$grub_have_fmt = xy; then
369      fmt
370  else
371      cat
372  fi
373}
374
375grub_tab="      "
376
377grub_add_tab () {
378  sed -e "s/^/$grub_tab/"
379}
380
Note: See TracBrowser for help on using the repository browser.