vds89

00_header

Jan 2nd, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.81 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. . "$pkgdatadir/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. cat <<EOF
  54. if [ "\${initrdfail}" = 2 ]; then
  55. set initrdfail=
  56. elif [ "\${initrdfail}" = 1 ]; then
  57. set next_entry="\${prev_entry}"
  58. set prev_entry=
  59. save_env prev_entry
  60. if [ "\${next_entry}" ]; then
  61. set initrdfail=2
  62. fi
  63. fi
  64. EOF
  65. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  66. cat <<EOF
  67. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  68. set default="${GRUB_DEFAULT_BUTTON}"
  69. elif [ "\${next_entry}" ] ; then
  70. set default="\${next_entry}"
  71. set next_entry=
  72. save_env next_entry
  73. set boot_once=true
  74. else
  75. set default="${GRUB_DEFAULT}"
  76. fi
  77. EOF
  78. else
  79. cat <<EOF
  80. if [ "\${next_entry}" ] ; then
  81. set default="\${next_entry}"
  82. set next_entry=
  83. save_env next_entry
  84. set boot_once=true
  85. else
  86. set default="${GRUB_DEFAULT}"
  87. fi
  88. EOF
  89. fi
  90. cat <<EOF
  91.  
  92. if [ x"\${feature_menuentry_id}" = xy ]; then
  93. menuentry_id_option="--id"
  94. else
  95. menuentry_id_option=""
  96. fi
  97.  
  98. export menuentry_id_option
  99.  
  100. if [ "\${prev_saved_entry}" ]; then
  101. set saved_entry="\${prev_saved_entry}"
  102. save_env saved_entry
  103. set prev_saved_entry=
  104. save_env prev_saved_entry
  105. set boot_once=true
  106. fi
  107.  
  108. function savedefault {
  109. if [ -z "\${boot_once}" ]; then
  110. saved_entry="\${chosen}"
  111. save_env saved_entry
  112. fi
  113. }
  114. EOF
  115.  
  116. cat <<"EOF"
  117. function initrdfail {
  118. if [ -n "${have_grubenv}" ]; then if [ -n "${partuuid}" ]; then
  119. if [ -z "${initrdfail}" ]; then
  120. set initrdfail=1
  121. if [ -n "${boot_once}" ]; then
  122. set prev_entry="${default}"
  123. save_env prev_entry
  124. fi
  125. fi
  126. save_env initrdfail
  127. fi; fi
  128. }
  129. EOF
  130.  
  131. if [ "$quick_boot" = 1 ]; then
  132. cat <<EOF
  133. function recordfail {
  134. set recordfail=1
  135. EOF
  136.  
  137. check_writable () {
  138. abstractions="$(grub-probe --target=abstraction "${grubdir}")"
  139. for abstraction in $abstractions; do
  140. case "$abstraction" in
  141. diskfilter | lvm)
  142. cat <<EOF
  143. # GRUB lacks write support for $abstraction, so recordfail support is disabled.
  144. EOF
  145. return 1
  146. ;;
  147. esac
  148. done
  149.  
  150. FS="$(grub-probe --target=fs "${grubdir}")"
  151. case "$FS" in
  152. btrfs | cpiofs | newc | odc | romfs | squash4 | tarfs | zfs)
  153. cat <<EOF
  154. # GRUB lacks write support for $FS, so recordfail support is disabled.
  155. EOF
  156. return 1
  157. ;;
  158. esac
  159.  
  160. cat <<EOF
  161. if [ -n "\${have_grubenv}" ]; then if [ -z "\${boot_once}" ]; then save_env recordfail; fi; fi
  162. EOF
  163. }
  164.  
  165. if ! check_writable; then
  166. recordfail_broken=1
  167. fi
  168.  
  169. cat <<EOF
  170. }
  171. EOF
  172. fi
  173.  
  174. cat <<EOF
  175. function load_video {
  176. EOF
  177. if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
  178. cat <<EOF
  179. insmod ${GRUB_VIDEO_BACKEND}
  180. EOF
  181. else
  182. # If all_video.mod isn't available load all modules available
  183. # with versions prior to introduction of all_video.mod
  184. cat <<EOF
  185. if [ x\$feature_all_video_module = xy ]; then
  186. insmod all_video
  187. else
  188. insmod efi_gop
  189. insmod efi_uga
  190. insmod ieee1275_fb
  191. insmod vbe
  192. insmod vga
  193. insmod video_bochs
  194. insmod video_cirrus
  195. fi
  196. EOF
  197. fi
  198. cat <<EOF
  199. }
  200.  
  201. EOF
  202.  
  203. serial=0;
  204. gfxterm=0;
  205. for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
  206. if [ xserial = "x$x" ]; then
  207. serial=1;
  208. fi
  209. if [ xgfxterm = "x$x" ]; then
  210. gfxterm=1;
  211. fi
  212. done
  213.  
  214. if [ "x$serial" = x1 ]; then
  215. if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
  216. grub_warn "$(gettext "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used.")"
  217. GRUB_SERIAL_COMMAND=serial
  218. fi
  219. echo "${GRUB_SERIAL_COMMAND}"
  220. fi
  221.  
  222. if [ "x$gfxterm" = x1 ]; then
  223. if [ -n "$GRUB_FONT" ] ; then
  224. # Make the font accessible
  225. prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT}"`
  226. cat << EOF
  227. if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
  228. EOF
  229. else
  230. for dir in "${pkgdatadir}" "`echo '/boot/grub' | sed "s,//*,/,g"`" /usr/share/grub ; do
  231. for basename in unicode unifont ascii; do
  232. path="${dir}/${basename}.pf2"
  233. if is_path_readable_by_grub "${path}" > /dev/null ; then
  234. font_path="${path}"
  235. else
  236. continue
  237. fi
  238. break 2
  239. done
  240. done
  241. if [ -n "${font_path}" ] ; then
  242. cat << EOF
  243. if [ x\$feature_default_font_path = xy ] ; then
  244. font=unicode
  245. else
  246. EOF
  247. # Make the font accessible
  248. prepare_grub_to_access_device `${grub_probe} --target=device "${font_path}"`
  249. cat << EOF
  250. font="`make_system_path_relative_to_its_root "${font_path}"`"
  251. fi
  252.  
  253. if loadfont \$font ; then
  254. EOF
  255. else
  256. cat << EOF
  257. if loadfont unicode ; then
  258. EOF
  259. fi
  260. fi
  261.  
  262. cat << EOF
  263. set gfxmode=${GRUB_GFXMODE}
  264. load_video
  265. insmod gfxterm
  266. EOF
  267.  
  268. # Gettext variables and module
  269. if [ "x${LANG}" != "xC" ] && [ "x${LANG}" != "x" ]; then
  270. cat << EOF
  271. set locale_dir=\$prefix/locale
  272. set lang=${grub_lang}
  273. insmod gettext
  274. EOF
  275. fi
  276.  
  277. cat <<EOF
  278. fi
  279. EOF
  280. fi
  281.  
  282. case x${GRUB_TERMINAL_INPUT} in
  283. x)
  284. # Just use the native terminal
  285. ;;
  286. x*)
  287. cat << EOF
  288. terminal_input ${GRUB_TERMINAL_INPUT}
  289. EOF
  290. ;;
  291. esac
  292.  
  293. case x${GRUB_TERMINAL_OUTPUT} in
  294. x)
  295. # Just use the native terminal
  296. ;;
  297. x*)
  298. cat << EOF
  299. terminal_output ${GRUB_TERMINAL_OUTPUT}
  300. EOF
  301. ;;
  302. esac
  303.  
  304. if [ "x$gfxterm" = x1 ]; then
  305. if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
  306. && is_path_readable_by_grub "$GRUB_THEME"; then
  307. gettext_printf "Found theme: %s\n" "$GRUB_THEME" >&2
  308.  
  309. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"`
  310. cat << EOF
  311. insmod gfxmenu
  312. EOF
  313. themedir="`dirname "$GRUB_THEME"`"
  314. for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
  315. if [ -f "$x" ]; then
  316. cat << EOF
  317. loadfont (\$root)`make_system_path_relative_to_its_root $x`
  318. EOF
  319. fi
  320. done
  321. if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
  322. cat << EOF
  323. insmod jpeg
  324. EOF
  325. fi
  326. if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
  327. cat << EOF
  328. insmod png
  329. EOF
  330. fi
  331. if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
  332. cat << EOF
  333. insmod tga
  334. EOF
  335. fi
  336.  
  337. cat << EOF
  338. set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
  339. export theme
  340. EOF
  341. elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
  342. && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
  343. gettext_printf "Found background: %s\n" "$GRUB_BACKGROUND" >&2
  344. case "$GRUB_BACKGROUND" in
  345. *.png) reader=png ;;
  346. *.tga) reader=tga ;;
  347. *.jpg|*.jpeg) reader=jpeg ;;
  348. *) gettext "Unsupported image format" >&2; echo >&2; exit 1 ;;
  349. esac
  350. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"`
  351. cat << EOF
  352. insmod $reader
  353. background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
  354. EOF
  355. fi
  356. fi
  357.  
  358. make_timeout ()
  359. {
  360. cat << EOF
  361. if [ "\${recordfail}" = 1 ] ; then
  362. set timeout=${GRUB_RECORDFAIL_TIMEOUT:-30}
  363. else
  364. EOF
  365. if [ "x${3}" != "x" ] ; then
  366. timeout="${2}"
  367. style="${3}"
  368. elif [ "x${1}" != "x" ] && \
  369. ([ "$quick_boot" = 1 ] || [ "x${1}" != "x0" ]) ; then
  370. # Handle the deprecated GRUB_HIDDEN_TIMEOUT scheme.
  371. timeout="${1}"
  372. if [ "x${2}" != "x0" ] ; then
  373. grub_warn "$(gettext "Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.")"
  374. fi
  375. if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
  376. style="hidden"
  377. verbose=
  378. else
  379. style="countdown"
  380. verbose=" --verbose"
  381. fi
  382. else
  383. # No hidden timeout, so treat as GRUB_TIMEOUT_STYLE=menu
  384. timeout="${2}"
  385. style="menu"
  386. fi
  387. cat << EOF
  388. if [ x\$feature_timeout_style = xy ] ; then
  389. set timeout_style=${style}
  390. set timeout=${timeout}
  391. EOF
  392. if [ "x${style}" = "xmenu" ] ; then
  393. cat << EOF
  394. # Fallback normal timeout code in case the timeout_style feature is
  395. # unavailable.
  396. else
  397. set timeout=${timeout}
  398. EOF
  399. else
  400. cat << EOF
  401. # Fallback hidden-timeout code in case the timeout_style feature is
  402. # unavailable.
  403. elif sleep${verbose} --interruptible ${timeout} ; then
  404. set timeout=0
  405. EOF
  406. fi
  407. cat << EOF
  408. fi
  409. fi
  410. EOF
  411. if [ "$recordfail_broken" = 1 ]; then
  412. cat << EOF
  413. if [ \$grub_platform = efi ]; then
  414. set timeout=${GRUB_RECORDFAIL_TIMEOUT:-30}
  415. if [ x\$feature_timeout_style = xy ] ; then
  416. set timeout_style=menu
  417. fi
  418. fi
  419. EOF
  420. fi
  421. }
  422.  
  423. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  424. cat <<EOF
  425. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  426. EOF
  427. make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_STYLE_BUTTON}"
  428. echo else
  429. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
  430. echo fi
  431. else
  432. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
  433. fi
  434.  
  435. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then
  436. cat <<EOF
  437. cmosclean $GRUB_BUTTON_CMOS_ADDRESS
  438. EOF
  439. fi
  440.  
  441. # Play an initial tune
  442. if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
  443. echo "play ${GRUB_INIT_TUNE}"
  444. fi
  445.  
  446. if [ "x${GRUB_BADRAM}" != "x" ] ; then
  447. echo "badram ${GRUB_BADRAM}"
  448. fi
Add Comment
Please, Sign In to add comment