2N/A#! /bin/sh
2N/Aset -e
2N/A
2N/A# grub-mkconfig helper script.
2N/A# Copyright (C) 2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc.
2N/A#
2N/A# GRUB is free software: you can redistribute it and/or modify
2N/A# it under the terms of the GNU General Public License as published by
2N/A# the Free Software Foundation, either version 3 of the License, or
2N/A# (at your option) any later version.
2N/A#
2N/A# GRUB is distributed in the hope that it will be useful,
2N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A# GNU General Public License for more details.
2N/A#
2N/A# You should have received a copy of the GNU General Public License
2N/A# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A
2N/Aprefix=@prefix@
2N/Aexec_prefix=@exec_prefix@
2N/Abindir=@bindir@
2N/Alibdir=@libdir@
2N/Adatarootdir=@datarootdir@
2N/A. ${libdir}/@PACKAGE@/grub-mkconfig_lib
2N/A
2N/Aexport TEXTDOMAIN=@PACKAGE@
2N/Aexport TEXTDOMAINDIR=@localedir@
2N/A
2N/ACLASS="--class os"
2N/A
2N/Acase "${GRUB_DISTRIBUTOR}" in
2N/A Debian)
2N/A OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD"
2N/A CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) --class gnu-kfreebsd --class gnu ${CLASS}"
2N/A ;;
2N/A *)
2N/A OS="FreeBSD"
2N/A CLASS="--class freebsd --class bsd ${CLASS}"
2N/A ;;
2N/Aesac
2N/A
2N/Aload_kfreebsd_module ()
2N/A{
2N/A mod="$1"
2N/A allow_fail="$2"
2N/A
2N/A if ! test -e "${module_dir}/${mod}.ko" ; then
2N/A if [ "${allow_fail}" = "true" ] ; then
2N/A # Return silently
2N/A return
2N/A else
2N/A # Print an error and fail.
2N/A ls "${module_dir}/${mod}.ko" > /dev/null
2N/A fi
2N/A fi
2N/A
2N/A if [ -z "${prepare_module_dir_cache}" ]; then
2N/A prepare_module_dir_cache="$(prepare_grub_to_access_device $(grub-probe -t device "${module_dir}") | sed -e "s/^/\t/")"
2N/A fi
2N/A
2N/A printf '%s\n' "${prepare_module_dir_cache}"
2N/A cat << EOF
2N/A kfreebsd_module_elf ${module_dir_rel}/${mod}.ko
2N/AEOF
2N/A}
2N/A
2N/Akfreebsd_entry ()
2N/A{
2N/A os="$1"
2N/A version="$2"
2N/A recovery="$3"
2N/A args="$4"
2N/A if ${recovery} ; then
2N/A title="$(gettext_quoted "%s, with kFreeBSD %s (recovery mode)")"
2N/A else
2N/A title="$(gettext_quoted "%s, with kFreeBSD %s")"
2N/A fi
2N/A printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
2N/A if ! ${recovery} ; then
2N/A save_default_entry | sed -e "s/^/\t/"
2N/A fi
2N/A if [ -z "${prepare_boot_cache}" ]; then
2N/A prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
2N/A fi
2N/A
2N/A printf '%s\n' "${prepare_boot_cache}"
2N/A message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})"
2N/A cat << EOF
2N/A echo '$message'
2N/A kfreebsd ${rel_dirname}/${basename} ${args}
2N/AEOF
2N/A
2N/A if test -n "${devices}" ; then
2N/A cat << EOF
2N/A kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename}
2N/AEOF
2N/A fi
2N/A
2N/A load_kfreebsd_module acpi true
2N/A
2N/A for abstraction in dummy $(grub-probe -t abstraction --device ${GRUB_DEVICE}) ; do
2N/A case $abstraction in
2N/A lvm) load_kfreebsd_module geom_linux_lvm false ;;
2N/A esac
2N/A done
2N/A
2N/A case "${kfreebsd_fs}" in
2N/A zfs)
2N/A load_kfreebsd_module opensolaris false
2N/A
2N/A ls "${dirname}/zfs/zpool.cache" > /dev/null
2N/A printf '%s\n' "${prepare_boot_cache}"
2N/A cat << EOF
2N/A kfreebsd_module ${rel_dirname}/zfs/zpool.cache type=/boot/zfs/zpool.cache
2N/AEOF
2N/A ;;
2N/A esac
2N/A
2N/A if [ x${kfreebsd_fs} = xufs ]; then
2N/A load_kfreebsd_module ${kfreebsd_fs} true
2N/A else
2N/A load_kfreebsd_module ${kfreebsd_fs} false
2N/A fi
2N/A
2N/A cat << EOF
2N/A set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device}
2N/A set kFreeBSD.vfs.root.mountfrom.options=rw
2N/A}
2N/AEOF
2N/A}
2N/A
2N/Alist=`for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
2N/A if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
2N/A done`
2N/Aprepare_boot_cache=
2N/A
2N/Awhile [ "x$list" != "x" ] ; do
2N/A kfreebsd=`version_find_latest $list`
2N/A echo "Found kernel of FreeBSD: $kfreebsd" >&2
2N/A basename=`basename $kfreebsd`
2N/A dirname=`dirname $kfreebsd`
2N/A rel_dirname=`make_system_path_relative_to_its_root $dirname`
2N/A
2N/A if [ -f /boot/device.hints ] ; then
2N/A devices=/boot/device.hints
2N/A devices_basename=`basename $devices`
2N/A devices_dirname=`dirname $devices`
2N/A devices_rel_dirname=`make_system_path_relative_to_its_root $devices_dirname`
2N/A fi
2N/A
2N/A case ${GRUB_FS} in
2N/A ufs1 | ufs2) kfreebsd_fs=ufs ;;
2N/A ext2) kfreebsd_fs=ext2fs ;;
2N/A *) kfreebsd_fs=${GRUB_FS} ;;
2N/A esac
2N/A
2N/A case ${GRUB_FS} in
2N/A zfs)
2N/A # zpool name
2N/A kfreebsd_device=$(grub-probe -t fs_label --device ${GRUB_DEVICE})
2N/A # filesystem name (empty string for the main filesystem)
2N/A kfreebsd_device="${kfreebsd_device}$(${grub_mkrelpath} / | sed -e "s,/*@$,,")"
2N/A ;;
2N/A *)
2N/A kfreebsd_device=${kfreebsd_fs}id/${GRUB_DEVICE_UUID}
2N/A # Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
2N/A # as an UUID
2N/A if [ "x${GRUB_DISTRIBUTOR}" = "xDebian" ] \
2N/A && ! (cat /etc/fstab | awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
2N/A | grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev/null); then
2N/A kfreebsd_device=${GRUB_DEVICE}
2N/A fi
2N/A ;;
2N/A esac
2N/A
2N/A version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
2N/A alt_version=`echo $version | sed -e "s,\.old$,,g"`
2N/A
2N/A module_dir=
2N/A for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
2N/A "/boot/kernel"; do
2N/A if test -e "$i" ; then
2N/A module_dir="$i"
2N/A break
2N/A fi
2N/A done
2N/A if test -n "${module_dir}" ; then
2N/A echo "Found kernel module directory: ${module_dir}" >&2
2N/A module_dir_rel=$(make_system_path_relative_to_its_root $module_dir)
2N/A fi
2N/A
2N/A kfreebsd_entry "${OS}" "${version}" false
2N/A if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
2N/A kfreebsd_entry "${OS}" "${version}" true "-s"
2N/A fi
2N/A
2N/A list=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | tr '\n' ' '`
2N/Adone