digrouz

/mnt/gentoo/etc/grub.d/00_header

Jan 16th, 2012
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /mnt/gentoo/etc/grub.d/00_header
  2. #! /bin/sh
  3. set -e
  4.  
  5. # grub-mkconfig helper script.
  6. # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  7. #
  8. # GRUB is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # GRUB is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  20.  
  21. transform="s,grub,grub2,"
  22.  
  23. prefix=/usr
  24. exec_prefix=${prefix}
  25. libdir=/lib64
  26. locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}`
  27. grub_lang=`echo $LANG | cut -d . -f 1`
  28.  
  29. . ${libdir}/grub/grub-mkconfig_lib
  30.  
  31. # Do this as early as possible, since other commands might depend on it.
  32. # (e.g. the `loadfont' command might need lvm or raid modules)
  33. for i in ${GRUB_PRELOAD_MODULES} ; do
  34.   echo "insmod $i"
  35. done
  36.  
  37. if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
  38. if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
  39. if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
  40. if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi
  41.  
  42. if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi
  43. if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi
  44. if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
  45.  
  46. cat << EOF
  47. if [ -s \$prefix/grubenv ]; then
  48.   load_env
  49. fi
  50. EOF
  51. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  52.     cat <<EOF
  53. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  54.    set default="${GRUB_DEFAULT_BUTTON}"
  55. else
  56.    set default="${GRUB_DEFAULT}"
  57. fi
  58. EOF
  59. else
  60.     cat <<EOF
  61. set default="${GRUB_DEFAULT}"
  62. EOF
  63. fi
  64. cat <<EOF
  65. if [ "\${prev_saved_entry}" ]; then
  66.   set saved_entry="\${prev_saved_entry}"
  67.   save_env saved_entry
  68.   set prev_saved_entry=
  69.   save_env prev_saved_entry
  70.   set boot_once=true
  71. fi
  72.  
  73. function savedefault {
  74.   if [ -z "\${boot_once}" ]; then
  75.     saved_entry="\${chosen}"
  76.     save_env saved_entry
  77.   fi
  78. }
  79.  
  80. function load_video {
  81. EOF
  82. if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
  83.     cat <<EOF
  84.   insmod ${GRUB_VIDEO_BACKEND}
  85. EOF
  86. else
  87.     # Insert all available backends; GRUB will use the most appropriate.
  88.     have_video=0;
  89.     for backend in $(cat "${GRUB_PREFIX}/video.lst"); do
  90.         have_video=1;
  91.         cat <<EOF
  92.   insmod ${backend}
  93. EOF
  94.     done
  95.     if [ x$have_video = x0 ]; then
  96.         echo "true"
  97.     fi
  98. fi
  99. cat <<EOF
  100. }
  101.  
  102. EOF
  103.  
  104. serial=0;
  105. gfxterm=0;
  106. for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
  107.     if [ xserial = "x$x" ]; then
  108.         serial=1;
  109.     fi
  110.     if [ xgfxterm = "x$x" ]; then
  111.         gfxterm=1;
  112.     fi
  113. done
  114.  
  115. if [ "x$serial" = x1 ]; then
  116.     if ! test -e ${GRUB_PREFIX}/serial.mod ; then
  117.         echo "Serial terminal not available on this platform." >&2 ; exit 1
  118.     fi
  119.  
  120.     if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
  121.         grub_warn "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used."
  122.         GRUB_SERIAL_COMMAND=serial
  123.     fi
  124.     echo "${GRUB_SERIAL_COMMAND}"
  125. fi
  126.  
  127. if [ "x$gfxterm" = x1 ]; then
  128.     # Make the font accessible
  129.     prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT_PATH}"`
  130.  
  131.     cat << EOF
  132. if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT_PATH}"` ; then
  133.   set gfxmode=${GRUB_GFXMODE}
  134.   load_video
  135.   insmod gfxterm
  136. EOF
  137.  
  138. # Gettext variables and module
  139. if [ "x${LANG}" != "xC" ] && [ -d "${locale_dir}" ] ; then
  140.     prepare_grub_to_access_device $(${grub_probe} --target=device ${locale_dir}) | sed -e "s/^/  /"
  141.   cat << EOF
  142.   set locale_dir=(\$root)$(make_system_path_relative_to_its_root ${locale_dir})
  143.   set lang=${grub_lang}
  144.   insmod gettext
  145. EOF
  146. fi
  147.  
  148. cat <<EOF
  149. fi
  150. EOF
  151. fi
  152.  
  153. case x${GRUB_TERMINAL_INPUT} in
  154.   x)
  155.     # Just use the native terminal
  156.   ;;
  157.   x*)
  158.     cat << EOF
  159. terminal_input ${GRUB_TERMINAL_INPUT}
  160. EOF
  161.   ;;
  162. esac
  163.  
  164. case x${GRUB_TERMINAL_OUTPUT} in
  165.   x)
  166.     # Just use the native terminal
  167.   ;;
  168.   x*)
  169.     cat << EOF
  170. terminal_output ${GRUB_TERMINAL_OUTPUT}
  171. EOF
  172.   ;;
  173. esac
  174.  
  175. if [ "x$gfxterm" = x1 ]; then
  176.     if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
  177.         && is_path_readable_by_grub "$GRUB_THEME"; then
  178.         echo "Found theme: $GRUB_THEME" >&2
  179.         prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"`
  180.         cat << EOF
  181. insmod gfxmenu
  182. EOF
  183.         themedir="`dirname "$GRUB_THEME"`"
  184.         for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
  185.             if [ -f "$x" ]; then
  186.                 cat << EOF
  187. loadfont (\$root)`make_system_path_relative_to_its_root $x`
  188. EOF
  189.             fi
  190.         done
  191.         if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
  192.             cat << EOF
  193. insmod jpeg
  194. EOF
  195.         fi
  196.         if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
  197.             cat << EOF
  198. insmod png
  199. EOF
  200.         fi
  201.         if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
  202.             cat << EOF
  203. insmod tga
  204. EOF
  205.         fi
  206.  
  207.         cat << EOF
  208. set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
  209. EOF
  210.     elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
  211.             && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
  212.         echo "Found background: $GRUB_BACKGROUND" >&2
  213.         case "$GRUB_BACKGROUND" in
  214.             *.png)         reader=png ;;
  215.             *.tga)         reader=tga ;;
  216.             *.jpg|*.jpeg)  reader=jpeg ;;
  217.             *)             echo "Unsupported image format" >&2; exit 1 ;;
  218.         esac
  219.         prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"`
  220.         cat << EOF
  221. insmod $reader
  222. background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
  223. EOF
  224.     fi
  225. fi
  226.  
  227. make_timeout ()
  228. {
  229.     if [ "x${1}" != "x" ] ; then
  230.         if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
  231.             verbose=
  232.         else
  233.             verbose=" --verbose"
  234.         fi
  235.         cat << EOF
  236. if sleep$verbose --interruptible ${1} ; then
  237.   set timeout=${2}
  238. fi
  239. EOF
  240.     else
  241.         cat << EOF
  242. set timeout=${2}
  243. EOF
  244.     fi
  245. }
  246.  
  247. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  248.     cat <<EOF
  249. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  250. EOF
  251. make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}"
  252. echo else
  253. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
  254. echo fi
  255. else
  256. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
  257. fi
  258.  
  259. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then
  260.     cat <<EOF
  261. cmosclean $GRUB_BUTTON_CMOS_ADDRESS
  262. EOF
  263. fi
  264.  
  265. # Play an initial tune
  266. if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
  267.   echo "play ${GRUB_INIT_TUNE}"
  268. fi
  269.  
  270. if [ "x${GRUB_BADRAM}" != "x" ] ; then
  271.   echo "badram ${GRUB_BADRAM}"
  272. fi
RAW Paste Data