Guest User

Untitled

a guest
Jun 30th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.96 KB | None | 0 0
  1. #! /bin/sh
  2. set -e
  3.  
  4. # grub-mkconfig helper script.
  5. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  6. #
  7. # GRUB is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # GRUB is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. prefix="/usr"
  21. exec_prefix="/usr"
  22. datarootdir="/usr/share"
  23. grub_lang=`echo $LANG | cut -d . -f 1`
  24. grubdir="`echo "/boot/grub" | sed 's,//*,/,g'`"
  25. quick_boot="1"
  26.  
  27. export TEXTDOMAIN=grub
  28. export TEXTDOMAINDIR="${datarootdir}/locale"
  29.  
  30. . "${datarootdir}/grub/grub-mkconfig_lib"
  31.  
  32. # Do this as early as possible, since other commands might depend on it.
  33. # (e.g. the `loadfont' command might need lvm or raid modules)
  34. for i in ${GRUB_PRELOAD_MODULES} ; do
  35. echo "insmod $i"
  36. done
  37.  
  38. if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
  39. if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
  40. if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
  41. if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi
  42.  
  43. if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi
  44. if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi
  45. if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
  46.  
  47. cat << EOF
  48. if [ -s \$prefix/grubenv ]; then
  49. set have_grubenv=true
  50. load_env
  51. fi
  52. EOF
  53. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  54. cat <<EOF
  55. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  56. set default="${GRUB_DEFAULT_BUTTON}"
  57. elif [ "\${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. else
  67. cat <<EOF
  68. if [ "\${next_entry}" ] ; then
  69. set default="\${next_entry}"
  70. set next_entry=
  71. save_env next_entry
  72. set boot_once=true
  73. else
  74. set default="${GRUB_DEFAULT}"
  75. fi
  76. EOF
  77. fi
  78. cat <<EOF
  79.  
  80. if [ x"\${feature_menuentry_id}" = xy ]; then
  81. menuentry_id_option="--id"
  82. else
  83. menuentry_id_option=""
  84. fi
  85.  
  86. export menuentry_id_option
  87.  
  88. if [ "\${prev_saved_entry}" ]; then
  89. set saved_entry="\${prev_saved_entry}"
  90. save_env saved_entry
  91. set prev_saved_entry=
  92. save_env prev_saved_entry
  93. set boot_once=true
  94. fi
  95.  
  96. function savedefault {
  97. if [ -z "\${boot_once}" ]; then
  98. saved_entry="\${chosen}"
  99. save_env saved_entry
  100. fi
  101. }
  102. EOF
  103.  
  104. if [ "$quick_boot" = 1 ]; then
  105. cat <<EOF
  106. function recordfail {
  107. set recordfail=1
  108. EOF
  109.  
  110. check_writable () {
  111. abstractions="$(grub-probe --target=abstraction "${grubdir}")"
  112. for abstraction in $abstractions; do
  113. case "$abstraction" in
  114. diskfilter | lvm)
  115. cat <<EOF
  116. # GRUB lacks write support for $abstraction, so recordfail support is disabled.
  117. EOF
  118. return
  119. ;;
  120. esac
  121. done
  122.  
  123. FS="$(grub-probe --target=fs "${grubdir}")"
  124. case "$FS" in
  125. btrfs | cpiofs | newc | odc | romfs | squash4 | tarfs | zfs)
  126. cat <<EOF
  127. # GRUB lacks write support for $FS, so recordfail support is disabled.
  128. EOF
  129. return
  130. ;;
  131. esac
  132.  
  133. cat <<EOF
  134. if [ -n "\${have_grubenv}" ]; then if [ -z "\${boot_once}" ]; then save_env recordfail; fi; fi
  135. EOF
  136. }
  137.  
  138. check_writable
  139.  
  140. cat <<EOF
  141. }
  142. EOF
  143. fi
  144.  
  145. cat <<EOF
  146. function load_video {
  147. EOF
  148. if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
  149. cat <<EOF
  150. insmod ${GRUB_VIDEO_BACKEND}
  151. EOF
  152. else
  153. # If all_video.mod isn't available load all modules available
  154. # with versions prior to introduction of all_video.mod
  155. cat <<EOF
  156. if [ x\$feature_all_video_module = xy ]; then
  157. insmod all_video
  158. else
  159. insmod efi_gop
  160. insmod efi_uga
  161. insmod ieee1275_fb
  162. insmod vbe
  163. insmod vga
  164. insmod video_bochs
  165. insmod video_cirrus
  166. fi
  167. EOF
  168. fi
  169. cat <<EOF
  170. }
  171.  
  172. EOF
  173.  
  174. serial=0;
  175. gfxterm=0;
  176. for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
  177. if [ xserial = "x$x" ]; then
  178. serial=1;
  179. fi
  180. if [ xgfxterm = "x$x" ]; then
  181. gfxterm=1;
  182. fi
  183. done
  184.  
  185. if [ "x$serial" = x1 ]; then
  186. if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
  187. grub_warn "$(gettext "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used.")"
  188. GRUB_SERIAL_COMMAND=serial
  189. fi
  190. echo "${GRUB_SERIAL_COMMAND}"
  191. fi
  192.  
  193. if [ "x$gfxterm" = x1 ]; then
  194. if [ -n "$GRUB_FONT" ] ; then
  195. # Make the font accessible
  196. prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT}"`
  197. cat << EOF
  198. if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
  199. EOF
  200. else
  201. for dir in "${pkgdatadir}" "`echo '/boot/grub' | sed "s,//*,/,g"`" /usr/share/grub ; do
  202. for basename in unicode unifont ascii; do
  203. path="${dir}/${basename}.pf2"
  204. if is_path_readable_by_grub "${path}" > /dev/null ; then
  205. font_path="${path}"
  206. else
  207. continue
  208. fi
  209. break 2
  210. done
  211. done
  212. if [ -n "${font_path}" ] ; then
  213. cat << EOF
  214. if [ x\$feature_default_font_path = xy ] ; then
  215. font=unicode
  216. else
  217. EOF
  218. # Make the font accessible
  219. prepare_grub_to_access_device `${grub_probe} --target=device "${font_path}"`
  220. cat << EOF
  221. font="`make_system_path_relative_to_its_root "${font_path}"`"
  222. fi
  223.  
  224. if loadfont \$font ; then
  225. EOF
  226. else
  227. cat << EOF
  228. if loadfont unicode ; then
  229. EOF
  230. fi
  231. fi
  232.  
  233. cat << EOF
  234. set gfxmode=${GRUB_GFXMODE}
  235. load_video
  236. insmod gfxterm
  237. EOF
  238.  
  239. # Gettext variables and module
  240. if [ "x${LANG}" != "xC" ] && [ "x${LANG}" != "x" ]; then
  241. cat << EOF
  242. set locale_dir=\$prefix/locale
  243. set lang=${grub_lang}
  244. insmod gettext
  245. EOF
  246. fi
  247.  
  248. cat <<EOF
  249. fi
  250. EOF
  251. fi
  252.  
  253. case x${GRUB_TERMINAL_INPUT} in
  254. x)
  255. # Just use the native terminal
  256. ;;
  257. x*)
  258. cat << EOF
  259. terminal_input ${GRUB_TERMINAL_INPUT}
  260. EOF
  261. ;;
  262. esac
  263.  
  264. case x${GRUB_TERMINAL_OUTPUT} in
  265. x)
  266. # Just use the native terminal
  267. ;;
  268. x*)
  269. cat << EOF
  270. terminal_output ${GRUB_TERMINAL_OUTPUT}
  271. EOF
  272. ;;
  273. esac
  274.  
  275. if [ "x$gfxterm" = x1 ]; then
  276. if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
  277. && is_path_readable_by_grub "$GRUB_THEME"; then
  278. gettext_printf "Found theme: %s\n" "$GRUB_THEME" >&2
  279.  
  280. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"`
  281. cat << EOF
  282. insmod gfxmenu
  283. EOF
  284. themedir="`dirname "$GRUB_THEME"`"
  285. for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
  286. if [ -f "$x" ]; then
  287. cat << EOF
  288. loadfont (\$root)`make_system_path_relative_to_its_root $x`
  289. EOF
  290. fi
  291. done
  292. if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
  293. cat << EOF
  294. insmod jpeg
  295. EOF
  296. fi
  297. if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
  298. cat << EOF
  299. insmod png
  300. EOF
  301. fi
  302. if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
  303. cat << EOF
  304. insmod tga
  305. EOF
  306. fi
  307.  
  308. cat << EOF
  309. set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
  310. export theme
  311. EOF
  312. elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
  313. && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
  314. gettext_printf "Found background: %s\n" "$GRUB_BACKGROUND" >&2
  315. case "$GRUB_BACKGROUND" in
  316. *.png) reader=png ;;
  317. *.tga) reader=tga ;;
  318. *.jpg|*.jpeg) reader=jpeg ;;
  319. *) gettext "Unsupported image format" >&2; echo >&2; exit 1 ;;
  320. esac
  321. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"`
  322. cat << EOF
  323. insmod $reader
  324. background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
  325. EOF
  326. fi
  327. fi
  328.  
  329. make_timeout ()
  330. {
  331. cat << EOF
  332. if [ "\${recordfail}" = 1 ] ; then
  333. set timeout=${GRUB_RECORDFAIL_TIMEOUT:-30}
  334. else
  335. EOF
  336. if [ "x${3}" != "x" ] ; then
  337. timeout="${2}"
  338. style="${3}"
  339. elif [ "x${1}" != "x" ] && \
  340. ([ "$quick_boot" = 1 ] || [ "x${1}" != "x0" ]) ; then
  341. # Handle the deprecated GRUB_HIDDEN_TIMEOUT scheme.
  342. timeout="${1}"
  343. if [ "x${2}" != "x0" ] ; then
  344. grub_warn "$(gettext "Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.")"
  345. fi
  346. if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
  347. style="hidden"
  348. verbose=
  349. else
  350. style="countdown"
  351. verbose=" --verbose"
  352. fi
  353. else
  354. # No hidden timeout, so treat as GRUB_TIMEOUT_STYLE=menu
  355. timeout="${2}"
  356. style="menu"
  357. fi
  358. cat << EOF
  359. if [ x\$feature_timeout_style = xy ] ; then
  360. set timeout_style=${style}
  361. set timeout=${timeout}
  362. EOF
  363. if [ "x${style}" = "xmenu" ] ; then
  364. cat << EOF
  365. # Fallback normal timeout code in case the timeout_style feature is
  366. # unavailable.
  367. else
  368. set timeout=${timeout}
  369. EOF
  370. else
  371. cat << EOF
  372. # Fallback hidden-timeout code in case the timeout_style feature is
  373. # unavailable.
  374. elif sleep${verbose} --interruptible ${timeout} ; then
  375. set timeout=0
  376. EOF
  377. fi
  378. cat << EOF
  379. fi
  380. fi
  381. EOF
  382. }
  383.  
  384. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  385. cat <<EOF
  386. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  387. EOF
  388. make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_STYLE_BUTTON}"
  389. echo else
  390. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
  391. echo fi
  392. else
  393. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
  394. fi
  395.  
  396. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then
  397. cat <<EOF
  398. cmosclean $GRUB_BUTTON_CMOS_ADDRESS
  399. EOF
  400. fi
  401.  
  402. # Play an initial tune
  403. if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
  404. echo "play ${GRUB_INIT_TUNE}"
  405. fi
  406.  
  407. if [ "x${GRUB_BADRAM}" != "x" ] ; then
  408. echo "badram ${GRUB_BADRAM}"
  409. fi
Add Comment
Please, Sign In to add comment