source: grub-pc/trunk/fuentes/.pc/mkconfig-kernels-infloop.patch/util/grub.d/10_kfreebsd.in @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 7.8 KB
Line 
1#! /bin/sh
2set -e
3
4# grub-mkconfig helper script.
5# Copyright (C) 2006,2007,2008,2009,2010,2011  Free Software Foundation, Inc.
6#
7# GRUB is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# GRUB is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# 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
20prefix="@prefix@"
21exec_prefix="@exec_prefix@"
22datarootdir="@datarootdir@"
23. "@datadir@/@PACKAGE@/grub-mkconfig_lib"
24
25export TEXTDOMAIN=@PACKAGE@
26export TEXTDOMAINDIR="@localedir@"
27
28CLASS="--class os"
29
30case "${GRUB_DISTRIBUTOR}" in
31  Debian)
32        OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD"
33        CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') --class gnu-kfreebsd --class gnu ${CLASS}"
34  ;;
35  *)
36        OS="FreeBSD"
37        CLASS="--class freebsd --class bsd ${CLASS}"
38  ;;
39esac
40
41load_kfreebsd_module ()
42{
43  mod="$1"
44  allow_fail="$2"
45
46  if ! test -e "${module_dir}/${mod}.ko" ; then
47    if [ "${allow_fail}" = "true" ] ; then
48      # Return silently
49      return
50    else
51      # Print an error and fail.
52      ls "${module_dir}/${mod}.ko" > /dev/null
53    fi
54  fi
55
56  if [ -z "${prepare_module_dir_cache}" ]; then
57    prepare_module_dir_cache="$(prepare_grub_to_access_device $(${grub_probe} -t device "${module_dir}") | grub_add_tab)"
58  fi
59
60  printf '%s\n' "${prepare_module_dir_cache}"
61  cat << EOF
62        kfreebsd_module_elf     ${module_dir_rel}/${mod}.ko
63EOF
64}
65
66title_correction_code=
67
68kfreebsd_entry ()
69{
70  os="$1"
71  version="$2"
72  type="$3"
73  args="$4"
74  if [ -z "$boot_device_id" ]; then
75      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
76  fi
77  if [ x$type != xsimple ] ; then
78      if [ x$type = xrecovery ] ; then
79          title="$(gettext_printf "%s, with kFreeBSD %s (%s)" "${os}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")")"
80      else
81          title="$(gettext_printf "%s, with kFreeBSD %s" "${os}" "${version}")"
82      fi
83      replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
84      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
85          quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
86          title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
87          grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "kfreebsd-advanced-$boot_device_id>kfreebsd-$version-$type-$boot_device_id")"
88      fi
89      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'kfreebsd-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
90  else
91      echo "menuentry '$(echo "$OS" | grub_quote)' ${CLASS} \$menuentry_id_option 'kfreebsd-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
92  fi
93  if [ x$type != xrecovery ] ; then
94      save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
95  fi
96  if [ -z "${prepare_boot_cache}" ]; then
97    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
98  fi
99
100  printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
101  message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})"
102  sed "s/^/$submenu_indentation/" << EOF
103        echo                    '$(echo "$message" | grub_quote)'
104        kfreebsd                ${rel_dirname}/${basename} ${args}
105EOF
106
107  if test -n "${devices}" ; then
108      sed "s/^/$submenu_indentation/" << EOF
109        kfreebsd_loadenv        ${devices_rel_dirname}/${devices_basename}
110EOF
111  fi
112
113  load_kfreebsd_module acpi true
114
115  for abstraction in dummy $(${grub_probe} -t abstraction --device ${GRUB_DEVICE}) ; do
116    case $abstraction in
117      lvm) load_kfreebsd_module geom_linux_lvm false ;;
118    esac
119  done
120
121  case "${kfreebsd_fs}" in
122    zfs)
123      load_kfreebsd_module opensolaris false
124
125      ls "/boot/zfs/zpool.cache" > /dev/null
126      printf '%s\n' "${prepare_boot_cache}"
127      sed "s/^/$submenu_indentation/" << EOF
128        kfreebsd_module         $(make_system_path_relative_to_its_root /boot)/zfs/zpool.cache type=/boot/zfs/zpool.cache
129EOF
130    ;;
131  esac
132
133  if [ x${kfreebsd_fs} = xufs ]; then
134        load_kfreebsd_module ${kfreebsd_fs} true | sed "s/^/$submenu_indentation/"
135  else
136        load_kfreebsd_module ${kfreebsd_fs} false | sed "s/^/$submenu_indentation/"
137  fi
138
139  sed "s/^/$submenu_indentation/" << EOF
140        set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device}
141        set kFreeBSD.vfs.root.mountfrom.options=rw
142}
143EOF
144}
145
146list=`for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
147        if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
148      done`
149prepare_boot_cache=
150boot_device_id=
151title_correction_code=
152
153# Extra indentation to add to menu entries in a submenu. We're not in a submenu
154# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
155submenu_indentation=""
156
157is_top_level=true
158
159while [ "x$list" != "x" ] ; do
160  kfreebsd=`version_find_latest $list`
161  gettext_printf "Found kernel of FreeBSD: %s\n" "$kfreebsd" >&2
162  basename=`basename $kfreebsd`
163  dirname=`dirname $kfreebsd`
164  rel_dirname=`make_system_path_relative_to_its_root $dirname`
165
166  if [ -f /boot/device.hints ] ; then
167    devices=/boot/device.hints
168    devices_basename=`basename $devices`
169    devices_dirname=`dirname $devices`
170    devices_rel_dirname=`make_system_path_relative_to_its_root $devices_dirname`
171  fi
172
173  case ${GRUB_FS} in
174    ufs1 | ufs2)        kfreebsd_fs=ufs ;;
175    ext2)               kfreebsd_fs=ext2fs ;;
176    *)                  kfreebsd_fs=${GRUB_FS} ;;
177  esac
178
179  case ${GRUB_FS} in
180    zfs)
181                        # zpool name
182                        kfreebsd_device=$(${grub_probe} -t fs_label --device ${GRUB_DEVICE})
183                        # filesystem name (empty string for the main filesystem)
184                        kfreebsd_device="${kfreebsd_device}$(${grub_mkrelpath} / | sed -e "s,/*@$,,")"
185    ;;
186    *)
187          kfreebsd_device=${kfreebsd_fs}id/${GRUB_DEVICE_UUID}
188          # Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
189          # as an UUID
190          if [ "x${GRUB_DISTRIBUTOR}" = "xDebian" ] \
191              && ! (cat /etc/fstab | awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
192              | grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev/null); then
193              kfreebsd_device=${GRUB_DEVICE}
194          fi
195          ;;
196  esac
197
198  version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
199  alt_version=`echo $version | sed -e "s,\.old$,,g"`
200
201  module_dir=
202  for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
203      "/boot/kernel"; do
204    if test -e "$i" ; then
205      module_dir="$i"
206      break
207    fi
208  done
209  if test -n "${module_dir}" ; then
210    gettext_printf "Found kernel module directory: %s\n" "${module_dir}" >&2
211    module_dir_rel=$(make_system_path_relative_to_its_root $module_dir)
212  fi
213
214  if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
215      kfreebsd_entry "${OS}" "${version}" simple
216      submenu_indentation="$grub_tab"
217   
218      if [ -z "$boot_device_id" ]; then
219          boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
220      fi
221      # TRANSLATORS: %s is replaced with an OS name
222      echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'kfreebsd-advanced-$boot_device_id' {"
223      is_top_level=false
224  fi
225
226  kfreebsd_entry "${OS}" "${version}" advanced
227  if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
228    kfreebsd_entry "${OS}" "${version}" recovery "-s"
229  fi
230
231  list=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | tr '\n' ' '`
232done
233
234# If at least one kernel was found, then we need to
235# add a closing '}' for the submenu command.
236if [ x"$is_top_level" != xtrue ]; then
237  echo '}'
238fi
239
240echo "$title_correction_code"
241
Note: See TracBrowser for help on using the repository browser.