2N/A#! /bin/sh
2N/Aset -e
2N/A
2N/A# grub-mkconfig helper script.
2N/A# Copyright (C) 2006,2007,2008,2009,2010 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/Aif [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
2N/A OS="NetBSD"
2N/Aelse
2N/A OS="${GRUB_DISTRIBUTOR} NetBSD"
2N/Afi
2N/A
2N/Anetbsd_load_fs_module ()
2N/A{
2N/A loader="$1" # "knetbsd" or "multiboot"
2N/A kernel="$2" # absolute path to the kernel file
2N/A
2N/A case $(zcat -f "${kernel}" | file -bL - | cut -d , -f 2 | tr -d ' ') in
2N/A Intel80386)
2N/A karch="i386"
2N/A ;;
2N/A x86-64)
2N/A karch="amd64"
2N/A ;;
2N/A *)
2N/A return
2N/A ;;
2N/A esac
2N/A
2N/A case $(${grub_probe} --target=fs -d ${GRUB_DEVICE}) in
2N/A ext2)
2N/A kmod="ext2fs"
2N/A ;;
2N/A fat)
2N/A kmod="msdosfs"
2N/A ;;
2N/A ntfs)
2N/A kmod="ntfs"
2N/A ;;
2N/A ufs*)
2N/A kmod="ffs"
2N/A ;;
2N/A *)
2N/A return
2N/A ;;
2N/A esac
2N/A
2N/A kversion=$(zcat -f "${kernel}" | strings | sed -n -e '/^@(#)NetBSD/ { s/^@(#)NetBSD \([0-9\.]*\) .*$/\1/g ; p ; q ; }')
2N/A kmodule="/stand/${karch}/${kversion}/modules/${kmod}/${kmod}.kmod"
2N/A
2N/A if test -z "$karch" -o -z "$kversion" -o ! -f "${kmodule}"; then
2N/A return
2N/A fi
2N/A
2N/A kmodule_rel=$(make_system_path_relative_to_its_root "$kmodule") || return
2N/A prepare_grub_to_access_device $(${grub_probe} -t device "${kmodule}") | sed -e 's,^, ,'
2N/A case "${loader}" in
2N/A knetbsd)
2N/A printf "\tknetbsd_module_elf %s\n" "${kmodule_rel}"
2N/A ;;
2N/A multiboot)
2N/A printf "\tmodule %s\n" "${kmodule_rel}"
2N/A ;;
2N/A esac
2N/A}
2N/A
2N/Anetbsd_entry ()
2N/A{
2N/A loader="$1" # "knetbsd" or "multiboot"
2N/A kernel="$2" # absolute path to the kernel file
2N/A recovery="$3" # is this is a recovery entry?
2N/A args="$4" # extra arguments appended to loader command
2N/A
2N/A kroot_device="$(echo ${GRUB_DEVICE} | sed -e 's,^/dev/r,,')"
2N/A if ${recovery} ; then
2N/A title="$(gettext_quoted "%s, with kernel %s (via %s, recovery mode)")"
2N/A else
2N/A title="$(gettext_quoted "%s, with kernel %s (via %s)")"
2N/A fi
2N/A
2N/A printf "menuentry \"${title}\" {\n" \
2N/A "${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}"
2N/A printf "%s\n" "${prepare_boot_cache}"
2N/A case "${loader}" in
2N/A knetbsd)
2N/A printf "\tknetbsd %s -r %s %s\n" \
2N/A "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
2N/A ;;
2N/A multiboot)
2N/A printf "\tmultiboot %s %s root=%s %s\n" \
2N/A "${kernel}" "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
2N/A ;;
2N/A esac
2N/A
2N/A netbsd_load_fs_module "${loader}" "${kernel}"
2N/A
2N/A printf "}\n"
2N/A}
2N/A
2N/Aprepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e 's,^, ,')"
2N/A
2N/A# We look for NetBSD kernels in / but not in subdirectories. We simply
2N/A# pick all statically linked ELF executable files (or links) in / with a
2N/A# name that starts with `netbsd'.
2N/Apattern="^ELF[^,]*executable.*statically linked"
2N/Afor k in $(ls -t /netbsd*) ; do
2N/A if ! grub_file_is_not_garbage "$k" ; then
2N/A continue
2N/A fi
2N/A if ! (zcat -f "$k" | file -bL - | grep -q "${pattern}") 2>/dev/null ; then
2N/A continue
2N/A fi
2N/A
2N/A echo "Found NetBSD kernel: $k" >&2
2N/A netbsd_entry "knetbsd" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
2N/A netbsd_entry "multiboot" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
2N/A if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
2N/A netbsd_entry "knetbsd" "$k" true "-s"
2N/A netbsd_entry "multiboot" "$k" true "-s"
2N/A fi
2N/Adone