10_netbsd.in 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #! /bin/sh
  2. set -e
  3. # grub-mkconfig helper script.
  4. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  5. #
  6. # GRUB is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # GRUB is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. prefix="@prefix@"
  19. exec_prefix="@exec_prefix@"
  20. datarootdir="@datarootdir@"
  21. . "$pkgdatadir/grub-mkconfig_lib"
  22. export TEXTDOMAIN=@PACKAGE@
  23. export TEXTDOMAINDIR="@localedir@"
  24. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  25. OS="NetBSD"
  26. else
  27. OS="${GRUB_DISTRIBUTOR} NetBSD"
  28. fi
  29. netbsd_load_fs_module ()
  30. {
  31. loader="$1" # "knetbsd" or "multiboot"
  32. kernel="$2" # absolute path to the kernel file
  33. case $(zcat -f "${kernel}" | file -bL - | cut -d , -f 2 | tr -d ' ') in
  34. Intel80386)
  35. karch="i386"
  36. ;;
  37. x86-64)
  38. karch="amd64"
  39. ;;
  40. *)
  41. return
  42. ;;
  43. esac
  44. case $(${grub_probe} --target=fs -d ${GRUB_DEVICE}) in
  45. ext2)
  46. kmod="ext2fs"
  47. ;;
  48. fat)
  49. kmod="msdosfs"
  50. ;;
  51. ntfs)
  52. kmod="ntfs"
  53. ;;
  54. ufs*)
  55. kmod="ffs"
  56. ;;
  57. *)
  58. return
  59. ;;
  60. esac
  61. kversion=$(zcat -f "${kernel}" | strings | sed -n -e '/^@(#)NetBSD/ { s/^@(#)NetBSD \([0-9\.]*\) .*$/\1/g ; p ; q ; }')
  62. kmodule="/stand/${karch}/${kversion}/modules/${kmod}/${kmod}.kmod"
  63. if test -z "$karch" || test -z "$kversion" || test ! -f "${kmodule}"; then
  64. return
  65. fi
  66. kmodule_rel=$(make_system_path_relative_to_its_root "$kmodule") || return
  67. prepare_grub_to_access_device $(${grub_probe} -t device "${kmodule}") | sed -e 's,^, ,' | sed "s/^/$submenu_indentation/"
  68. case "${loader}" in
  69. knetbsd)
  70. printf "${grub_tab}knetbsd_module_elf %s\n" "${kmodule_rel}" | sed "s/^/$submenu_indentation/"
  71. ;;
  72. multiboot)
  73. printf "${grub_tab}module %s\n" "${kmodule_rel}" | sed "s/^/$submenu_indentation/"
  74. ;;
  75. esac
  76. }
  77. title_correction_code=
  78. netbsd_entry ()
  79. {
  80. loader="$1" # "knetbsd" or "multiboot"
  81. kernel="$2" # absolute path to the kernel file
  82. type="$3"
  83. args="$4" # extra arguments appended to loader command
  84. kroot_device="$(echo ${GRUB_DEVICE} | sed -e 's,^/dev/r,,')"
  85. if [ -z "$boot_device_id" ]; then
  86. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  87. fi
  88. if [ x$type != xsimple ] ; then
  89. if [ x$type = xrecovery ] ; then
  90. title="$(gettext_printf "%s, with kernel %s (via %s, recovery mode)" "${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}")"
  91. else
  92. title="$(gettext_printf "%s, with kernel %s (via %s)" "${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}")"
  93. fi
  94. replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  95. if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  96. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  97. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  98. 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" "netbsd-advanced-$boot_device_id>netbsd-${loader}-$kernel-$type-$boot_device_id")"
  99. fi
  100. echo "menuentry '$(echo "$title" | grub_quote)' \$menuentry_id_option 'netbsd-${loader}-$kernel-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  101. else
  102. echo "menuentry '$(echo "$OS" | grub_quote)' \$menuentry_id_option 'netbsd-${loader}-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  103. fi
  104. printf "%s\n" "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  105. case "${loader}" in
  106. knetbsd)
  107. printf "${grub_tab}knetbsd %s -r %s %s\n" \
  108. "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}" | sed "s/^/$submenu_indentation/"
  109. ;;
  110. multiboot)
  111. printf "${grub_tab}multiboot %s %s root=%s %s\n" \
  112. "${kernel}" "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}" | sed "s/^/$submenu_indentation/"
  113. ;;
  114. esac
  115. netbsd_load_fs_module "${loader}" "${kernel}"
  116. printf "}\n" | sed "s/^/$submenu_indentation/"
  117. }
  118. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e 's,^, ,')"
  119. boot_device_id=
  120. # We look for NetBSD kernels in / but not in subdirectories. We simply
  121. # pick all statically linked ELF executable files (or links) in / with a
  122. # name that starts with `netbsd'.
  123. pattern="^ELF[^,]*executable.*statically linked"
  124. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  125. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  126. submenu_indentation=""
  127. is_top_level=true
  128. for k in /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do
  129. if ! grub_file_is_not_garbage "$k" ; then
  130. continue
  131. fi
  132. if ! (zcat -f "$k" | file -bL - | grep -q "${pattern}") 2>/dev/null ; then
  133. continue
  134. fi
  135. gettext_printf "Found NetBSD kernel: %s\n" "$k" >&2
  136. if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
  137. netbsd_entry "knetbsd" "$k" simple "${GRUB_CMDLINE_NETBSD_DEFAULT}"
  138. submenu_indentation="$grub_tab"
  139. if [ -z "$boot_device_id" ]; then
  140. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  141. fi
  142. # TRANSLATORS: %s is replaced with an OS name
  143. echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'netbsd-advanced-$boot_device_id' {"
  144. is_top_level=false
  145. fi
  146. netbsd_entry "knetbsd" "$k" advanced "${GRUB_CMDLINE_NETBSD_DEFAULT}"
  147. netbsd_entry "multiboot" "$k" advanced "${GRUB_CMDLINE_NETBSD_DEFAULT}"
  148. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  149. netbsd_entry "knetbsd" "$k" recovery "-s"
  150. netbsd_entry "multiboot" "$k" recovery "-s"
  151. fi
  152. done
  153. # If at least one kernel was found, then we need to
  154. # add a closing '}' for the submenu command.
  155. if [ x"$is_top_level" != xtrue ]; then
  156. echo '}'
  157. fi
  158. echo "$title_correction_code"