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

9.2-releaseenter/10releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2releng/10.2stable/10
Last change on this file since c297e38 was c297e38, checked in by Kris Moore <kris@…>, 2 years ago

Add an adjustment to grub-mkconfig_lib, which fixes an issue with
ZFS & RAIDZ partitions

  • 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
17transform="s,x,x,"
18
19prefix="/usr/local"
20exec_prefix="${prefix}"
21datarootdir="${prefix}/share"
22datadir="${datarootdir}"
23bindir="${exec_prefix}/bin"
24sbindir="${exec_prefix}/sbin"
25pkgdatadir="${datadir}/grub"
26
27if test "x$grub_probe" = x; then
28  grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`"
29fi
30if test "x$grub_mkrelpath" = x; then
31  grub_mkrelpath="${bindir}/`echo grub-mkrelpath | sed "${transform}"`"
32fi
33
34if which gettext >/dev/null 2>/dev/null; then
35  :
36else
37  gettext () {
38     printf "%s" "$@"
39  }
40fi
41
42grub_warn ()
43{
44  echo "$(gettext "Warning:")" "$@" >&2
45}
46
47make_system_path_relative_to_its_root ()
48{
49  "${grub_mkrelpath}" "$1"
50}
51
52is_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
87convert_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
109save_default_entry ()
110{
111  if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
112    cat << EOF
113savedefault
114EOF
115  fi
116}
117
118prepare_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  # Abstraction modules aren't auto-loaded.
133  abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
134  for module in ${abstraction} ; do
135    echo "insmod ${module}"
136  done
137 
138  # KPM - 6-24-2013
139  # Add this work-around since GRUB doesn't like to identify ZFS
140  # partitions which are in a raidz configuration, gives Unknown FS error
141  # We can instead look at zpool to see if this device is used though
142  zpool status 2>/dev/null | grep -q "`echo ${device} | sed 's|/dev/||g'`"
143  if [ $? -eq 0 ] ; then
144     fs="zfs"
145  else
146    fs="`"${grub_probe}" --device "${device}" --target=fs`"
147  fi
148  for module in ${fs} ; do
149    echo "insmod ${module}"
150  done
151
152  if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
153      for uuid in "`"${grub_probe}" --device "${device}" --target=cryptodisk_uuid`"; do
154          echo "cryptomount -u $uuid"
155      done
156  fi
157
158  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
159  # otherwise set root as per value in device.map.
160  fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
161  if [ "x$fs_hint" != x ]; then
162    echo "set root='$fs_hint'"
163  fi
164  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
165    hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
166    echo "if [ x\$feature_platform_search_hint = xy ]; then"
167    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
168    echo "else"
169    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
170    echo "fi"
171  fi
172}
173
174grub_get_device_id ()
175{
176  device="$1"
177  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
178    echo "$fs_uuid";
179  else
180    echo "$device"
181  fi
182}
183
184grub_file_is_not_garbage ()
185{
186  if test -f "$1" ; then
187    case "$1" in
188      *.dpkg-*) return 1 ;; # debian dpkg
189      *.rpmsave|*.rpmnew) return 1 ;;
190      README*|*/README*)  return 1 ;; # documentation
191    esac
192  else
193    return 1
194  fi
195  return 0
196}
197
198version_sort ()
199{
200  case $version_sort_sort_has_v in
201    yes)
202      LC_ALL=C sort -V;;
203    no)
204      LC_ALL=C sort -n;;
205    *)
206      if sort -V </dev/null > /dev/null 2>&1; then
207        version_sort_sort_has_v=yes
208        LC_ALL=C sort -V
209      else
210        version_sort_sort_has_v=no
211        LC_ALL=C sort -n
212      fi;;
213   esac
214}
215
216version_test_numeric ()
217{
218  version_test_numeric_a="$1"
219  version_test_numeric_cmp="$2"
220  version_test_numeric_b="$3"
221  if [ "$version_test_numeric_a" = "$version_test_numeric_b" ] ; then
222    case "$version_test_numeric_cmp" in
223      ge|eq|le) return 0 ;;
224      gt|lt) return 1 ;;
225    esac
226  fi
227  if [ "$version_test_numeric_cmp" = "lt" ] ; then
228    version_test_numeric_c="$version_test_numeric_a"
229    version_test_numeric_a="$version_test_numeric_b"
230    version_test_numeric_b="$version_test_numeric_c"
231  fi
232  if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then
233    return 0
234  else
235    return 1
236  fi
237}
238
239version_test_gt ()
240{
241  version_test_gt_a="`echo "$1" | sed -e "s/[^-]*-//"`"
242  version_test_gt_b="`echo "$2" | sed -e "s/[^-]*-//"`"
243  version_test_gt_cmp=gt
244  if [ "x$version_test_gt_b" = "x" ] ; then
245    return 0
246  fi
247  case "$version_test_gt_a:$version_test_gt_b" in
248    *.old:*.old) ;;
249    *.old:*) version_test_gt_a="`echo -n "$version_test_gt_a" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=gt ;;
250    *:*.old) version_test_gt_b="`echo -n "$version_test_gt_b" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=ge ;;
251  esac
252  version_test_numeric "$version_test_gt_a" "$version_test_gt_cmp" "$version_test_gt_b"
253  return "$?"
254}
255
256version_find_latest ()
257{
258  version_find_latest_a=""
259  for i in "$@" ; do
260    if version_test_gt "$i" "$version_find_latest_a" ; then
261      version_find_latest_a="$i"
262    fi
263  done
264  echo "$version_find_latest_a"
265}
266
267# One layer of quotation is eaten by "", the second by sed, and the third by
268# printf; so this turns ' into \'.  Note that you must use the output of
269# this function in a printf format string.
270
271grub_quote () {
272  sed "s/'/'\\\\\\\\''/g"
273}
274
275gettext_quoted () {
276  gettext "$@" | sed "s/'/'\\\\\\\\''/g"
277}
278
279# Run the first argument through gettext_quoted, and then pass that and all
280# remaining arguments to printf.  This is a useful abbreviation and tends to
281# be easier to type.
282gettext_printf () {
283  gettext_printf_format="$1"
284  shift
285  printf "$(gettext "$gettext_printf_format")" "$@"
286}
287
288uses_abstraction () {
289  device="$1"
290
291  abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
292  for module in ${abstraction}; do
293    if test "x${module}" = "x$2"; then
294      return 0
295    fi
296  done
297  return 1
298}
299
300print_option_help () {
301  if test x$print_option_help_wc = x; then
302      if wc -L  </dev/null > /dev/null 2>&1; then
303          print_option_help_wc=-L
304      elif wc -m  </dev/null > /dev/null 2>&1; then
305          print_option_help_wc=-m
306      else
307          print_option_help_wc=-b
308      fi
309  fi
310  if test x$grub_have_fmt = x; then
311      if fmt -w 40  </dev/null > /dev/null 2>&1; then
312          grub_have_fmt=y;
313      else
314          grub_have_fmt=n;
315      fi
316  fi
317  print_option_help_lead="  $1"
318  print_option_help_lspace="$(echo "$print_option_help_lead" | wc $print_option_help_wc)"
319  print_option_help_fill="$((26 - print_option_help_lspace))"
320  printf "%s" "$print_option_help_lead"
321  if test $print_option_help_fill -le 0; then
322      print_option_help_nl=y
323      echo
324  else
325      print_option_help_i=0;
326      while test $print_option_help_i -lt $print_option_help_fill; do
327      printf " "
328          print_option_help_i=$((print_option_help_i+1))
329      done
330      print_option_help_nl=n
331  fi
332  if test x$grub_have_fmt = xy; then
333      print_option_help_split="$(echo "$2" | fmt -w 50)"
334  else
335      print_option_help_split="$2"
336  fi
337  if test x$print_option_help_nl = xy; then
338      echo "$print_option_help_split" | awk \
339          '{ print "                          " $0; }'
340  else
341      echo "$print_option_help_split" | awk 'BEGIN   { n = 0 }
342  { if (n == 1) print "                          " $0; else print $0; n = 1 ; }'
343  fi
344}
345
346grub_fmt () {
347  if test x$grub_have_fmt = x; then
348      if fmt -w 40 < /dev/null > /dev/null; then
349          grub_have_fmt=y;
350      else
351          grub_have_fmt=n;
352      fi
353  fi
354
355  if test x$grub_have_fmt = xy; then
356      fmt
357  else
358      cat
359  fi
360}
Note: See TracBrowser for help on using the repository browser.