00_header.in 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. #! /bin/sh -e
  2. # grub-mkconfig helper script.
  3. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  4. #
  5. # GRUB is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # GRUB is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. transform="@program_transform_name@"
  18. prefix=@prefix@
  19. exec_prefix=@exec_prefix@
  20. libdir=@libdir@
  21. grub_prefix=`echo /boot/burg | sed ${transform}`
  22. locale_dir=`echo /boot/burg/locale | sed ${transform}`
  23. grub_lang=`echo $LANG | cut -d _ -f 1`
  24. sysconfdir=@sysconfdir@
  25. pass_file=${sysconfdir}/default/burg-passwd
  26. . ${libdir}/burg/burg-mkconfig_lib
  27. # Do this as early as possible, since other commands might depend on it.
  28. # (e.g. the `loadfont' command might need lvm or raid modules)
  29. for i in ${GRUB_PRELOAD_MODULES} ; do
  30. echo "insmod $i"
  31. done
  32. if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
  33. if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
  34. if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
  35. if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi
  36. if test "x${GRUB_USERS}" != "x" ; then
  37. if test ! -r $pass_file ; then
  38. echo "Password file not found" >&2 ; exit 1
  39. fi
  40. awk -F: 'BEGIN {super=""} {print "password_" $3,$1,$4; if ($2=="s") super=super $1 ",";} END {if (super=="") exit 1; else print "set superusers=" super;}' $pass_file || { echo "No superuser is found" >&2 ; exit 1; }
  41. fi
  42. default_theme="$(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1)"
  43. if test ! -r "${grub_prefix}/themes/${default_theme}/theme"; then
  44. default_theme=burg
  45. fi
  46. if test "x${GRUB_THEME}" = "xsaved"; then
  47. echo "set theme_name=${default_theme}"
  48. fi
  49. if test "x${GRUB_GFXMODE}" = "xsaved"; then
  50. echo "set gfxmode=640x480"
  51. fi
  52. cat << EOF
  53. if [ -s \$prefix/burgenv ]; then
  54. load_env
  55. fi
  56. set default="${GRUB_DEFAULT}"
  57. if [ \${prev_saved_entry} ]; then
  58. set saved_entry=\${prev_saved_entry}
  59. save_env saved_entry
  60. set prev_saved_entry=
  61. save_env prev_saved_entry
  62. set boot_once=true
  63. fi
  64. function savedefault {
  65. if [ -z \${boot_once} ]; then
  66. saved_entry=\${chosen}
  67. save_env saved_entry
  68. fi
  69. }
  70. EOF
  71. if test "x${GRUB_GFXMODE}" != "xsaved"; then
  72. echo "set gfxmode=${GRUB_GFXMODE}"
  73. fi
  74. serial=0;
  75. gfxterm=0;
  76. for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
  77. if [ xserial = "x$x" ]; then
  78. serial=1;
  79. fi
  80. if [ xgfxterm = "x$x" ]; then
  81. gfxterm=1;
  82. fi
  83. done
  84. if [ "x$serial" = x1 ]; then
  85. if ! test -e ${grub_prefix}/serial.mod ; then
  86. echo "Serial terminal not available on this platform." >&2 ; exit 1
  87. fi
  88. if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
  89. grub_warn "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used."
  90. GRUB_SERIAL_COMMAND=serial
  91. fi
  92. echo "${GRUB_SERIAL_COMMAND}"
  93. fi
  94. if [ x$GRUB_THEME != x ] && [ ! -f $GRUB_THEME ] ; then
  95. cat << EOF
  96. function select_menu {
  97. if menu_popup -t template_popup theme_menu ; then
  98. free_config template_popup template_subitem menu class screen
  99. load_config \${prefix}/themes/\${theme_name}/theme \${prefix}/themes/custom/theme_\${theme_name}
  100. EOF
  101. if test "x${GRUB_THEME}" = "xsaved"; then
  102. cat << EOF
  103. save_env theme_name
  104. menu_refresh
  105. fi
  106. }
  107. EOF
  108. else
  109. cat << EOF
  110. menu_refresh
  111. fi
  112. }
  113. set theme_name=${GRUB_THEME}
  114. EOF
  115. fi
  116. cat << EOF
  117. function toggle_fold {
  118. if test -z \$theme_fold ; then
  119. set theme_fold=1
  120. else
  121. set theme_fold=
  122. fi
  123. EOF
  124. if test "x${GRUB_FOLD}" = "xsaved"; then
  125. cat << EOF
  126. save_env theme_fold
  127. menu_refresh
  128. }
  129. EOF
  130. else
  131. cat << EOF
  132. menu_refresh
  133. }
  134. EOF
  135. if test "x${GRUB_FOLD}" = "xtrue"; then
  136. echo "set theme_fold=1"
  137. else
  138. echo "set theme_fold="
  139. fi
  140. fi
  141. cat << EOF
  142. function select_resolution {
  143. if menu_popup -t template_popup resolution_menu ; then
  144. menu_reload_mode
  145. EOF
  146. if test "x${GRUB_GFXMODE}" = "xsaved"; then
  147. echo " save_env gfxmode"
  148. fi
  149. cat << EOF
  150. fi
  151. }
  152. EOF
  153. echo "if test -f \${prefix}/themes/\${theme_name}/theme ; then"
  154. cat << EOF
  155. insmod coreui
  156. menu_region.text
  157. EOF
  158. for i in ${grub_prefix}/themes/* ; do
  159. if test -r "$i/theme"; then
  160. theme_name=`echo $i | sed 's,.*/,,'`
  161. echo " load_string '+theme_menu { -${theme_name} { command=\"set theme_name=${theme_name}\" }}'"
  162. fi
  163. done
  164. for i in ${grub_prefix}/themes/conf.d/* ; do
  165. case "$i" in
  166. *~*) ;;
  167. *)
  168. if grub_file_is_not_garbage "$i" && test -r "$i" ; then
  169. echo " load_config \${prefix}/themes/conf.d/`echo $i | sed 's,.*/,,'`"
  170. fi
  171. ;;
  172. esac
  173. done
  174. echo " load_config \${prefix}/themes/\${theme_name}/theme \${prefix}/themes/custom/theme_\${theme_name}"
  175. if [ "x$gfxterm" = x1 ]; then
  176. cat << EOF
  177. insmod ${GRUB_VIDEO_BACKEND}
  178. insmod png
  179. insmod jpeg
  180. set gfxfont="Unifont Regular 16"
  181. menu_region.gfx
  182. vmenu resolution_menu
  183. EOF
  184. fi
  185. cat << EOF
  186. controller.ext
  187. fi
  188. EOF
  189. gfxterm=0
  190. term_output=
  191. for x in ${GRUB_TERMINAL_OUTPUT}; do
  192. if [ xgfxterm != "x$x" ]; then
  193. term_output=${term_output} $x
  194. fi
  195. done
  196. GRUB_TERMINAL_OUTPUT=${term_output}
  197. fi
  198. if [ "x$gfxterm" = x1 ]; then
  199. # Make the font accessible
  200. prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT_PATH}"`
  201. cat << EOF
  202. if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT_PATH}"` ; then
  203. insmod gfxterm
  204. insmod ${GRUB_VIDEO_BACKEND}
  205. EOF
  206. if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
  207. && is_path_readable_by_grub "$GRUB_THEME"; then
  208. echo "Found theme: $GRUB_THEME" >&2
  209. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"` | sed -e "s/^/ /"
  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. EOF
  239. elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
  240. && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
  241. echo "Found background: $GRUB_BACKGROUND" >&2
  242. case "$GRUB_BACKGROUND" in
  243. *.png) reader=png ;;
  244. *.tga) reader=tga ;;
  245. *.jpg|*.jpeg) reader=jpeg ;;
  246. *) echo "Unsupported image format" >&2; exit 1 ;;
  247. esac
  248. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"` | sed -e "s/^/ /"
  249. cat << EOF
  250. insmod $reader
  251. background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
  252. EOF
  253. fi
  254. cat << EOF
  255. fi
  256. EOF
  257. fi
  258. case x${GRUB_TERMINAL_INPUT} in
  259. x)
  260. # Just use the native terminal
  261. ;;
  262. x*)
  263. cat << EOF
  264. if terminal_input ${GRUB_TERMINAL_INPUT} ; then true ; else
  265. # For backward compatibility with versions of terminal.mod that don't
  266. # understand terminal_input
  267. terminal ${GRUB_TERMINAL_INPUT}
  268. fi
  269. EOF
  270. ;;
  271. esac
  272. case x${GRUB_TERMINAL_OUTPUT} in
  273. x)
  274. # Just use the native terminal
  275. ;;
  276. x*)
  277. cat << EOF
  278. if terminal_output ${GRUB_TERMINAL_OUTPUT} ; then true ; else
  279. # For backward compatibility with versions of terminal.mod that don't
  280. # understand terminal_output
  281. terminal ${GRUB_TERMINAL_OUTPUT}
  282. fi
  283. EOF
  284. ;;
  285. esac
  286. # Gettext variables and module
  287. if [ "x${LANG}" != "xC" ] ; then
  288. prepare_grub_to_access_device $(${grub_probe} --target=device ${locale_dir})
  289. cat << EOF
  290. set locale_dir=(\$root)$(make_system_path_relative_to_its_root ${locale_dir})
  291. set lang=${grub_lang}
  292. insmod gettext
  293. EOF
  294. fi
  295. if [ "x${GRUB_HIDDEN_TIMEOUT}" != "x" ] ; then
  296. if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
  297. verbose=
  298. else
  299. verbose=" --verbose"
  300. fi
  301. cat << EOF
  302. if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then
  303. set timeout=${GRUB_TIMEOUT}
  304. fi
  305. EOF
  306. else
  307. cat << EOF
  308. set timeout=${GRUB_TIMEOUT}
  309. EOF
  310. fi
  311. # Play an initial tune
  312. if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
  313. cat << EOF
  314. insmod play
  315. play ${GRUB_INIT_TUNE}
  316. EOF
  317. fi