00_header.in 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. grub_lang=`echo $LANG | cut -d . -f 1`
  22. export TEXTDOMAIN=@PACKAGE@
  23. export TEXTDOMAINDIR="@localedir@"
  24. . "$pkgdatadir/grub-mkconfig_lib"
  25. # Do this as early as possible, since other commands might depend on it.
  26. # (e.g. the `loadfont' command might need lvm or raid modules)
  27. for i in ${GRUB_PRELOAD_MODULES} ; do
  28. echo "insmod $i"
  29. done
  30. if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
  31. if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
  32. if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
  33. if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi
  34. if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi
  35. if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi
  36. if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
  37. cat << EOF
  38. if [ -s \$prefix/grubenv ]; then
  39. load_env
  40. fi
  41. EOF
  42. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  43. cat <<EOF
  44. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  45. set default="${GRUB_DEFAULT_BUTTON}"
  46. elif [ "\${next_entry}" ] ; then
  47. set default="\${next_entry}"
  48. set next_entry=
  49. save_env next_entry
  50. set boot_once=true
  51. else
  52. set default="${GRUB_DEFAULT}"
  53. fi
  54. EOF
  55. else
  56. cat <<EOF
  57. if [ "\${next_entry}" ] ; then
  58. set default="\${next_entry}"
  59. set next_entry=
  60. save_env next_entry
  61. set boot_once=true
  62. else
  63. set default="${GRUB_DEFAULT}"
  64. fi
  65. EOF
  66. fi
  67. cat <<EOF
  68. if [ x"\${feature_menuentry_id}" = xy ]; then
  69. menuentry_id_option="--id"
  70. else
  71. menuentry_id_option=""
  72. fi
  73. export menuentry_id_option
  74. if [ "\${prev_saved_entry}" ]; then
  75. set saved_entry="\${prev_saved_entry}"
  76. save_env saved_entry
  77. set prev_saved_entry=
  78. save_env prev_saved_entry
  79. set boot_once=true
  80. fi
  81. function savedefault {
  82. if [ -z "\${boot_once}" ]; then
  83. saved_entry="\${chosen}"
  84. save_env saved_entry
  85. fi
  86. }
  87. function load_video {
  88. EOF
  89. if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
  90. cat <<EOF
  91. insmod ${GRUB_VIDEO_BACKEND}
  92. EOF
  93. else
  94. # If all_video.mod isn't available load all modules available
  95. # with versions prior to introduction of all_video.mod
  96. cat <<EOF
  97. if [ x\$feature_all_video_module = xy ]; then
  98. insmod all_video
  99. else
  100. insmod efi_gop
  101. insmod efi_uga
  102. insmod ieee1275_fb
  103. insmod vbe
  104. insmod vga
  105. insmod video_bochs
  106. insmod video_cirrus
  107. fi
  108. EOF
  109. fi
  110. cat <<EOF
  111. }
  112. EOF
  113. serial=0;
  114. gfxterm=0;
  115. for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
  116. if [ xserial = "x$x" ]; then
  117. serial=1;
  118. fi
  119. if [ xgfxterm = "x$x" ]; then
  120. gfxterm=1;
  121. fi
  122. done
  123. if [ "x$serial" = x1 ]; then
  124. if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
  125. grub_warn "$(gettext "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used.")"
  126. GRUB_SERIAL_COMMAND=serial
  127. fi
  128. echo "${GRUB_SERIAL_COMMAND}"
  129. fi
  130. if [ "x$gfxterm" = x1 ]; then
  131. if [ -n "$GRUB_FONT" ] ; then
  132. # Make the font accessible
  133. prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT}"`
  134. cat << EOF
  135. if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
  136. EOF
  137. else
  138. for dir in "${pkgdatadir}" "`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`" /usr/share/grub ; do
  139. for basename in unicode unifont ascii; do
  140. path="${dir}/${basename}.pf2"
  141. if is_path_readable_by_grub "${path}" > /dev/null ; then
  142. font_path="${path}"
  143. else
  144. continue
  145. fi
  146. break 2
  147. done
  148. done
  149. if [ -n "${font_path}" ] ; then
  150. cat << EOF
  151. if [ x\$feature_default_font_path = xy ] ; then
  152. font=unicode
  153. else
  154. EOF
  155. # Make the font accessible
  156. prepare_grub_to_access_device `${grub_probe} --target=device "${font_path}"`
  157. cat << EOF
  158. font="`make_system_path_relative_to_its_root "${font_path}"`"
  159. fi
  160. if loadfont \$font ; then
  161. EOF
  162. else
  163. cat << EOF
  164. if loadfont unicode ; then
  165. EOF
  166. fi
  167. fi
  168. cat << EOF
  169. set gfxmode=${GRUB_GFXMODE}
  170. load_video
  171. insmod gfxterm
  172. EOF
  173. # Gettext variables and module
  174. if [ "x${LANG}" != "xC" ] && [ "x${LANG}" != "x" ]; then
  175. cat << EOF
  176. set locale_dir=\$prefix/locale
  177. set lang=${grub_lang}
  178. insmod gettext
  179. EOF
  180. fi
  181. cat <<EOF
  182. fi
  183. EOF
  184. fi
  185. case x${GRUB_TERMINAL_INPUT} in
  186. x)
  187. # Just use the native terminal
  188. ;;
  189. x*)
  190. cat << EOF
  191. terminal_input ${GRUB_TERMINAL_INPUT}
  192. EOF
  193. ;;
  194. esac
  195. case x${GRUB_TERMINAL_OUTPUT} in
  196. x)
  197. # Just use the native terminal
  198. ;;
  199. x*)
  200. cat << EOF
  201. terminal_output ${GRUB_TERMINAL_OUTPUT}
  202. EOF
  203. ;;
  204. esac
  205. if [ "x$gfxterm" = x1 ]; then
  206. if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
  207. && is_path_readable_by_grub "$GRUB_THEME"; then
  208. gettext_printf "Found theme: %s\n" "$GRUB_THEME" >&2
  209. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"`
  210. cat << EOF
  211. insmod gfxmenu
  212. EOF
  213. themedir="`dirname "$GRUB_THEME"`"
  214. for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
  215. if [ -f "$x" ]; then
  216. cat << EOF
  217. loadfont (\$root)`make_system_path_relative_to_its_root $x`
  218. EOF
  219. fi
  220. done
  221. if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
  222. cat << EOF
  223. insmod jpeg
  224. EOF
  225. fi
  226. if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
  227. cat << EOF
  228. insmod png
  229. EOF
  230. fi
  231. if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
  232. cat << EOF
  233. insmod tga
  234. EOF
  235. fi
  236. cat << EOF
  237. set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
  238. export theme
  239. EOF
  240. elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
  241. && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
  242. gettext_printf "Found background: %s\n" "$GRUB_BACKGROUND" >&2
  243. case "$GRUB_BACKGROUND" in
  244. *.png) reader=png ;;
  245. *.tga) reader=tga ;;
  246. *.jpg|*.jpeg) reader=jpeg ;;
  247. *) gettext "Unsupported image format" >&2; echo >&2; exit 1 ;;
  248. esac
  249. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"`
  250. cat << EOF
  251. insmod $reader
  252. background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
  253. EOF
  254. fi
  255. fi
  256. make_timeout ()
  257. {
  258. if [ "x${3}" != "x" ] ; then
  259. timeout="${2}"
  260. style="${3}"
  261. elif [ "x${1}" != "x" ] && [ "x${1}" != "x0" ] ; then
  262. # Handle the deprecated GRUB_HIDDEN_TIMEOUT scheme.
  263. timeout="${1}"
  264. if [ "x${2}" != "x0" ] ; then
  265. grub_warn "$(gettext "Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.")"
  266. fi
  267. if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
  268. style="hidden"
  269. verbose=
  270. else
  271. style="countdown"
  272. verbose=" --verbose"
  273. fi
  274. else
  275. # No hidden timeout, so treat as GRUB_TIMEOUT_STYLE=menu
  276. timeout="${2}"
  277. style="menu"
  278. fi
  279. cat << EOF
  280. if [ x\$feature_timeout_style = xy ] ; then
  281. set timeout_style=${style}
  282. set timeout=${timeout}
  283. EOF
  284. if [ "x${style}" = "xmenu" ] ; then
  285. cat << EOF
  286. # Fallback normal timeout code in case the timeout_style feature is
  287. # unavailable.
  288. else
  289. set timeout=${timeout}
  290. EOF
  291. else
  292. cat << EOF
  293. # Fallback hidden-timeout code in case the timeout_style feature is
  294. # unavailable.
  295. elif sleep${verbose} --interruptible ${timeout} ; then
  296. set timeout=0
  297. EOF
  298. fi
  299. cat << EOF
  300. fi
  301. EOF
  302. }
  303. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  304. cat <<EOF
  305. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  306. EOF
  307. make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_STYLE_BUTTON}"
  308. echo else
  309. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
  310. echo fi
  311. else
  312. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
  313. fi
  314. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then
  315. cat <<EOF
  316. cmosclean $GRUB_BUTTON_CMOS_ADDRESS
  317. EOF
  318. fi
  319. # Play an initial tune
  320. if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
  321. echo "play ${GRUB_INIT_TUNE}"
  322. fi
  323. if [ "x${GRUB_BADRAM}" != "x" ] ; then
  324. echo "badram ${GRUB_BADRAM}"
  325. fi