]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Add grub-mkconfig support for NetBSD.
authorGrégoire Sutre <gregoire.sutre@gmail.com>
Mon, 19 Apr 2010 19:25:41 +0000 (21:25 +0200)
committerGrégoire Sutre <gregoire.sutre@gmail.com>
Mon, 19 Apr 2010 19:25:41 +0000 (21:25 +0200)
ChangeLog
po/POTFILES-shell
util/grub-mkconfig.in
util/grub-mkconfig_lib.in
util/grub.d/10_netbsd.in [new file with mode: 0644]

index 57565fcb392e685f122c9b315b87ca8fc8112965..a80606f46ed49239cb6f1092926b17e750672ecf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-04-19  Grégoire Sutre  <gregoire.sutre@gmail.com>
+
+       Add grub-mkconfig support for NetBSD.
+
+       * util/grub.d/10_netbsd.in: grub-mkconfig helper script for NetBSD.
+       * util/grub-mkconfig.in: export new NetBSD specific variables.
+       * po/POTFILES-shell: added 10_netbsd.in.
+       * util/grub-mkconfig_lib.in: check for gettext binary, default to echo.
+
 2010-04-19  BVK Chaitanya  <bvk.groups@gmail.com>
 
        Fix emu build with grub-emu-pci and grub-emu-modules.
index cb28d331b2afa70211ed1881dc1ff0451eb179cb..90d2b978c79509df78cbe0f0831ce193d4dfeed4 100644 (file)
@@ -2,3 +2,4 @@
 # Shell language are included here.
 util/grub.d/10_kfreebsd.in
 util/grub.d/10_linux.in
+util/grub.d/10_netbsd.in
index 4e476ae066d02449b621c7c0f949e277b8028d18..85212f8fc0b30efc53a9032e9b3bd272e7d6df7e 100644 (file)
@@ -239,11 +239,14 @@ export GRUB_DEFAULT \
   GRUB_DISTRIBUTOR \
   GRUB_CMDLINE_LINUX \
   GRUB_CMDLINE_LINUX_DEFAULT \
+  GRUB_CMDLINE_NETBSD \
+  GRUB_CMDLINE_NETBSD_DEFAULT \
   GRUB_TERMINAL_INPUT \
   GRUB_TERMINAL_OUTPUT \
   GRUB_SERIAL_COMMAND \
   GRUB_DISABLE_LINUX_UUID \
   GRUB_DISABLE_LINUX_RECOVERY \
+  GRUB_DISABLE_NETBSD_RECOVERY \
   GRUB_GFXMODE \
   GRUB_BACKGROUND \
   GRUB_THEME \
index a4151348ca92a1393c89b62e99f3861495f90b76..831bef8466a6f416905c194c607a661d144d45da 100644 (file)
@@ -31,6 +31,12 @@ if test "x$grub_mkrelpath" = x; then
   grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
 fi
 
+if $(which gettext >/dev/null 2>/dev/null) ; then
+  gettext="gettext"
+else
+  gettext="echo"
+fi
+
 grub_warn ()
 {
   echo "Warning: $@" >&2
@@ -190,5 +196,5 @@ version_find_latest ()
 }
 
 gettext_quoted () {
-  gettext "$@" | sed "s/'/'\\\\''/g"
+  $gettext "$@" | sed "s/'/'\\\\''/g"
 }
diff --git a/util/grub.d/10_netbsd.in b/util/grub.d/10_netbsd.in
new file mode 100644 (file)
index 0000000..7e5fb34
--- /dev/null
@@ -0,0 +1,86 @@
+#! /bin/sh -e
+
+# grub-mkconfig helper script.
+# Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
+#
+# GRUB is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GRUB is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+bindir=@bindir@
+libdir=@libdir@
+. ${libdir}/grub/grub-mkconfig_lib
+
+export TEXTDOMAIN=@PACKAGE@
+export TEXTDOMAINDIR=@localedir@
+
+if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
+  OS=NetBSD
+else
+  OS="${GRUB_DISTRIBUTOR} NetBSD"
+fi
+
+netbsd_entry ()
+{
+  loader="$1"  # "knetbsd" or "multiboot"
+  kernel="$2"  # absolute path to the kernel file
+  recovery="$3"        # is this is a recovery entry?
+  args="$4"    # extra arguments appended to loader command
+
+  kroot_device="$(echo ${GRUB_DEVICE} | sed -e 's,^/dev/r,,')"
+  if ${recovery} ; then
+    title="$(gettext_quoted "%s, with kernel %s (via %s, recovery mode)")"
+  else
+    title="$(gettext_quoted "%s, with kernel %s (via %s)")"
+  fi
+
+  printf "menuentry \"${title}\" {\n" \
+    "${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}"
+  printf "%s\n" "${prepare_boot_cache}"
+  case "${loader}" in
+    knetbsd)
+      printf "\tknetbsd %s -r %s %s\n" \
+        "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
+      ;;
+    multiboot)
+      printf "\tmultiboot %s %s root=%s %s\n" \
+        "${kernel}" "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
+      ;;
+  esac
+  printf "}\n"
+}
+
+prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e 's,^,      ,')"
+
+# We look for NetBSD kernels in / but not in subdirectories.  We simply
+# pick all statically linked ELF executable files (or links) in / with a
+# name that starts with `netbsd'.
+pattern="^ELF[^,]*executable.*statically linked"
+for k in $(ls -t /netbsd*) ; do
+  if ! grub_file_is_not_garbage "$k" ; then
+    continue
+  fi
+  if ! ((file -bL "$k" | grep -q "${pattern}") ||
+        (zcat "$k" | file -bL - | grep -q "${pattern}")) 2>/dev/null ; then
+    continue
+  fi
+
+  echo "Found NetBSD kernel: $k" >&2
+  netbsd_entry "knetbsd"   "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
+  netbsd_entry "multiboot" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
+  if [ "x${GRUB_DISABLE_NETBSD_RECOVERY}" != "xtrue" ]; then
+    netbsd_entry "knetbsd"   "$k" true "-s"
+    netbsd_entry "multiboot" "$k" true "-s"
+  fi
+done