Advertisement
Guest User

/etc/grub.d/05_debian_theme

a guest
Feb 13th, 2011
1,511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. test -d "${GRUB_PREFIX}"; cd "${GRUB_PREFIX}"
  2.  
  3. # Set the location of a possibly necessary cache file for the background image.
  4. # NOTE: This MUST BE A DOTFILE to avoid confusing it with user-defined images.
  5. BACKGROUND_CACHE=".background_cache"
  6.  
  7. set_default_theme(){
  8. # Set the traditional Debian blue theme.
  9. echo "${1}set menu_color_normal=light-cyan/black"
  10. echo "${1}set menu_color_highlight=white/blue"
  11. }
  12.  
  13. set_custom_theme(){
  14. # Set custom color theme.
  15. echo "${1}set menu_color_normal=light-cyan/black"
  16. echo "${1}set menu_color_highlight=white/light-blue"
  17. echo "${1}set color_normal=white/black"
  18. echo "${1}set color_highlight=white/light-blue"
  19. }
  20.  
  21. set_background_image(){
  22. # Step #1: Search all available output modes ...
  23. local output
  24. for output in ${GRUB_TERMINAL_OUTPUT}; do
  25. if [ "x$output" = "xgfxterm" ]; then
  26. break
  27. fi
  28. done
  29.  
  30. # ... and check if we are able to display a background image at all.
  31. if ! [ "x${output}" = "xgfxterm" ]; then
  32. return 1
  33. fi
  34.  
  35. # Step #2: Check if the specified background image exists.
  36. if ! [ -f "${1}" ]; then
  37. return 2
  38. fi
  39.  
  40. # Step #3: Search the correct GRUB module for our background image.
  41. local reader
  42. case "${1}" in
  43. *.jpg|*.JPG|*.jpeg|*.JPEG) reader="jpeg";;
  44. *.png|*.PNG) reader="png";;
  45. *.tga|*.TGA) reader="tga";;
  46. *) return 3;; # Unknown image type.
  47. esac
  48.  
  49. # Step #4: Check if the necessary GRUB module is available.
  50. if ! [ -f "${reader}.mod" ]; then
  51. return 4
  52. fi
  53.  
  54. # Step #5: Check if GRUB can read the background image directly.
  55. # If so, we can remove the cache file (if any). Otherwise the backgound
  56. # image needs to be cached under /boot/grub/.
  57. if is_path_readable_by_grub "${1}"; then
  58. rm --force "${BACKGROUND_CACHE}.jpeg" \
  59. "${BACKGROUND_CACHE}.png" "${BACKGROUND_CACHE}.tga"
  60. elif cp "${1}" "${BACKGROUND_CACHE}.${reader}"; then
  61. set -- "${BACKGROUND_CACHE}.${reader}" "${2}" "${3}"
  62. else
  63. return 5
  64. fi
  65.  
  66. # Step #6: Prepare GRUB to read the background image.
  67. if ! prepare_grub_to_access_device "`${grub_probe} --target=device "${1}"`"; then
  68. return 6
  69. fi
  70.  
  71. # Step #7: Everything went fine, print out a message to stderr ...
  72. echo "Found background image: ${1}" >&2
  73.  
  74. # ... and write our configuration snippet to stdout. Use the colors
  75. # desktop-base specified. If we're using a user-defined background, use
  76. # the default colors since we've got no idea how the image looks like.
  77. # If loading the background image fails, use the default theme.
  78. echo "insmod ${reader}"
  79. echo "if background_image `make_system_path_relative_to_its_root "${1}"`; then"
  80. if [ -n "${2}" ]; then
  81. echo " set color_normal=${2}"
  82. fi
  83. if [ -n "${3}" ]; then
  84. echo " set color_highlight=${3}"
  85. fi
  86. if [ -z "${2}" ] && [ -z "${3}" ]; then
  87. echo " true"
  88. fi
  89. echo "else"
  90. set_default_theme " "
  91. echo "fi"
  92. }
  93.  
  94. # Earlier versions of grub-pc copied the default background image to /boot/grub
  95. # during postinst. Remove those obsolete images if they haven't been touched by
  96. # the user. They are still available under /usr/share/images/desktop-base/ if
  97. # desktop-base is installed.
  98. while read checksum background; do
  99. if [ -f "${background}" ] && [ "x`sha1sum "${background}"`" = "x${checksum} ${background}" ]; then
  100. echo "Removing old background image: ${background}" >&2
  101. rm "${background}"
  102. fi
  103. done <<EOF
  104. 648ee65dd0c157a69b019a5372cbcfea4fc754a5 debian-blueish-wallpaper-640x480.png
  105. 0431e97a6c661084c59676c4baeeb8c2f602edb8 debian-blueish-wallpaper-640x480.png
  106. 968ecf6696c5638cfe80e8e70aba239526270864 debian-blueish-wallpaper-640x480.tga
  107. 11143e8c92a073401de0b0fd42d0c052af4ccd9b moreblue-orbit-grub.png
  108. d00d5e505ab63f2d53fa880bfac447e2d3bb197c moreblue-orbit-grub.png
  109. f5b12c1009ec0a3b029185f6b66cd0d7e5611019 moreblue-orbit-grub.png
  110. EOF
  111.  
  112. # Include the configuration of desktop-base if available.
  113. if [ -f "/usr/share/desktop-base/grub_background.sh" ]; then
  114. . "/usr/share/desktop-base/grub_background.sh"
  115. fi
  116.  
  117. # First check whether the user has specified a background image explicitly.
  118. # If so, try to use it. Don't try the other possibilities in that case
  119. # (#608263).
  120. if [ -n "${GRUB_BACKGROUND+x}" ]; then
  121. set_background_image "${GRUB_BACKGROUND}" || set_default_theme
  122. exit 0
  123. fi
  124.  
  125. # Next search for pictures the user put into /boot/grub/ and use the first one.
  126. # Next try to use the background image and colors specified by desktop-base.
  127. # If we haven't found a background image yet, use the default from desktop-base.
  128. # Finally, if all of the above fails, use the default theme.
  129. set_background_image "`ls -1 *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.tga *.TGA 2>/dev/null | head -1`" ||
  130. set_background_image "${WALLPAPER}" "${COLOR_NORMAL}" "${COLOR_HIGHLIGHT}" ||
  131. set_background_image "/boot/grub/images/boot.png" ||
  132. set_default_theme
  133. set_custom_theme
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement